def _publish_end_of_alerts(self, alerts: dict): all_alerts = self._get_alerts() updated_dict = {} if all_alerts: for alert in all_alerts: fingerprint = alert.get('fingerprint', None) if not fingerprint: continue updated_dict[fingerprint] = alert for alert in alerts.values(): if not alert.get('endsAt', None): alert['endsAt'] = time.strftime("%Y-%m-%dT%H:%M:%S.0Z", time.gmtime()) alert = updated_dict.get(alert['fingerprint'], alert) PrometheusAlertManagerEvent.end(raw_alert=alert).publish()
def test_sct_severity_wrong(self): event = PrometheusAlertManagerEvent.end(raw_alert=dict(labels=dict( sct_severity="WRONG"))) self.assertEqual(event.severity, Severity.WARNING) self.assertTrue( str(event).startswith( "(PrometheusAlertManagerEvent Severity.WARNING)")) self.assertEqual(event, pickle.loads(pickle.dumps(event)))
def test_sct_severity(self): event = PrometheusAlertManagerEvent.end(raw_alert=dict(labels=dict( sct_severity="CRITICAL"))) self.assertEqual(event.severity, Severity.CRITICAL) self.assertTrue( str(event).startswith( "(PrometheusAlertManagerEvent Severity.CRITICAL)")) self.assertEqual(event, pickle.loads(pickle.dumps(event)))