limit_execution: delayed notifications #1681
-
I have the following rules with different name: MonFriWorkTime
type: flatline
limit_execution: "* 6-19 * * 1-5"
threshold: 1
timeframe:
minutes: 10
name: MonFriNonWorkTime
type: flatline
limit_execution: "* 0-5,20-23 * * 1-5"
threshold: 1
timeframe:
minutes: 30
name: SatSun
type: flatline
limit_execution: "* * * * 6,0"
threshold: 1
timeframe:
minutes: 30 I expect to receive alerts within the time interval specified in {
"_index": "elastalert",
"_type": "_doc",
"_id": "OA-FoJcBWBDl74cr2ge3",
"_score": 0.0,
"_source": {
"match_body": {
"@timestamp": "2025-06-23T23:57:23.663253Z",
"key": "all",
"count": 0,
"threshold": 1,
"num_hits": 330,
"num_matches": 2
},
"rule_name": "MonFriWorkTime",
"alert_info": {
"type": "alertmanager"
},
"alert_sent": true,
"alert_time": "2025-06-24T06:00:16.237305Z",
"match_time": "2025-06-23T23:57:23.663253Z",
"@timestamp": "2025-06-24T06:00:16.309467Z"
}
} This results in delayed notifications. How can I fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
Therefore, when the rule is allowed to run again, it will continue where it left off. The purpose of this is to stop people from getting alerts outside of business hours, not to completely ignore triggerable events that occurred outside of the execution window. It does not trigger outside of the execution window, but yes, once it runs again it indeed can still find those matching events that had previously occurred. To completely ignore events that occurred outside of the execution window you might be able to specific that in the filter. But I haven't tried it and you'd have to read up on that range filter syntax. |
Beta Was this translation helpful? Give feedback.
-
So, I need to implement |
Beta Was this translation helpful? Give feedback.
-
Actually, that's not quite accurate. For
|
Beta Was this translation helpful? Give feedback.
-
Enhancements: import datetime
from croniter import croniter
from elastalert.enhancements import BaseEnhancement, DropMatchException
class LimitExecutionEnhancement(BaseEnhancement):
def process(self, match):
limit = self.rule.get('limit_execution')
if not limit:
return
ts = match.get('@timestamp')
if not ts:
return
event_time = datetime.datetime.fromisoformat(ts.replace("Z", "+00:00"))
if not croniter.match(limit, event_time):
raise DropMatchException() |
Beta Was this translation helpful? Give feedback.
Enhancements: