Permalink
Browse files

Merge pull request #1090 from mozilla/update_summary_generic_deadman

Update summary field in deadman_generic alert
  • Loading branch information...
pwnbus committed Feb 6, 2019
2 parents 7e87f73 + 3e895ab commit f496e01c4eb60a00710cbc5a18bf24f7964708f6
Showing with 17 additions and 9 deletions.
  1. +4 −2 alerts/deadman_generic.json
  2. +9 −3 alerts/deadman_generic.py
  3. +4 −4 tests/alerts/test_deadman_generic.py
@@ -1,14 +1,16 @@
{
"alerts": [
{
"description": "Sample Alert 1",
"search_query": "ABC12345436",
"time_window": "5",
"description": "Basic deadman"
"time_window_type": "minutes"
},
{
"description": "Sample Alert 2",
"search_query": "anotherterm",
"time_window": "20",
"description": "Another deadman"
"time_window_type": "hours"
}
]
}
@@ -15,7 +15,6 @@ class AlertDeadmanGeneric(DeadmanAlertTask):

def main(self):
self._config = self.parse_json_alert_config('deadman_generic.json')

for alert_cfg in self._config['alerts']:
try:
self.process_alert(alert_cfg)
@@ -26,7 +25,10 @@ def main(self):
)

def process_alert(self, alert_config):
search_query = SearchQuery(minutes=int(alert_config['time_window']))
self.current_alert_time_window = int(alert_config['time_window'])
self.current_alert_time_type = alert_config['time_window_type']
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'])))
self.filtersManual(search_query)
self.searchEventsSimple()
@@ -39,5 +41,9 @@ def onNoEvent(self, description):
tags = ['deadman']
severity = 'ERROR'

summary = "Deadman check failed for '{0}'".format(description)
summary = "Deadman check failed for '{0}' the past {1} {2}".format(
description,
self.current_alert_time_window,
self.current_alert_time_type
)
return self.createAlertDict(summary, category, tags, [], severity=severity)
@@ -32,7 +32,7 @@ class TestDeadmanGeneric(AlertTestSuite):
"category": "deadman",
"tags": ['deadman'],
"severity": "ERROR",
"summary": 'Deadman check failed for \'Basic deadman\'',
"summary": 'Deadman check failed for \'Sample Alert 1\' the past 5 minutes',
}
test_cases.append(
PositiveAlertTestCase(
@@ -51,7 +51,7 @@ class TestDeadmanGeneric(AlertTestSuite):
"category": "deadman",
"tags": ['deadman'],
"severity": "ERROR",
"summary": 'Deadman check failed for \'Another deadman\'',
"summary": 'Deadman check failed for \'Sample Alert 2\' the past 20 hours',
}
test_cases.append(
PositiveAlertTestCase(
@@ -86,8 +86,8 @@ class TestDeadmanGeneric(AlertTestSuite):
AlertTestSuite.create_event(matched_event_first),
AlertTestSuite.create_event(matched_event_second)
]
events[1]['_source']['utctimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'minutes': 21})
events[1]['_source']['receivedtimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'minutes': 21})
events[1]['_source']['utctimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'hours': 21})
events[1]['_source']['receivedtimestamp'] = AlertTestSuite.subtract_from_timestamp_lambda(date_timedelta={'hours': 21})
test_cases.append(
PositiveAlertTestCase(
description="Positive test case with events matching second alert configuration but are old",

0 comments on commit f496e01

Please sign in to comment.