Compare commits

..

No commits in common. "66232c8260752e74914f1de3021e127855af90fa" and "af5c2124503480417c2c498005bf9b8c0ca76764" have entirely different histories.

2 changed files with 6 additions and 20 deletions

View File

@ -71,10 +71,6 @@ class CustomUserCreationForm(UserCreationForm):
class NotificationSettingsForm(RestrictedFormMixin, ModelForm): class NotificationSettingsForm(RestrictedFormMixin, ModelForm):
def __init__(self, *args, **kwargs):
super(NotificationSettingsForm, self).__init__(*args, **kwargs)
self.fields["url"].label = "URL"
class Meta: class Meta:
model = NotificationSettings model = NotificationSettings
fields = ( fields = (
@ -100,10 +96,6 @@ class NotificationSettingsForm(RestrictedFormMixin, ModelForm):
class NotificationRuleForm(RestrictedFormMixin, ModelForm): class NotificationRuleForm(RestrictedFormMixin, ModelForm):
def __init__(self, *args, **kwargs):
super(NotificationRuleForm, self).__init__(*args, **kwargs)
self.fields["url"].label = "URL"
class Meta: class Meta:
model = NotificationRule model = NotificationRule
fields = ( fields = (
@ -135,8 +127,6 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
def clean(self): def clean(self):
cleaned_data = super(NotificationRuleForm, self).clean() cleaned_data = super(NotificationRuleForm, self).clean()
# TODO: should this be in rules.py?
if "service" in cleaned_data: if "service" in cleaned_data:
if cleaned_data["service"] == "webhook": if cleaned_data["service"] == "webhook":
if not cleaned_data.get("url"): if not cleaned_data.get("url"):

View File

@ -247,10 +247,7 @@ class NotificationRuleData(object):
if index is None: if index is None:
# Check if we have any matches on all indices # Check if we have any matches on all indices
values = self.object.match.values() return any(self.object.match.values())
if not values:
return None
return any(values)
# Check if it's the same hash # Check if it's the same hash
if match is not None: if match is not None:
@ -351,7 +348,7 @@ class NotificationRuleData(object):
self.ingest_matches_sync(index, message, meta, mode) self.ingest_matches_sync(index, message, meta, mode)
# No async helper for this one as we only need it for schedules # No async helper for this one as we only need it for schedules
async def rule_no_match(self, index=None, message=None): async def rule_no_match(self, index=None):
""" """
A rule has not matched. A rule has not matched.
If the previous run did match, send a notification if configured to notify If the previous run did match, send a notification if configured to notify
@ -367,7 +364,7 @@ class NotificationRuleData(object):
rule_notify(self.object, index, "no_match", None) rule_notify(self.object, index, "no_match", None)
self.store_match(index, False) self.store_match(index, False)
await self.ingest_matches( await self.ingest_matches(
index=index, message={}, meta={"msg": message}, mode="schedule" index=index, message={}, meta={"msg": "No matches"}, mode="schedule"
) )
async def run_schedule(self): async def run_schedule(self):
@ -379,12 +376,11 @@ class NotificationRuleData(object):
response = await self.db.schedule_query_results(self) response = await self.db.schedule_query_results(self)
if not response: if not response:
# No results in the result_map # No results in the result_map
print("No results in result_map") await self.rule_no_match()
await self.rule_no_match(message="No response from database")
for index, (meta, results) in response.items(): for index, (meta, results) in response.items():
if not results: if not results:
# Falsy results, no matches # Falsy results, no matches
await self.rule_no_match(index, message="No results for index") await self.rule_no_match(index)
# Add the match values of all aggregations to a list # Add the match values of all aggregations to a list
aggs_for_index = [] aggs_for_index = []
@ -402,7 +398,7 @@ class NotificationRuleData(object):
) )
continue continue
# Default branch, since the happy path has a continue keyword # Default branch, since the happy path has a continue keyword
await self.rule_no_match(index, message="Aggregation did not match") await self.rule_no_match(index)
def test_schedule(self): def test_schedule(self):
""" """