I'm trying to create a simple if conditional on the host.name field if it matches an IP address. This is originating from a syslog source and is a static IP. I've tried == with quotes around the IP, escaping the octet dots, no forward slashes around the IP, =~ with quotes but none work. Also tried [host.name] with but same result. Any ideas?
filter {
if "syslog" in [tags] {
if [host][name] =~ /10.10.1.1/ {
mutate { add_tag => ["fw"] }
}
}
}
Below is the json from a log that should be getting this tag applied. It does get the syslog tag originally. Could it have something to do with host.name not being in the original message because it's coming via syslog?
In our naming of filters the syslog input begins with 0003_input_syslog.conf while the filter listed initially is 0950_identify_syslog.conf so I think it should apply later.
I am running out of suggestions. You could try --config.debug --log.level debug --config.test_and_exit and review the debug logs to see if the ordering is what we expect.
So it looks like it's something to do specifically with a comparison to the [host][name] field. I modified the conditional to match something in the message field instead and I was able to get the fw tag added so it's not an ordering issue with the syslog. Unfortunately, the hostname doesn't appear in the message field so I can't use that. It makes me think the [host][name] may be added on later but I'm not sure when or there is a unique way to compare an IP to a nested field.
if "inbound/pass1" in [message] {
This did add the fw tag but inbound/pass doesn't appear in all logs.
So apparently [host][name] is really just [host]. I actually didn't have to drop and add it back. This line below now works and gives me host.name with the proper tag.
if [host] == "10.10.1.1" { ...
Is [host] a top level field that by itself becomes [host][name] assuming no other nested fields are applied?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.