How to check != null in Cassandra using datastax DevCenter? - cassandra

I've tried different cases:
where ip != NULL
where ip <> NULL
where ip IS NOT NULL
but it doesn't work :(

it works by tricky ears feint:
where ip >= ''

Related

Does metadata.getTokenRanges() return all token range across all nodes in cassandra?

I went through Is there a way to see token ranges for each node in cassandra which uses vnodes?. In this implementation we get all hosts and get token ranges in those individual hosts to get all token range across all nodes.
But, in my case, I am using below code:
public static synchronized List<Object[]> getTokenRangesAcrossNodes(
final String node, final Integer port, final String userName, final String password) {
if (cluster == null) {
connect(node, port, userName, password);
}
Metadata metadata = cluster.getMetadata();
return unwrapTokenRanges(new ArrayList<>(metadata.getTokenRanges()));
}
In above connect() function node has all the comma seperated cassandra host string and I use Cluster.builder().addContactPoints() to create session.
My question is:
Does metadata.getTokenRanges() gives all token ranges across all hosts? or do I need to get all hosts and get token ranges for each host?
Does fetching token range across all nodes is different from the token range for a given keyspace?
Cassandra version: 3.*
Each host exposes its primary tokens by getTokens().
Metadata.getTokenRanges() returns the token ranges that define data distribution in the ring.
You have also the option to use Metadata.getTokenRanges(String keyspace, Host host) which returns the token ranges that are replicated on a given host for a certain keyspace.
Check the following links:
Metadata
Host.getTokens()
Metadata.getTokenRanges(String keyspace, Host host)
Metadata.getTokenRanges()
And this example might prove helpful.

How to block a specific IP in Packetbeat

So I am doing a data visualization of netflow traffic, and I am running packetbeat in "af mode" to gather all of the netflow data.
The problem is that the IP that I am connecting to the box with packetbeat on it, is something I want to ignore. Since I know what it is and it is just cluttering things up in the visualization.
I want to ignore all of the traffic that has this data:
"dest.ip" of < XYZ >
and
"source.ip" of < IP of server running packetbeat >
I have the "packetbeat.ignore_outgoing: true" set up in my packetbeat.yml file. I am running this on CentOS and outputting the packetbeat data straight to Logstash.
Is there any way to do this?
What I ended up doing was writing a Logstash filter.
filter {
if[type] == "flow" and [dest][ip] == "192.168.X.Y" and [packet_source][ip] == "192.168.Z.D" {
drop { }
}
}

DNS automation in a private cloud using DNSJava

I am trying to create a DNS service (automation of various DNS operations) to serve our existing private cloud. I am looking for options and ideas to do this. Is there any existing Java API to do this? Please suggest.
I made a research on the possible solutions. I found DNSJava to be a good solution. But I did not find much documentation/examples. The following are some questions which, when answered, can solve my current problems:
How to add NS or A records to zone files?
How to print out the contents of a zone file?
I have created a local DNS server for test purpose. It will be really helpful if the examples are given with respect to localhost.
Thank you!
After a lot of research, I found a way to modify the zone files with DNSJava. Bind9 should be setup in the server. Required zone files should be created with basic information. Adding and deleting a record in the zone file is straight forward once we have this setup. Please refer to this page to generate TSIG key for Bind9. The code that can actually add a record is given below.
Name zoneName = null;
String domain = "your.domain";
String host = "hostname";
DNSRecordType type = DNSRecordType.A;
int ttl = 600;
Lookup lookup = new Lookup(Name.fromString("your.domain"));
Record [] records = lookup.run();
if(records != null) {
zoneName = records[0].getName();
}
if(zoneName != null) {
Name hostName = Name.fromString("hostname", zoneName);
Update update = new Update(zoneName);
update.add(hostName, Type.value(type.toString()), 600,
"192.168.2.50");
Resolver resolver = new SimpleResolver();
resolver.setTCP(true);
resolver.setTSIGKey(new TSIG("your.domain.",
"z0pll56C4cwLXYd2HG6WsQ=="));
Message response1 = resolver.send(update);
response = response1.getHeader().toString();
}

Non-static IP: script to alert change

