Elastalert process hung
Hi @Qmando
I have 120 rule files in a directory. Elastalert process is getting hung(will not send any alerts) without showing any anomalies in elastalert logs.
Sometime this will run more than 24hours without any issue. I could n’t find out exactly when this is getting hung. I used to kill Elastalert process and start again usually whenever this is hung.
Can you please help me to resolve this issue.
Hi @Qmando Waiting for your valuable reply.
What was the last line printed before it hung?
Hi @Qmando , Thank you for your reply. Please find attached log( Last 100 lines before it hung).
[root@ip-172-31-82-238 centos]# tail -100f /var/log/supervisord/supervisor.log
2018-04-03 20:18:02,689 DEBG 'elastalert' stderr output: INFO:elastalert:Ran SID history was added to an account from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,695 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule special groups have been assigned to a new logon from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,703 DEBG 'elastalert' stderr output: INFO:elastalert:Ran special groups have been assigned to a new logon from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,716 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule special groups logon table modified from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,724 DEBG 'elastalert' stderr output: INFO:elastalert:Ran special groups logon table modified from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,731 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule system audit policy was changed from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,739 DEBG 'elastalert' stderr output: INFO:elastalert:Ran system audit policy was changed from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,745 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule system security access was granted to an account from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,753 DEBG 'elastalert' stderr output: INFO:elastalert:Ran system security access was granted to an account from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,759 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule system security access was removed from an account from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,768 DEBG 'elastalert' stderr output: INFO:elastalert:Ran system security access was removed from an account from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,774 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the acl was set on accounts which are members of administrators groups from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,782 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the acl was set on accounts which are members of administrators groups from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,789 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the audit filter for certificate services changed from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,797 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the audit filter for certificate services changed from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,803 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the audit log was cleared from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,810 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the audit log was cleared from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,817 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the audit policy (SACL) on an object was changed from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,825 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the audit policy (SACL) on an object was changed from 2018-04-03 20:06 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,832 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the domain controller failed to validate the credentials for an account from 2018-04-03 19:57 UTC to 2018-04-03 20:12 UTC: 0 / 0 hits
2018-04-03 20:18:02,838 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the domain controller failed to validate the credentials for an account from 2018-04-03 20:12 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,845 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the domain controller failed to validate the credentials for an account from 2018-04-03 19:57 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,851 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the name of an account was changed from 2018-04-03 19:57 UTC to 2018-04-03 20:12 UTC: 0 / 0 hits
2018-04-03 20:18:02,857 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the name of an account was changed from 2018-04-03 20:12 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,864 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the name of an account was changed from 2018-04-03 19:57 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,871 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the password hash an account was accessed from 2018-04-03 19:57 UTC to 2018-04-03 20:12 UTC: 0 / 0 hits
2018-04-03 20:18:02,877 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the password hash an account was accessed from 2018-04-03 20:12 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,889 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the password hash an account was accessed from 2018-04-03 19:57 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,895 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the system time was changed from 2018-04-03 19:57 UTC to 2018-04-03 20:12 UTC: 0 / 0 hits
2018-04-03 20:18:02,901 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule the system time was changed from 2018-04-03 20:12 UTC to 2018-04-03 20:18 UTC: 0 / 0 hits
2018-04-03 20:18:02,908 DEBG 'elastalert' stderr output: INFO:elastalert:Ran the system time was changed from 2018-04-03 19:57 UTC to 2018-04-03 20:18 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
2018-04-03 20:18:02,957 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule Threat Detected Ips from 2018-04-03 19:57 UTC to 2018-04-03 20:12 UTC: 120 / 120 hits
2018-04-03 20:18:03,014 DEBG 'elastalert' stderr output: INFO:elastalert:Queried rule Threat Detected Ips from 2018-04-03 20:12 UTC to 2018-04-03 20:18 UTC: 164 / 44 hits
Hi @Qmando , Thanks for your support.
I am waiting for your valuable reply.
Really in trouble due to this unknown elastalert hung issue.
Can you share the "Threat Detected Ips" rule? Remove any sensitive info. Stopping in the middle of the query seems very odd. Also, what version of elastalert is running?
Hi @Qmando Thanks a lot for your prompt reply.
Elasticsearch version: 5.5.3 $ pip install "elasticsearch>=5.0.0"
Threat Detected IPs Rule:
# Alert when the rate of events exceeds a threshold
# (Optional)
# Elasticsearch host
# (Optional)
# Elasticsearch port
# (OptionaL) Connect with SSL to Elasticsearch
#use_ssl: True
# (Optional) basic-auth username and password for Elasticsearch
#es_username: someusername
#es_password: somepassword
# (Required)
# Rule name, must be unique
name: Threat Detected Ips
# (Required)
# Type of alert.
# the any rule type alerts when each events occur in elasticsearch index
type: any
# (Required)
# Index to search, wildcard supported
index: threat-ips-*
# (Required)
# A list of Elasticsearch filters used for find events
# These filters are joined with AND and nested in a filtered query
# For more info: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html
owner: Support Team
priority: 1
# (Required)
# The alert is use when a match is found
alert:
- "email"
- [email protected]
from_addr: email@mailcom
smtp_host: smtp.office365.com
smtp_port: 587
smtp_auth_file: /home/centos/smtp_auth.yml
What about elastalert version, not elasticsearch. Either pip freeze | grep elastalert or look in elastalert/setup.py
Hi @Qmando Thanks for your support.
Elastalert Version: 0.1.21
Hi @Qmando
I am waiting for your valuable reply.
Thank you.
I don't know what the issue is. I've never a query freeze midway before. It seems to be getting stuck either while querying elasticsearch or while sending the alert emails, both of which I would expect timeout instead of freezing.
If you can figure out a way to reproduce this behavior, then we may be able to debug further.
I am not able to find out exactly when it is getting hung. My elastalert was hung 12 hours ago today and i restarted. Now it’s working fine. Don’t know when it is going to hung next time, may be tomorrow or day after tomorrow.
Hi @Qmando
Thanks for your reply.
The configuration file is given below. Please let me know if any corrections required in this. I have 126 rule files in this directory- /home/centos/elastalert/rules.
This is the folder that contains the rule yaml files
Any .yaml file will be loaded as a rule
rules_folder: /home/centos/elastalert/rules
How often ElastAlert will query Elasticsearch
The unit can be anything from weeks to seconds
run_every: minutes: 10
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: xxxxxxx es_username: xxx es_password: xxx
The Elasticsearch port
es_port: xxxx
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 #protocol: https
Verify TLS certificates
#verify_certs: False
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
If an alert fails for some reason, ElastAlert will retry
sending the alert until this time period has elapsed
alert_time_limit: days: 2
Hi @Qmando
I have noticed that even after elastalert hung documents getting indexed in writeback index with Zero matches, But in elastalert log, no new lines coming. That means I think it's not actually hung, but somehow this stops matching.
Can you please shed some light on this.
Maybe it's a bug or misconfiguration with supervisord
Hi @Qmando Thanks for your reply.
I have two elastalert process running. One with supervisord and another one without supervisord. Both are showing the same behavior.
Now elastalert process which is running without supervisord is hung.
Other one anomaly that I have noticed is that the time_taken field in writeback index showing values more than 15min in some of the documents. For example: { "_index": "fvc_alerts", "_type": "elastalert_status", "_id": "AWKbigehROtDqqIeJ4lA", "_version": 1, "_score": null, "_source": { "hits": 4, "matches": 4, "@timestamp": "2018-04-06T15:18:57.184989Z", "rule_name": "a logon was attempted using explicit credentials", "starttime": "2018-04-06T14:58:54.064502Z", "endtime": "2018-04-06T15:18:40.890993Z", "time_taken": 16.29398822784424
}, "fields": { "@timestamp": [ 1523027937184 ], "endtime": [ 1523027920890 ], "starttime": [ 1523026734064 ] }, "sort": [ 1523027937184 ] }
Hi @Qmando
Please see the below document in writeback index. time_taken: 296m. Is this the reason for hung OR stop matching?
Can you please shed some light on this.
{ "_index": "fvc_alerts", "_type": "elastalert_status", "_id": "AWKYFnH-ROtDqqIeJ021", "_version": 1, "_score": null, "_source": { "hits": 33, "matches": 18, "@timestamp": "2018-04-05T23:13:50.589619Z", "rule_name": "Suspicious Connection Resets", "starttime": "2018-04-05T22:48:53.744596Z", "endtime": "2018-04-05T23:08:53.899601Z", "time_taken": 296.6900110244751 }, "fields": { "endtime": [ 1522969733899 ], "@timestamp": [ 1522970030589 ], "starttime": [ 1522968533744 ] }, "sort": [ 1522970030589 ] }
time_taken is measured in seconds, so that would be about 5 minutes. 33 hits and 18 matches is a pretty small number, so it shouldn't be this slow.
I've seen this occur with enhancements and modules that are doing weird things, but you just have standard email alerter right?
There could be issues related to connecting to the smtp server causing it to be extremely slow.
Yes, we are using standard email alerter. But why it goes hung. now all the documents indexing in writeback index is with hits:0 and matches:0.
Can you please let me know if you guys are providing any kind of paid support, so I can provide ssh access to have a look and solve this issue.
Hi @Qmando The elastlalert process is hung for last 4hours but i have noticed two alerts matched and sent during this time.
If its smtp connection issue, how can i resolve this? Can you please shed some light.
If it's still sending alerts, it's not hung. Try running it outside of supervisord?