Update pre-commit versions
This commit is contained in:
@@ -11,7 +11,6 @@ except ImportError:
|
||||
from datetime import datetime
|
||||
|
||||
import orjson
|
||||
from asgiref.sync import async_to_sync
|
||||
from siphashc import siphash
|
||||
|
||||
from core.lib.notify import sendmsg
|
||||
@@ -182,6 +181,7 @@ class NotificationRuleData(object):
|
||||
self.db = db
|
||||
self.data = self.cleaned_data.get("data")
|
||||
self.window = self.cleaned_data.get("window")
|
||||
self.policy = self.cleaned_data.get("policy")
|
||||
self.parsed = None
|
||||
self.aggs = {}
|
||||
|
||||
@@ -323,6 +323,9 @@ class NotificationRuleData(object):
|
||||
"""
|
||||
current_match = self.get_match(index, message)
|
||||
log.debug(f"Rule matched: {index} - current match: {current_match}")
|
||||
|
||||
# Default policy: Trigger only when results change
|
||||
|
||||
if current_match is False:
|
||||
# Matched now, but not before
|
||||
if "matched" not in meta:
|
||||
@@ -342,6 +345,8 @@ class NotificationRuleData(object):
|
||||
"""
|
||||
current_match = self.get_match(index, message)
|
||||
log.debug(f"Rule matched: {index} - current match: {current_match}")
|
||||
|
||||
# Default policy: Trigger only when results change
|
||||
if current_match is False:
|
||||
# Matched now, but not before
|
||||
if "matched" not in meta:
|
||||
@@ -361,6 +366,8 @@ class NotificationRuleData(object):
|
||||
"""
|
||||
current_match = self.get_match(index)
|
||||
log.debug(f"Rule not matched: {index} - current match: {current_match}")
|
||||
|
||||
# Change policy: When there are no results following a successful run
|
||||
if current_match is True:
|
||||
# Matched before, but not now
|
||||
if self.object.send_empty:
|
||||
@@ -407,13 +414,10 @@ class NotificationRuleData(object):
|
||||
def test_schedule(self):
|
||||
"""
|
||||
Test the schedule query to ensure it is valid.
|
||||
Run the query with the async_to_sync helper so we can call it from
|
||||
a form.
|
||||
Raises an exception if the query is invalid.
|
||||
"""
|
||||
if self.db:
|
||||
sync_schedule = async_to_sync(self.db.schedule_query_results)
|
||||
sync_schedule(self)
|
||||
self.db.schedule_query_results_test_sync(self)
|
||||
|
||||
def validate_schedule_fields(self):
|
||||
"""
|
||||
@@ -476,9 +480,10 @@ class NotificationRuleData(object):
|
||||
raise RuleParseError(
|
||||
"Field tags cannot be used with on-demand rules", "data"
|
||||
)
|
||||
if self.cleaned_data["send_empty"]:
|
||||
if self.policy != "default":
|
||||
raise RuleParseError(
|
||||
"Field cannot be used with on-demand rules", "send_empty"
|
||||
f"Cannot use {self.cleaned_data['policy']} policy with on-demand rules",
|
||||
"policy",
|
||||
)
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user