def test_old_alert_removed_blackout(self): ''' Test an existing alert whose associated blackout no longer exists. ''' alert = Alert( id='old-alert', resource='test::resource', event='test-event', group='test', service=['test-service'], tags=['site=siteX', 'regex_blackout=99'], status='open', ) test_obj = BlackoutRegex() test = test_obj.pre_receive(alert) self.assertEqual(test.status, 'open') self.assertEqual(test.tags, ['site=siteX'])
def test_new_alert_multi_match(self): ''' Test alert matching a regex blackout on multiple attributes. ''' alert = Alert( id='multi-match', resource='FPC1', event='FPCDown', group='test', service=['test-service'], tags=['site=siteX'], status='open', ) test_obj = BlackoutRegex() test = test_obj.pre_receive(alert) self.assertEqual(test.status, 'blackout') self.assertEqual(test.tags, ['site=siteX', 'regex_blackout=6'])
def test_new_alert_no_match_tags(self): ''' Test alert that doesn't match as not all the tags match. ''' alert = Alert( id='no-match-tags', resource='test::resource', event='test-event', group='test', service=['test-service'], tags=['site=siteX', 'role=switch'], status='open', ) test_obj = BlackoutRegex() test = test_obj.pre_receive(alert) self.assertEqual(test.status, 'open') self.assertEqual(test.tags, ['site=siteX', 'role=switch'])
def test_new_alert_match_service(self): ''' Test alert matching a regex blackout on the service field. ''' alert = Alert( id='match-service', resource='test::resource', event='test-event', group='test', service=['service-blah'], tags=[], status='open', ) test_obj = BlackoutRegex() test = test_obj.pre_receive(alert) self.assertEqual(test.status, 'blackout') self.assertEqual(test.tags, ['regex_blackout=2'])
def test_new_alert_no_match(self): ''' Test alert not matching a regex blackout. ''' alert = Alert( id='no-match', resource='test::resource', event='test-event', group='test', service=['test-service'], tags=[], status='open', ) test_obj = BlackoutRegex() test = test_obj.pre_receive(alert) self.assertEqual(test.status, 'open') self.assertEqual(test.tags, [])
def test_new_alert_match_tag(self): ''' Test alert matching a regex blackout on the tag(s). ''' alert = Alert( id='match-tag', resource='test::resource', event='test-event', group='test', service=['test-service'], tags=['site=siteX', 'role=router'], status='open', ) test_obj = BlackoutRegex() test = test_obj.pre_receive(alert) self.assertEqual(test.status, 'blackout') self.assertEqual(test.tags, ['site=siteX', 'role=router', 'regex_blackout=3'])