Add mode to stored rules output

This commit is contained in:
2023-02-08 18:26:40 +00:00
parent 7e78c2857e
commit 1b1dbbc76c
4 changed files with 24 additions and 7 deletions

View File

@@ -275,7 +275,7 @@ class NotificationRuleData(object):
return
async def ingest_matches(self, index, matches, meta):
async def ingest_matches(self, index, matches, meta, mode):
"""
Store all matches for an index.
:param index: the index to store the matches for
@@ -290,9 +290,10 @@ class NotificationRuleData(object):
matches_copy[match_index]["rule_uuid"] = self.object.id
matches_copy[match_index]["meta"] = meta
matches_copy[match_index]["match_ts"] = match_ts
matches_copy[match_index]["mode"] = mode
await self.db.async_store_matches(matches_copy)
async def rule_matched(self, index, message, meta):
async def rule_matched(self, index, message, meta, mode):
"""
A rule has matched.
If the previous run did not match, send a notification after formatting
@@ -305,10 +306,11 @@ class NotificationRuleData(object):
log.debug(f"Rule matched: {index} - current match: {current_match}")
if current_match is False:
# Matched now, but not before
meta["matched"] = self.format_aggs(meta["aggs"])
if "matched" not in meta:
meta["matched"] = self.format_aggs(meta["aggs"])
rule_notify(self.object, index, message, meta)
self.store_match(index, message)
await self.ingest_matches(index, message, meta)
await self.ingest_matches(index, message, meta, mode)
async def rule_no_match(self, index=None):
"""
@@ -352,7 +354,9 @@ class NotificationRuleData(object):
if len(aggs_for_index) == len(self.aggs.keys()):
if all(aggs_for_index):
# All aggs have matched
await self.rule_matched(index, results[: self.object.amount], meta)
await self.rule_matched(
index, results[: self.object.amount], meta, mode="schedule"
)
continue
# Default branch, since the happy path has a continue keyword
await self.rule_no_match(index)