Skip to content
Snippets Groups Projects
Verified Commit c6adff3c authored by Varac's avatar Varac
Browse files

Show firing prometheus alert names in test

parent 8ee3c9b7
No related branches found
No related tags found
No related merge requests found
# Run testinfra tests
Test host configured in `test/inventory.yml`
Test host configured in `../clusters/CLUSTERNAME/inventory.yml`
py.test -v --ansible-inventory=../inventory.yml --hosts='ansible://*'
export inventory=../clusters/CLUSTERNAME/inventory.yml
py.test -v --ansible-inventory=${inventory} --hosts='ansible://*'
Specify host manually:
py.test -v --hosts='ssh://root@example.openappstack.net'
Run only tests tagged with `prometheus`:
py.test -v --ansible-inventory=${inventory} --hosts='ansible://*' -m prometheus
## Cert tests
Run cert test manually using the ansible inventory file:
ADDRESS='example.openappstack.net' py.test -v -m 'certs' \
--connection=ansible \
--ansible-inventory=../ansible/inventory.yml \
--ansible-inventory=${inventory} \
--hosts='ansible://*'
Run cert test manually against a different cluster, not configured in any
......
......@@ -6,12 +6,9 @@ import requests
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"]
......@@ -19,12 +16,11 @@ def test_prometheus_alerts(host):
real_alerts = [alert for alert in alerts
if alert["labels"]["severity"] != "none"]
alert_names = list(map(lambda alert: alert["labels"]["alertname"], real_alerts))
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 !"
assert count == 0, "Firing alerts: {0}".format(str(alert_names))
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment