class TestAlertValidate(unittest.TestCase): def setUp(self): self.alert = Alert() def test_no_labels_key(self): alert = self.alert.from_dict(TEST_ALERT_VALIDATE_DATA_1) with self.assertRaises(ValueError) as cm: alert.validate_and_dump() err = cm.exception self.assertIn('Object does not validate', str(err)) def test_no_values_set_for_labels(self): alert = self.alert.from_dict(TEST_ALERT_VALIDATE_DATA_2) with self.assertRaises(ValueError) as cm: alert.validate_and_dump() err = cm.exception self.assertIn('Object does not validate', str(err)) def test_validate_alert_good(self): alert = self.alert.from_dict(TEST_ADD_LABEL_DATA) result = alert.validate_and_dump() self.assertTrue(result)
if r.status_code != 200: logger.error("Prometheus-Status: Not connected to Alertmanager!") exit(1) if prom != 2: data = { "labels": { "alertname": "Prometheus Down", "severity": "critical" }, "annotations": { "description": "One of Prometheus pod has problem!", "summary": "PROMETHEUS - Prometheus Down" } } a_manager = AlertManager(host=host,port=port) a_manager.post_alerts(Alert.from_dict(data)) # print message local test # print(Alert.from_dict(data)) logger.error("Prometheus instance is down!") else: logger.info("Prometheus is running!") except Exception as e: logger.exception("%s"%(e)) exit(0)
def setUp(self): self.a_manager = AlertManager(host=HOST) self.a_manager.post_alerts(TEST_ALERT_POST_DATA) self.alert = Alert.from_dict(TEST_ALERT_POST_DATA) self.silence = Silence.from_dict(TEST_SILENCE_POST_DATA) self.silence.set_endtime('in 1 minute')