Esempio n. 1
0
class TestAddAnnotation(unittest.TestCase):
    def setUp(self):
        self.alert = Alert()

    def test_add_annotation(self):
        self.alert.add_annotation('alert_source', 'maas')
        self.assertEqual(self.alert, TEST_ADD_ANNOTATION_DATA)
Esempio n. 2
0
class TestAddLabel(unittest.TestCase):
    def setUp(self):
        self.alert = Alert()

    def test_add_label(self):
        self.alert.add_label('alertname', 'alert1')
        self.assertEqual(self.alert, TEST_ADD_LABEL_DATA)
Esempio n. 3
0
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)
Esempio n. 4
0
    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)
Esempio n. 5
0
 def setUp(self):
     self.alert = Alert()
Esempio n. 6
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')