diff --git a/test/pytest.ini b/test/pytest.ini index 0bf407eab322724e5da48cfc8580ba41305da920..281b543c47df5bbb53f9cb07b703820a3880a5e6 100644 --- a/test/pytest.ini +++ b/test/pytest.ini @@ -3,3 +3,4 @@ markers = certs: Run tests related to TLS certificates testinfra: Run testinfra tests (test OS/package versions etc) + prometheus: Test prometheus diff --git a/test/pytest/test_prometheus.py b/test/pytest/test_prometheus.py new file mode 100755 index 0000000000000000000000000000000000000000..416a97a52dbaed6c20013dcb518ec0d35f50cb33 --- /dev/null +++ b/test/pytest/test_prometheus.py @@ -0,0 +1,31 @@ +import json +import pytest +import requests + +@pytest.mark.prometheus +def test_prometheus_alerts(host): + + print("Starting prometheus test...") + #cmd = host.run("hostname") + #print("Hostname: " + cmd.stdout) + + url = 'http://127.0.0.1:30090/api/v1/alerts' + alert_json = json.loads(host.check_output('curl ' + url)) + print(type(alert_json)) + status = alert_json["status"] + alerts = alert_json["data"]["alerts"] + + # Filter out the ever firing "Dead mans switch" + real_alerts = [alert for alert in alerts + if alert["labels"]["severity"] != "none"] + + count = len(real_alerts) + + print(json.dumps(real_alerts)) + + assert status == "success", "Failure queriying the prometheus api at" + url + assert count == 0, "There are prometheus alerts firing !" + + +if __name__ == "__main__": + test_prometheus_alerts('')