elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

frequency type filtering not working

Open luvpreetsingh opened this issue 9 years ago • 21 comments

I have this alert rule.

es_host: localhost
es_port: 9200
name: infotrack matching rule
index: nginx-logs-alpha-parsed
filter:
- term:
     request: "/infotrack"
type: frequency 
num_events: 5
timeframe:
     minutes: 15
alert:
- "email"
email:
- "[email protected]"

This says that send me an email if request == /infotrack occurs for more than 5 times in 15 minutes.

This happens when I run this,

monitoring-server@monitoring-server:/etc/elastalert$ python -m elastalert.elastalert --verbose --rule alert_rules/infotrack_match_rule.yaml
INFO:elastalert:Starting up
INFO:elastalert:Queried rule infotrack matching rule from 2017-07-23 12:42 UTC to 2017-07-23 12:47 UTC: 0 / 0 hits
INFO:elastalert:Queried rule infotrack matching rule from 2017-07-23 12:47 UTC to 2017-07-23 12:52 UTC: 0 / 0 hits
INFO:elastalert:Queried rule infotrack matching rule from 2017-07-23 12:52 UTC to 2017-07-23 12:57 UTC: 0 / 0 hits
INFO:elastalert:Queried rule infotrack matching rule from 2017-07-23 12:57 UTC to 2017-07-23 13:02 UTC: 0 / 0 hits
INFO:elastalert:Queried rule infotrack matching rule from 2017-07-23 13:02 UTC to 2017-07-23 13:03 UTC: 0 / 0 hits
INFO:elastalert:Ran infotrack matching rule from 2017-07-23 12:42 UTC to 2017-07-23 13:03 UTC: 0 query hits (0 already seen), 0 matches, 0 alerts sent
INFO:elastalert:Sleeping for 59.965402 seconds

But in my kibana, I can see that 15 events have occured in the last minutes. So it should notify me but it does not.

image

Why it is getting 0 hits ?

luvpreetsingh avatar Jul 23 '17 13:07 luvpreetsingh

@luvpreetsingh

Verify the queried index: nginx-logs-alpha-parsed name is correct ?.

I had experienced the same issue, if possible use * at the end of the index name.

sathishdsgithub avatar Jul 23 '17 13:07 sathishdsgithub

The name is correct.

I did try it with different names, nginx-logs-alpha-parsed*and nginx-logs-alpha-*.

But did not work.

luvpreetsingh avatar Jul 23 '17 17:07 luvpreetsingh

@luvpreetsingh

Could you please check this https://github.com/Yelp/elastalert/issues/832 and see if it helps to fix your issue.

sathishdsgithub avatar Jul 24 '17 04:07 sathishdsgithub

In that issue there was problem with the alerts when there were hits.

But I am getting 0 hits.

Other rules are working fine, do you think there could be problem due to the /(slash) in front of the query ?

luvpreetsingh avatar Jul 24 '17 07:07 luvpreetsingh

I guess this is the case.

The below query works pretty well,

filter:
- term:
     status: "500"

but when I use it with the above query,

filter:
- term:
     status: "500"
- term:
     request: "/infotrack"

It does not give any hits even when there is data present.

Here is the proof that there is data, I am getting hits in kibana.

image 1

luvpreetsingh avatar Jul 24 '17 07:07 luvpreetsingh

This works,

filter:
- term:
     request: "infotrack"

luvpreetsingh avatar Jul 24 '17 11:07 luvpreetsingh

Hi @luvpreetsingh

Any idea how to handle / or blank space or . in the filter text.?

Thanks

anjan-cele avatar Aug 09 '17 11:08 anjan-cele

Hi @anjan-cele , What is the position of / or . or blank space in your text ? At the starting or in the middle ?

luvpreetsingh avatar Aug 09 '17 11:08 luvpreetsingh

Hi @luvpreetsingh

Position is after the word. I have an error message which is being shown in Kibana but 0 query hits in elastalert.

filter:

  • term: message: "download request failed and found the data stream is not readable"

Thanks

anjan-cele avatar Aug 09 '17 11:08 anjan-cele

I think it should work. Maybe you need to escape white spaces. Maybe @sathishdsgithub can help you.

luvpreetsingh avatar Aug 09 '17 11:08 luvpreetsingh

Hi @sathishdsgithub

With respect to above conversation, how can I escape whitespaces?