I have a server at home with basic DSL. I registered a domain name (at GoDaddy) and can login remotely just fine. However, this requires the input of the IP address and a static IP would be prohibitively expensive. I haven't found a good dynamic service. Instead, it seems that my IP address doesn't change very often--maybe once a month--and so it's just as easy for me to update the GoDaddy domain information. However, I would like to receive an alert from my server when this change happens. Here's the script that I wrote to do this:
#!/bin/bash
oldipinfo=""
while [ 1 ]
do
sleep 3600
ipinfo=`lynx -dump checkip.dyndns.org`
if [ ipinfo != oldipinfo ]
then
echo "New IP for server $(ipinfo)" | mail -s "NEW IP!" myaddress#gmail.com
echo $ipinfo >> ipinfo.out
oldipinfo=ipinfo
fi
done
This actually e-mails me (and updates the file) every hour, so I've done something wrong?
Thanks for your help!
JV
You never read the oldipinfo from the file you cache it in, so your script always has oldipinfo set to an empty string, meaning that "" != x.x.x.x will always be true.
You should have
oldipinfo=`cat ipinfo.txt`

Querying azure table storage for null values

Does anyone know the proper way to query azure table storage for a null value. From what I've read, it's possible (although there is a bug which prevents it on development storage). However, I keep getting the following error when I do so on the live cloud storage:
One of the request inputs is not valid.
This is a dumbed down version of the LINQ query that I've put together.
var query = from fooBar in fooBarSVC.CreateQuery<FooBar>("FooBars")
where fooBar.PartitionKey == kPartitionID
&& fooBar.Code == kfooBarCode
&& fooBar.Effective_Date <= kFooBarDate.ToUniversalTime()
&& (fooBar.Termination_Date > kFooBarDate.ToUniversalTime() || fooBar.Termination_Date == null)
select fooBar;
If I run the query without checking for null, it works fine. I know a possible solution would be to run a second query on the collection that this query brings back. I don't mind doing that if I need to, but would like to know if I can get this approach to work first.
Anyone see anything obvious I'm doing wrong?
The problem is that because azure table storage does not have a schema, the null column actually doesn't exist. This is why your query is not valid. there is no such thing as a null column in table storage. You could do something like store an empty string if you really have to. Really though the fundamental issue here is that Azure table storage really is not built to be queried by any columns other than partition key and row key. Every time you make a query on one of these non-standard columns you are doing a table scan. If you start to get lots of data you are going to have a very high rate of query time outs. I would suggest setting up a manual index for these types of queries. For example, you could store the same data in the same table but with different values for the Row key. Ultimately, if your are app is not getting crazy high usage I would just use SQL Azure as it will be much more flexible for the types of queries you are doing.
Update: Azure has a great guide on table storage design that I would recommend reading. http://azure.microsoft.com/en-us/documentation/articles/storage-table-design-guide/
I just had this problem and found a nice little ninja-trick to actually test for nulls. Although I'm using the Azure Storage interface directly, I'm 90% sure it will work for LINQ too if you do the same.
Here's what I did to check if Price (Int32?) is null:
not (Price lt 0 or Price gt 0)
I'm guessing in your case you can do the same in LINQ by testing if fooBar.Termination_Date is less or greater than DateTime.UtcNow for example. Something like this:
where fooBar.PartitionKey == kPartitionID
&& fooBar.Code == kfooBarCode
&& fooBar.Effective_Date <= kFooBarDate.ToUniversalTime()
&& (fooBar.Termination_Date > kFooBarDate.ToUniversalTime()
|| (not (fooBar.Termination_Date < DateTime.UtcNow
or fooBar.Termination_Date > DateTime.UtcNow))
select fooBar;
For a string column called MyColumn I was able to type: not(MyColumn gt '')
Mike S answer above put me on the right path.
For strings, we can compare to empty string.
IsNotBlank(value)
Can be:
(Value gt '')
Using the Azure Tables client library for .NET. to query for null Guid values.
In the sample code, the property's name is MyColumn.
var filter = Azure.Data.Tables.TableClient
.CreateQueryFilter($"not(MyColumn gt {Guid.Empty})");
The TableClient.CreateQueryFilter method will create the filter:
not(MyColumn gt guid'00000000-0000-0000-0000-000000000000')

Resources