Ignoring strings in filtering
Hello,
I did some work on ElastAlert today and I encountered some problem with Strings in filtering.
I tried to reproduce the filtering of some of my Kibana Dashboards, everything works if I set filters such as:
- not:
term:
src_.ip: "173.20.930.210"
- or:
- term:
dst_port: "8080"
- term:
dst_port: "443"
but if I use string values, those filters won't hit anything:
- query:
query_string:
query: "src_interface: A-Adm8-WEB1"
or :
- term:
src_interface: "A-Adm8-WEB1"
I tried other values such as Deny etc..., as long as it is a string, it acts like it doesn't even exist. (0 hits if ran alone)
I tried a-adm8-web1, '"A-Adm8-WEB1"', '"a-adm8-web1"', {src_interface: '"A-Adm8-WEB1"'} Even copied the result from elastalert-rule-from-kibana none of these make it work...
No way it's a conf problem since it works without string values, maybe I'm missing something but can't find out what.
If you are using default Logstash/Elasticsearch settings, src_interface is probably an analyzed field, meaning the would need
- term:
src_interface.raw: A-Adm8-WEB1
The query string should work though. You are sure that there are documents with the correct timestamp and that exact src_interface?
you can run elastalert with --es_debug_trace file and it will show you exactly what query is being made. If you can, post the exact query being made and the full json of a document you expect it to match, and that should be enough to figure out why it's not working.
I found for simple string that it needed to write everything in lower case such as Deny => deny
For strings with special characters, I think it needs some escaping, but just like you mentionned, field.raw: "value" works but you need to put those ""
@NicoYUE @Qmando
I'm trying to ignore specific string in field srx-source-zone. I tried with options whitelist and query_string and filter term nothing worked.
I'm trying to exclude the below filed using NOT in query_string srx-source-zone-name:corporate. Please assist me ?
filter:
- query:
query_string:
query: "_type:message"
- query:
query_string:
query: "srx-rt-flow:RT_FLOW_SESSION_DENY"
- query:
query_string:
query: "NOT srx-source-zone-name:corporate"
@NicoYUE @Qmando
I'm trying to ignore specific string in field srx-source-zone-name. I tried with options whitelist and query_string and filter term nothing worked.
I'm trying to exclude the below filed using NOT in query_string srx-source-zone-name:EXTERNAL. Please assist me ?
srx-rt-flow : RT_FLOW_SESSION_DENY srx-source-address: 10.18.109.59 srx-source-port: 56453 srx-source-zone-name: EXTERNAL
Tried below method but nothing is working. I get matches for the NOT string also :-(
Method 1:
doc_type: message
filter:
- query:
query_string:
query: "_type:message"
- query:
query_string:
query: "srx-rt-flow:RT_FLOW_SESSION_DENY"
- query:
query_string:
query: "NOT srx-source-zone-name:EXTERNAL"
Method 2:
filter:
- query:
query_string:
query: "_type:message"
- query:
query_string:
query: "srx-rt-flow:RT_FLOW_SESSION_DENY AND NOT srx-source-zone-name:EXTERNAL"
Method 3:
filter:
- not:
terms:
srx-source-zone-name: ["EXTERNAL"]
Method 4:
field: srx-source-zone-name type: any compare_key: srx-source-zone-name ignore_null: true whitelist:
- "EXTERNAL"
Method 5:
filter:
- not:
term:
srx-source-zone-name: "EXTERNAL"
Am I missing something here ? I did not get any error when I run the rule but the filter is not negating the mentioned string.