So I'm trying to figure out a way to deal with delays from when a message is received by a collector, when a message is finally indexed in Elastic and when watcher finally runs the query that generates an alert.
As an example, a system generates two events that get received by logstash with the following timestamps:
2016-06-16T00:02:26.091Z
2016-06-16T00:02:26.092Z
It takes an indeterminate amount of time for these documents to finally land into elastic (>10s)
When a configured watcher runs, it runs its query with a filter that should be the last 10 seconds?
"filter": {
"range": {
"@timestamp" : {
"from": "{{ctx.trigger.scheduled_time}}||-10s",
"to": "{{ctx.trigger.triggered_time}}"
}
}
}
This results in a scheduled time of 2016-06-16T00:02:41.492Z, which -10 seconds should be 2016-06-16T00:02:31.492Z.
But because my events were received by logstash longer than 10 seconds ago, and took a long time to get into elastic, these events are missed by Watcher. The only way I'm able to receive events is if I set a long offset in my query filter. How do I work around this issue? I run the risk of triggering duplicate alerts as the latency between logstash and elastic varies.
It would be nice if you could set the last time a watcher ran as a value in your filter. Something like {{ctx.trigger.last_run_time}}. Then you could guarantee that watcher is catching everything that happened between runs? Maybe you can and I'm missing something?
"trigger" : {
"schedule" : { "interval" : "10s" }
},
"input" : {
"search" : {
"request" : {
"indices" : [
"myindex*"
],
"body" : {
"query": {
"query_string": {
"analyze_wildcard": true,
"query": "query"
}
},
"filter": {
"range": {
"@timestamp" : {
"from": "{{ctx.trigger.scheduled_time}}||-10s",
"to": "{{ctx.trigger.triggered_time}}"
}
}
}
}
}
}
},
"condition" : {
"compare" : {
"ctx.payload.hits.total" : {
"gte" : 1
}
}
},
"actions" : {
"email_admin" : {
"email" : {
"from":"from@domain.com",
"to" : "to@domain.com",
"subject" : "Email Subject",
"body" : {
"html" : "Message body"
}
}
}
}