elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Seems Query Fileter Not Works

Open keyolk opened this issue 9 years ago • 6 comments

I'm trying to use the elastalert for my logging alert. below rule works well.

name: test
type: any
index: test-*
use_strftime_index: true

realert:
  minutes: 0

filter:
- query:
    query_string:
        query: "*"

alert:
- command

command: ["smsg.sh", "%(timestamp)s", "%(logger_id)s", "%(msg)s"]

but with below it just sleeps always .

name: test
type: any
index: test-*

filter:
- query:
    query_string:
        query: "level: error"

alert:
- command

command: ["smsg.sh", "%(timestamp)s", "%(logger_id)s", "%(msg)s"]
elastalert --config confs/config.yaml --rule rules/rule_error_smsg.yml --verbose
INFO:elastalert:Starting up
INFO:elastalert:Sleeping for 9.772058 seconds
INFO:elastalert:Sleeping for 9.99423 seconds
INFO:elastalert:Sleeping for 9.993578 seconds
INFO:elastalert:Sleeping for 9.993654 seconds
INFO:elastalert:Sleeping for 9.993486 seconds
INFO:elastalert:Sleeping for 9.993614 seconds

I can get log with curl

$ curl $ELASTICSEARCH_URL/_search -d '{"query":{"match":{ "level":"error"}} }'| json_reformat
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 2384,
    "max_score": 0.30750936,
    "hits": [
      {
...

Any points I have to check ?

keyolk avatar Aug 21 '17 02:08 keyolk

@keyolk

Remove the realert from the rule.yaml and put it in config.yaml and then give it a try.

sathishdsgithub avatar Aug 21 '17 03:08 sathishdsgithub

@sathishdsgithub Thanks, But there i no realert on rule.yaml which have problem

name: test
type: any
index: test-*

filter:
- query:
    query_string:
        query: "level: error"

alert:
- command

command: ["smsg.sh", "%(timestamp)s", "%(logger_id)s", "%(msg)s"]

keyolk avatar Aug 21 '17 04:08 keyolk

@keyolk

Please make sure the realert is not added in any rule.yaml and try to run the python with a specific rule as shown below.

python -m elastalert.elastalert --rule rules/rule_error_smsg.yml --verbose

sathishdsgithub avatar Aug 21 '17 06:08 sathishdsgithub

@sathishdsgithub I found something strange that If I lauch it on terminal directly, it works well. but used through Makefile, it always sleep.

Makefile

alert-error: ## Start alert for error log
  python -m elastalert.elastalert --config confs/config.yaml --rule rules/rule_error_smsg.yml --verbose
$ make alert-error
python -m elastalert.elastalert --config confs/config.yaml --rule rules/rule_error_smsg.yml --verbose                                                                                                                                                                                                                                             
INFO:elastalert:Starting up
INFO:elastalert:Sleeping for 9.992756 seconds
INFO:elastalert:Sleeping for 9.994193 seconds
INFO:elastalert:Sleeping for 9.993732 seconds
INFO:elastalert:Sleeping for 9.993721 seconds
INFO:elastalert:Sleeping for 9.992684 seconds
INFO:elastalert:Sleeping for 9.982215 seconds
INFO:elastalert:Sleeping for 9.992494 seconds
INFO:elastalert:Sleeping for 9.993416 seconds
$ python -m elastalert.elastalert --config confs/config.yaml  --rule rules/rule_error_docker_smsg.yml --verbose                                                                                                                                                                                                                    3m 16s 806ms│
INFO:elastalert:Starting up
INFO:elastalert:Queried rule test-es from 2017-08-21 17:40 KST to 2017-08-21 17:40 KST: 4 / 4 hits
INFO:elastalert:Ignoring match for silenced rule test-es
INFO:elastalert:Ignoring match for silenced rule test-es
INFO:elastalert:Ignoring match for silenced rule test-es
INFO:elastalert:Ignoring match for silenced rule test-es
INFO:elastalert:Ran test-es from 2017-08-21 17:40 KST to 2017-08-21 17:40 KST: 4 query hits (0 already seen), 4 matches, 0 alerts sent
INFO:elastalert:Sleeping for 9.944609 seconds
INFO:elastalert:Queried rule test-es from 2017-08-21 17:40 KST to 2017-08-21 17:40 KST: 4 / 4 hits
INFO:elastalert:Ran test-es from 2017-08-21 17:40 KST to 2017-08-21 17:40 KST: 4 query hits (4 already seen), 0 matches, 0 alerts sent
INFO:elastalert:Sleeping for 9.974346 seconds
INFO:elastalert:Queried rule test-es from 2017-08-21 17:40 KST to 2017-08-21 17:40 KST: 3 / 3 hits
INFO:elastalert:Ran test-es from 2017-08-21 17:40 KST to 2017-08-21 17:40 KST: 3 query hits (3 already seen), 0 matches, 0 alerts sent
INFO:elastalert:Sleeping for 9.961659 seconds
INFO:elastalert:Queried rule test-es from 2017-08-21 17:40 KST to 2017-08-21 17:41 KST: 28 / 28 hits
...

config.yml

rules_folder: rules
run_every:
  seconds: 10
realert:
  minutes: 0
buffer_time:
  minutes: 1
es_host: test.es
es_port: 29200
alert_time_limit:
  minutes: 1
old_query_limit:
  minutes: 1
writeback_index: elastalert_status  

keyolk avatar Aug 21 '17 08:08 keyolk

Are you in a different directory when using the Makefile?

--rule rules/rule_error_smsg.yml is using a relative file path, so it only works if you are in the parent directory of rules folder.

If you did --rule rule_error_smsg.yml, it should always work.

Qmando avatar Aug 22 '17 00:08 Qmando

@Qmando @sathishdsgithub Thanks all I found my mistake in Makefile, I had a mistypo for rule file name.

I think it would be better make elastalert to complain when rule file is not present.

keyolk avatar Aug 22 '17 03:08 keyolk