Frequency rule not working as expected, creating several matches and alerts
Hi,
With frequency rule below , with 4 HITS in one minute, i am getting more matches than one ( 2 matches ), which I think is not expected.
name: "INFO: Test frequency rule"
type: frequency
index: fluentd.openstack.*
realert:
minutes: 0
num_events: 2
timeframe:
minutes: 1
run_every:
minutes: 1
filter:
- query:
query_string:
query: 'TEST QUERY STRING'
alert:
- "slack"
slack:
slack_webhook_url: "SLACK_WEBHOOK_URL"
alert_text_type: aggregation_summary_only
summary_table_fields:
- "SOME_REQUEST_ID"
jira_server: "JIRA_SERVER"
jira_project: "JIRA_PROJECT"
jira_issuetype: "Task"
jira_account_file: "CREDS_FILE"
kibana_discover_version: "7.3"
kibana_discover_index_pattern_id: "INDEX_PATTERN_ID"
slack_attach_kibana_discover_url: True
jira_attach_kibana_discover_url: True
kibana_discover_columns:
- "SOME_REQUEST_ID"
- "message"
Per documentation ->
frequency: This rule matches when there are at least a certain number of events in a given time frame. This may be counted on a per-query_key basis.
Or in example rule for frequency :
Alert when this many documents matching the query occur within a timeframe
So , for me it sounds like it doesn't matter if i have 2 hits or 2000 hits, it should be one match.
Below you can find logfile
INFO:elastalert:Ran INFO: Test frequency rule from 2020-01-24 13:08 CET to 2020-01-24 13:12 CET: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2020-01-24 13:12:59,309 DEBG 'elastalert' stderr output:
INFO:elastalert:Queried rule INFO: Test frequency rule from 2020-01-24 13:08 CET to 2020-01-24 13:12 CET: 4 / 4 hits
2020-01-24 13:12:59,416 DEBG 'elastalert' stderr output:
INFO:elastalert:Background configuration change check run at 2020-01-24 13:12 CET
2020-01-24 13:12:59,440 DEBG 'elastalert' stderr output:
INFO:elastalert:Background alerts thread 0 pending alerts sent at 2020-01-24 13:12 CET
2020-01-24 13:12:59,585 DEBG 'elastalert' stderr output:
INFO:elastalert:Disabled rules are: []
2020-01-24 13:12:59,587 DEBG 'elastalert' stderr output:
INFO:elastalert:Sleeping for 59.999572 seconds
2020-01-24 13:12:59,793 DEBG 'elastalert' stderr output:
/venv/elastalert/lib/python3.7/site-packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
INFO:elastalert:Alert 'INFO: Test frequency rule' sent to Slack
2020-01-24 13:13:00,287 DEBG 'elastalert' stderr output:
/venv/elastalert/lib/python3.7/site-packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
INFO:elastalert:Alert 'INFO: Test frequency rule' sent to Slack
2020-01-24 13:13:00,435 DEBG 'elastalert' stderr output:
INFO:elastalert:Ran INFO: Test frequency rule from 2020-01-24 13:08 CET to 2020-01-24 13:12 CET: 4 query hits (0 already seen), 2 matches, 2 alerts sent
Is this expected behavious of frequency rule ?
Thanks, Michal Arbet (kevko)
Hi @keuko, did you solve the issue you mention above by adding #2653? Because I have tried it but I'm still facing the same problem as you did with my frequency rule, that is the following. If I get more than 1 event, I get different alerts and I don't expect that.
type: frequency
index: index
timestamp_field: time_stamp_corre
num_events: 1
timeframe:
# hours: 1
minutes: 2
realert:
minutes: 0
attach_related: true
filter:
- range:
tx_packets:
gt: 1000
- range:
rx_packets:
gt: 100
Thank you very much!
Hi @beaesteban01 ,
Yes, we have it fixed locally in company and working as expected (same patch - just cherry-picked). Could you please define which you are expecting and what are u getting ?
It's actually some time since I've prepared a patch (so don't remember code and details), BUT if I check differencies in our configurations, I have one option more in my config -> run_every , did you check this ? Did you try to tune it ?
If I remember correctly run_every also affecting time_frame which is analyzed ..so can affect also results (alerts)
@beaesteban01 and also check if logs are not OLD when elastalert starting, something like this https://github.com/Yelp/elastalert/issues/691 <<
And let me know :)
Hi @keuko, thanks for answering so fast!
My problem is the following: I have the frequency rule above to alert when 1 or more events with those characteristics arrive and attach the events to related_eventson the same alert. I am using the same rule for the same purpose but looking into another index and with num_events = 3 and it works as I expect (in terms of how the output info looks and the related events attached) but again this rule doesn't add more events than 3.
In this case, I am testing with 4 events:
-
if NO
run_everydefined, 4 different alerts triggerINFO:elastalert:Ran r2_wifi_pru from 2021-02-15 15:56 UTC to 2021-02-15 15:59 UTC: 7 query hits (3 already seen), 4 matches, 4 alerts sent -
if I set
run_every: minutes: 2again 4 different alertsINFO:elastalert:Ran r2_wifi_pru from 2021-02-15 16:13 UTC to 2021-02-15 16:17 UTC: 8 query hits (4 already seen), 4 matches, 4 alerts sent
I don't know what I am doing wrong but the rule doesn't add more than the number of events defined, even though I changed to your patch. And I have checked but the logs are not old, the elastalert_status index is very recent too...
Thank you very much!! :)
Hi @beaesteban01 ,
No problem , but I don't know if i will be able to help you, I am also only user and was debugging code some time ago, but will try to spent some time to check with you ..
Could you share your elastalert config ?
Michal
I appreciate it very much @keuko, I am a bit new with elastalert...
My configPrueba.yaml here. I just really have default config and changed the write back index (and also created it with elastalert-create-index --config configPrueba.yaml)
May the problem be that the default run_every : minutes: 1and my timeframe is 2 mins?
# This is the folder that contains the rule yaml files
# Any .yaml file will be loaded as a rule
rules_folder: correlation_rules_pruebas
# How often ElastAlert will query Elasticsearch
# The unit can be anything from weeks to seconds
run_every:
minutes: 1
# ElastAlert will buffer results from the most recent
# period of time, in case some log sources are not in real time
buffer_time:
minutes: 15
# The Elasticsearch hostname for metadata writeback
# Note that every rule can have its own Elasticsearch host
es_host: localhost
# The Elasticsearch port
es_port: 9200
# The AWS region to use. Set this when using AWS-managed elasticsearch
#aws_region: us-east-1
# The AWS profile to use. Use this if you are using an aws-cli profile.
# See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
# for details
#profile: test
# Optional URL prefix for Elasticsearch
#es_url_prefix: elasticsearch
# Connect with TLS to Elasticsearch
#use_ssl: True
# Verify TLS certificates
#verify_certs: True
# GET request with body is the default option for Elasticsearch.
# If it fails for some reason, you can pass 'GET', 'POST' or 'source'.
# See http://elasticsearch-py.readthedocs.io/en/master/connection.html?highlight=send_get_body_as#transport
# for details
#es_send_get_body_as: GET
# Option basic-auth username and password for Elasticsearch
#es_username: someusername
#es_password: somepassword
# Use SSL authentication with client certificates client_cert must be
# a pem file containing both cert and key for client
#verify_certs: True
#ca_certs: /path/to/cacert.pem
#client_cert: /path/to/client_cert.pem
#client_key: /path/to/client_key.key
# The index on es_host which is used for metadata storage
# This can be a unmapped index, but it is recommended that you run
# elastalert-create-index to set a mapping
writeback_index: elastalert_status_pruebas
writeback_alias: elastalert_alerts_pruebas
# If an alert fails for some reason, ElastAlert will retry
# sending the alert until this time period has elapsed
alert_time_limit:
days: 2
# Custom logging configuration
# If you want to setup your own logging configuration to log into
# files as well or to Logstash and/or modify log levels, use
# the configuration below and adjust to your needs.
# Note: if you run ElastAlert with --verbose/--debug, the log level of
# the "elastalert" logger is changed to INFO, if not already INFO/DEBUG.
#logging:
# version: 1
# incremental: false
# disable_existing_loggers: false
# formatters:
# logline:
# format: '%(asctime)s %(levelname)+8s %(name)+20s %(message)s'
#
# handlers:
# console:
# class: logging.StreamHandler
# formatter: logline
# level: DEBUG
# stream: ext://sys.stderr
#
# file:
# class : logging.FileHandler
# formatter: logline
# level: DEBUG
# filename: elastalert.log
# loggers:
# elastalert:
# level: WARN
# handlers: []
# propagate: true
#
# elasticsearch:
# level: WARN
# handlers: []
# propagate: true
#
# elasticsearch.trace:
# level: WARN
# handlers: []
# propagate: true
# '': # root logger
# level: WARN
# handlers:
# - console
# - file
# propagate: false
Bea