Thanks

FYI @luvpreetsingh

anjan-cele avatar Aug 09 '17 11:08 anjan-cele

@anjan-cele read this: https://www.elastic.co/blog/found-text-analysis-part-1

Full text fields are split into individual words, stripped of punctuation, and lowercased. "Hello world!" becomes two tokens ['hello', 'world']

term:
  field: "HELLO"

would not match because "HELLO" != "hello"

but

term:
  field: "world"

would match.

You can also just use query string and it will take care of analyzing for you.

filter:
 - query:
      query_string:
        query: "field: HELLO"

and

filter:
 - query:
      query_string:
        query: "field: hello!"

would both match.

Read https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html too

Qmando avatar Aug 10 '17 21:08 Qmando

@Qmando

Thanks for helping me out. query_string is working fine for me. Thanks

I have a new issue like :

In my log - suppose there is 2 error message like :

Download error for account id : 10 Download error for account id : 20

and I have given my filter as

filter:

  • query: query_string: query: "message: "Download error for account id""

It is alerting the first one and ignoring the second one. Is there any way to get both alert? These account Id is a dynamic value, it can change for next loggings according to errors. The logging is happening almost at the same time, so Elastalert is taking it as Already Seen hit. But it is a different hit with different value.

Please suggest. Thanks

anjan-cele avatar Aug 11 '17 10:08 anjan-cele

@anjan-cele

The query should match the both, have you tried something like below. Replace` the " " with ' '

filter:
 - query:
      query_string:
        query: 'message: "Download error for account id"'

sathishdsgithub avatar Aug 11 '17 11:08 sathishdsgithub

@anjan-cele What do you mean by "ignoring the second one". Are you getting a log line "Ignoring match for silenced rule ..."?

Qmando avatar Aug 14 '17 16:08 Qmando

Hi @Qmando

"ignoring the second one" means that I am getting only one mail alert for the first logged error only. i.e Download error for account id : 10.

Yes I am getting a log line as you said above.

My requirement is like there is 2 error message, so I should get 2 alert mail. Though the search query_string is same.

Please suggest.

anjan-cele avatar Aug 14 '17 17:08 anjan-cele

Then add

realert:
  minutes: 0

https://github.com/Yelp/elastalert#why-did-i-only-get-one-alert-when-i-expected-to-get-several

Qmando avatar Aug 14 '17 17:08 Qmando

Hi @Qmando

I have added this :

realert: minutes: 0

But still I am not getting both alerts. I tried seconds: 0 also but not worked.

My both log timings are as: August 16th 2017, 15:55:00.881 August 16th 2017, 15:54:59.873

Please suggest

Thanks

anjan-cele avatar Aug 16 '17 15:08 anjan-cele

Post your full rule YAML and the output from running elastalert including the "Ignoring match.. " line

Qmando avatar Aug 16 '17 17:08 Qmando

Hi @Qmando

Here it is...

name: Gemini Helper Error Rule
type: frequency
index: logstash-*
num_events: 2
timeframe:
  hours: 4
filter:
- query:
      query_string:
        query: "message: \"Processing error response for advertiser\""
alert:
- "email"
smtp_host: SMTPServername
smtp_ssl: false
from_addr: myemail
email:
- myemail
realert:
  minutes: 0

I have attached the Kibana UI screenshot for logs. There is 2 logging happened at approx 3.55 PM IST, I got 1 2 log mail for the first but not for the 2nd.

Log says like :

Aug 16 06:39:17 amdc2webl24 elastalert[26739]: INFO:elastalert:Queried rule Gemini Helper Error Rule from 2017-08-15 10:57 EDT to 2017-08-16 06:39 EDT: 8 / 8 hits
Aug 16 06:39:21 amdc2webl24 elastalert[26739]: INFO:elastalert:Sent email to [ '[email protected]']
Aug 16 06:39:21 amdc2webl24 elastalert[26739]: INFO:elastalert:Ran Gemini Helper Error Rule from 2017-08-15 10:57 EDT to 2017-08-16 06:39 EDT: 8 query hits (6 already seen), 1 matches, 1 alerts sent
  1. Why 1 matches here? In attached image you can see 2 are there at approx 3.55 PM IST?

6 hits earlier was 4 hours before. And there is no silence line occurred.

Please suggest

anjan-cele avatar Aug 16 '17 20:08 anjan-cele