Check the specified window
This commit is contained in:
parent
742a2f92da
commit
1964ab62ec
|
@ -256,6 +256,16 @@ class ElasticsearchBackend(StorageBackend):
|
||||||
search_query = self.parse_query(
|
search_query = self.parse_query(
|
||||||
data, tags, None, False, add_bool, bypass_check=True
|
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_bool(search_query, add_bool)
|
||||||
self.add_top(search_query, add_top)
|
self.add_top(search_query, add_top)
|
||||||
if "sentiment" in data:
|
if "sentiment" in data:
|
||||||
|
|
|
@ -137,7 +137,8 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
||||||
try:
|
try:
|
||||||
# Passing db to avoid circular import
|
# Passing db to avoid circular import
|
||||||
parsed_data = NotificationRuleData(self.request.user, cleaned_data, db=db)
|
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:
|
except RuleParseError as e:
|
||||||
self.add_error(e.field, f"Parsing error: {e}")
|
self.add_error(e.field, f"Parsing error: {e}")
|
||||||
return
|
return
|
||||||
|
|
|
@ -126,6 +126,7 @@ class NotificationRuleData(object):
|
||||||
self.cleaned_data = cleaned_data
|
self.cleaned_data = cleaned_data
|
||||||
self.db = db
|
self.db = db
|
||||||
self.data = self.cleaned_data.get("data")
|
self.data = self.cleaned_data.get("data")
|
||||||
|
self.window = self.cleaned_data.get("window")
|
||||||
self.parsed = None
|
self.parsed = None
|
||||||
self.aggs = {}
|
self.aggs = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue