@mikecote, Thank you for the reply. We have enabled debug logging in Kibana and the concerned log lines are below
We are trying to alert when a document match the search filters. So, we are running the alert EVERY 1 MINUTE and match IS ABOVE 0 FOR THE LAST 1 minute.
It seems, eventhough there are matching documents in the target index, stackAlerts elasticsearch query do not find it, most of the time. Please see below.
E.g.
document at @15:07:36.395 is not hit by query at 2021-07-14T15:07:55+05:30
document at @15:07:56.174 is missed by query at 2021-07-14T15:08:58+05:30
Was expecting the THE LAST 1 minute
verb will hit the documents of the past 1 minute, is this correct?
> tail -f /var/log/kibana/kibana.log | grep --line-buffered '"debug","plugins","stackAlerts"'
{"type":"log","@timestamp":"2021-07-14T14:57:25+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:27:25.342Z\",\"gte\":\"2021-07-14T09:26:25.342Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T14:57:25+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":0,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
{"type":"log","@timestamp":"2021-07-14T15:04:46+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:34:46.380Z\",\"gte\":\"2021-07-14T09:33:46.380Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:04:46+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":0,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
{"type":"log","@timestamp":"2021-07-14T15:07:55+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:37:55.432Z\",\"gte\":\"2021-07-14T09:36:55.432Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:07:55+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":1,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
{"type":"log","@timestamp":"2021-07-14T15:08:58+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:38:58.433Z\",\"gte\":\"2021-07-14T09:37:58.433Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:08:58+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":1,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
{"type":"log","@timestamp":"2021-07-14T15:10:01+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:40:01.430Z\",\"gte\":\"2021-07-14T09:39:01.430Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:10:01+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":8,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
{"type":"log","@timestamp":"2021-07-14T15:12:07+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:42:07.568Z\",\"gte\":\"2021-07-14T09:41:07.568Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:12:07+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":0,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
{"type":"log","@timestamp":"2021-07-14T15:13:10+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T09:43:10.469Z\",\"gte\":\"2021-07-14T09:42:10.469Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:13:10+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":2,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[]}}"}
Have removed some log entries to reduce reply size.
The documents are available, as seen in the Discover for the above tested log time
Jul 14, 2021 @ 15:13:59.869 login login XXX
Jul 14, 2021 @ 15:09:00.240 login login XXX
Jul 14, 2021 @ 15:07:56.174 login login XXX
Jul 14, 2021 @ 15:07:36.395 login login XXX
Jul 14, 2021 @ 15:03:56.566 login login XXX
Jul 14, 2021 @ 14:47:47.021 login login XXX
During this testing period, the only following document was matched and alerted
Time message.model message.action agent.id
Jul 14, 2021 @ 15:34:14.550 login login XXX
{"type":"log","@timestamp":"2021-07-14T15:35:13+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" query - {\"allow_no_indices\":true,\"index\":[\"logs-events-xx\"],\"size\":10,\"ignore_unavailable\":true,\"track_total_hits\":true,\"body\":{\"docvalue_fields\":[{\"field\":\"@timestamp\",\"format\":\"strict_date_optional_time\"}],\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"filter\":[{\"bool\":{\"must\":[{\"term\":{\"message.model\":\"login\"}},{\"term\":{\"message.action\":\"login\"}}]}},{\"bool\":{\"must_not\":[{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T07:17:04.204Z\"}}}]}}]}}]}},{\"bool\":{\"filter\":[{\"range\":{\"@timestamp\":{\"lte\":\"2021-07-14T10:05:13.797Z\",\"gte\":\"2021-07-14T10:04:13.797Z\",\"format\":\"strict_date_optional_time\"}}}]}},{\"match_all\":{}}]}},\"sort\":[{\"@timestamp\":{\"order\":\"desc\"}}]}}"}
{"type":"log","@timestamp":"2021-07-14T15:35:14+05:30","tags":["debug","plugins","stackAlerts"],"pid":18575,"message":"alert .es-query:XXX \"alert events login\" result - {\"took\":612,\"timed_out\":false,\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0},\"hits\":{\"total\":{\"value\":1,\"relation\":\"eq\"},\"max_score\":null,\"hits\":[DOCUMENT]},\"sort\":[1626257054550]}]}}"}
So, our alert rules do not raise any alert for the matching documents, but only for a few. Can you please help debug?