Check the specified window

This commit is contained in:
Mark Veidemanis 2023-01-16 01:17:19 +00:00
parent 742a2f92da
commit 1964ab62ec
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 13 additions and 1 deletions

View File

@ -256,6 +256,16 @@ class ElasticsearchBackend(StorageBackend):
search_query = self.parse_query(
data, tags, None, False, add_bool, bypass_check=True
)
if rule_object.window is not None:
range_query = {
"range": {
"ts": {
"gt": f"now-{rule_object.window}/d",
"lt": "now/d",
}
}
}
add_top.append(range_query)
self.add_bool(search_query, add_bool)
self.add_top(search_query, add_top)
if "sentiment" in data:

View File

@ -137,7 +137,8 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
try:
# Passing db to avoid circular import
parsed_data = NotificationRuleData(self.request.user, cleaned_data, db=db)
parsed_data.test_schedule()
if cleaned_data["enabled"]:
parsed_data.test_schedule()
except RuleParseError as e:
self.add_error(e.field, f"Parsing error: {e}")
return

View File

@ -126,6 +126,7 @@ class NotificationRuleData(object):
self.cleaned_data = cleaned_data
self.db = db
self.data = self.cleaned_data.get("data")
self.window = self.cleaned_data.get("window")
self.parsed = None
self.aggs = {}