Make metadata return from search more flexible

This commit is contained in:
Mark Veidemanis 2023-01-16 07:20:37 +00:00
parent 2eb090f088
commit 4aa8e67e11
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 7 additions and 7 deletions

View File

@ -107,7 +107,7 @@ def format_webhook(**kwargs):
return notify_message return notify_message
def rule_notify(rule, index, message, matched): def rule_notify(rule, index, message, meta=None):
""" """
Send a notification for a matching rule. Send a notification for a matching rule.
Gets the notification settings for the rule. Gets the notification settings for the rule.
@ -115,7 +115,7 @@ def rule_notify(rule, index, message, matched):
:param rule: The rule object, must be specified :param rule: The rule object, must be specified
:param index: The index the rule matched on, can be None :param index: The index the rule matched on, can be None
:param message: The message to send, can be None :param message: The message to send, can be None
:param matched: The matched fields, can be None :param meta: dict of metadata, contains `aggs` key for the matched fields
""" """
# If there is no message, don't say anything matched # If there is no message, don't say anything matched
if message: if message:
@ -138,7 +138,7 @@ def rule_notify(rule, index, message, matched):
"rule": rule, "rule": rule,
"index": index, "index": index,
"message": message, "message": message,
"matched": matched, "matched": meta["aggs"],
"notification_settings": notification_settings, "notification_settings": notification_settings,
} }
@ -249,7 +249,7 @@ class NotificationRuleData(object):
return new_aggs return new_aggs
def rule_matched(self, index, message, aggs): def rule_matched(self, index, message, meta):
""" """
A rule has matched. A rule has matched.
If the previous run did not match, send a notification after formatting If the previous run did not match, send a notification after formatting
@ -262,8 +262,8 @@ class NotificationRuleData(object):
log.debug(f"Rule matched: {index} - current match: {current_match}") log.debug(f"Rule matched: {index} - current match: {current_match}")
if current_match is False: if current_match is False:
# Matched now, but not before # Matched now, but not before
formatted_aggs = self.format_aggs(aggs) meta["aggs"] = self.format_aggs(meta["aggs"])
rule_notify(self.object, index, message, formatted_aggs) rule_notify(self.object, index, message, meta)
self.store_match(index, True) self.store_match(index, True)
def rule_no_match(self, index=None): def rule_no_match(self, index=None):
@ -309,7 +309,7 @@ class NotificationRuleData(object):
if all(aggs_for_index): if all(aggs_for_index):
# All aggs have matched # All aggs have matched
self.rule_matched( self.rule_matched(
index, results[: self.object.amount], meta["aggs"] index, results[: self.object.amount], meta
) )
continue continue
# Default branch, since the happy path has a continue keyword # Default branch, since the happy path has a continue keyword