Cardinality rule type and top_count_keys
Hello everybody,
I try to use top_count_keys in a cardinality rule type but I can't succeed to make it works :
name: "##PortScan"
index: firewall_*
type: cardinality
query_key: [event_ip,src_ip,dst_port]
cardinality_field: dst_ip
max_cardinality: 25
buffer_time:
minutes: 5
timeframe:
minutes: 5
filter:
- query:
query_string:
query: 'event_device:Firewall AND dst_port:(1 OR 5 OR 7 OR 18 OR 20 OR 21 OR 22 OR 23)
top_count_number: 10
raw_count_keys: false
include:
- src_ip
- source
- dst_ip
- dst_port
- event_ip
top_count_keys: ["dst_ip"]
alert_text_type: exclude_fields
Alerts is working but no top_count_keys in alert output:
dst_ip: No events found.
I tried with raw_count_keys: false disabled but same issue :
dst_ip.raw: No events found.
Does anybody else has the same issue ?
I see what the bug is. If you have compound query_key, it will construct an incorrect filter when trying to query for the dst_ip. I don't have time to fix this immediately, but I can offer you a patch that may help:
--- a/elastalert/ruletypes.py
+++ b/elastalert/ruletypes.py
@@ -858,6 +858,7 @@ class CardinalityRule(RuleType):
self.check_for_match(key, event, False)
else:
self.first_event.pop(key, None)
+ event['values'] = self.cardinality_cache[key]
self.add_match(event)
This will let you see all the 25 values of dst_ip that triggered the alert. I should definitely just add this as a feature...
Let me know if it works for your needs and I'll hopefully get around to fixing this bug sometime.
@Qmando Thanks for the patch. I try this as soon as possible and will let you updated !
Fixed by #1793