Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1589 from mozilla/add_custom_tags_genericdeadman
Browse files Browse the repository at this point in the history
Add custom tags to deadman generic alert
  • Loading branch information
Phrozyn committed Apr 9, 2020
2 parents d42a5be + 644fc3f commit 6cc0a1e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions alerts/deadman_generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"description": "Sample Alert 1",
"search_query": "ABC12345436",
"time_window": "5",
"time_window_type": "minutes"
"time_window_type": "minutes",
"tags": ["generic_deadman"]
},
{
"description": "Sample Alert 2",
"search_query": "anotherterm",
"time_window": "20",
"time_window_type": "hours"
"time_window_type": "hours",
"tags": ["someothertag"]
}
]
}
7 changes: 6 additions & 1 deletion alerts/deadman_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def main(self):
def process_alert(self, alert_config):
self.current_alert_time_window = int(alert_config['time_window'])
self.current_alert_time_type = alert_config['time_window_type']
self.custom_tags = alert_config['tags']
search_query_time_window = {self.current_alert_time_type: self.current_alert_time_window}
search_query = SearchQuery(**search_query_time_window)
search_query.add_must(QueryStringMatch(str(alert_config['search_query'])))
Expand All @@ -42,7 +43,11 @@ def process_alert(self, alert_config):
# if no events found
def onNoEvent(self, description):
category = 'deadman'
tags = ['deadman', 'generic_deadman']
tags = ['deadman']
# Allow each definition to specify custom tags
for custom_tag in self.custom_tags:
tags.append(custom_tag)

severity = self._config['severity']

summary = "Deadman check failed for '{0}' the past {1} {2}".format(
Expand Down
2 changes: 1 addition & 1 deletion tests/alerts/test_deadman_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestDeadmanGeneric(AlertTestSuite):
}
unmatched_second_alert = {
"category": "deadman",
"tags": ['deadman', 'generic_deadman'],
"tags": ['deadman', 'someothertag'],
"severity": "ERROR",
"summary": 'Deadman check failed for \'Sample Alert 2\' the past 20 hours',
}
Expand Down

0 comments on commit 6cc0a1e

Please sign in to comment.