diff --git a/alertmanager/test_alert.sh b/alertmanager/test_alert.sh index 9b29f66..cd4baf6 100644 --- a/alertmanager/test_alert.sh +++ b/alertmanager/test_alert.sh @@ -1,5 +1,5 @@ #!/bin/sh -url='http://localhost:9093/api/v1/alerts' +url='http://localhost:9093/api/v2/alerts' name="TEST ALERT" echo "firing up alert $name" diff --git a/alertmanager/test_resolve.sh b/alertmanager/test_resolve.sh index e16bc52..8544431 100644 --- a/alertmanager/test_resolve.sh +++ b/alertmanager/test_resolve.sh @@ -1,5 +1,5 @@ #!/bin/sh -url='http://localhost:9093/api/v1/alerts' +url='http://localhost:9093/api/v2/alerts' name="TEST ALERT" echo "resolving alert $name" diff --git a/backend/alive.py b/backend/alive.py index 239b59d..c654ec1 100644 --- a/backend/alive.py +++ b/backend/alive.py @@ -47,7 +47,7 @@ def check_port(host, port): return False -def check_all_hosts(): +def check_all_hosts(): # pragma: no cover """ Pulls in all hosts and checks them all """ diff --git a/backend/serve.py b/backend/serve.py index e827c97..af9adc1 100755 --- a/backend/serve.py +++ b/backend/serve.py @@ -825,8 +825,11 @@ def list_alerts(): """ url = "http://alertmanager:9093/api/v2/alerts" password = open("/alertmanager/pass").read() + headers = { + "Content-Type" : "application/json" + } - return json.dumps(requests.get(url, auth=("admin", password)).json()), 200 + return json.dumps(requests.get(url, auth=("admin", password), headers=headers).json()), 200 @app.route("/alertmanager/alert", methods=["POST"]) @@ -842,15 +845,19 @@ def resolve_alert(data=""): else: # pragma: no cover return "Invalid data", 419 - url = "http://alertmanager:9093/api/v1/alerts" + url = "http://alertmanager:9093/api/v2/alerts" password = open("/alertmanager/pass").read() del parsed_data["startsAt"] parsed_data["status"] = "resolved" parsed_data["endsAt"] = "2021-08-03T14:34:41-05:00" + + headers = { + "Content-Type" : "application/json" + } retval = requests.post( - url, data=json.dumps([parsed_data]), auth=("admin", password) + url, data=json.dumps([parsed_data]), auth=("admin", password), headers=headers ) return retval.text, retval.status_code @@ -865,7 +872,11 @@ def restart_alertmanager(): url = "http://alertmanager:9093/-/reload" password = open("/alertmanager/pass").read() - retval = requests.post(url, auth=("admin", password)) + headers = { + "Content-Type" : "application/json" + } + + retval = requests.post(url, auth=("admin", password), headers=headers) return retval.text, retval.status_code @@ -1192,7 +1203,7 @@ def save_ansible_file(fname, inp_data="", vars_file=""): # Ansible runner @app.route("/ansible_runner/", methods=["POST"]) @requires_auth_admin -def run_ansible(inp_data=""): # pragma: no cover +def run_ansible(inp_data=""): if inp_data != "": data = inp_data elif request.method == "POST": # pragma: no cover @@ -1228,7 +1239,7 @@ def run_ansible(inp_data=""): # pragma: no cover cmdline="-vvvvv --vault-password-file ../vault.pass", quiet=True ) - except Exception as e: + except Exception as e: # pragma: no cover # Delete Vault Password if "vault.pass" in os.listdir(RUN_DIR): os.remove("{}/vault.pass".format(RUN_DIR)) diff --git a/backend/test/test_01_alertmanager.py b/backend/test/test_01_alertmanager.py index e3c15b0..383f742 100644 --- a/backend/test/test_01_alertmanager.py +++ b/backend/test/test_01_alertmanager.py @@ -83,14 +83,17 @@ def test_send_alert(): - Will just print out URL and payload """ a = unwrap(serve.list_alerts)() + print(a[0]) assert a[1] == 200 b = json.loads(a[0]) - assert watcher.send_alert( + output= watcher.send_alert( "test-alert", "test-service", "test-host", ) + print(output.text) + assert output a = unwrap(serve.list_alerts)() assert a[1] == 200 diff --git a/backend/watcher.py b/backend/watcher.py index c2e8fda..3da5edb 100644 --- a/backend/watcher.py +++ b/backend/watcher.py @@ -28,22 +28,25 @@ def send_alert( :param serverity - defaults to error """ - url = "http://alertmanager:9093/api/v1/alerts" + url = "http://alertmanager:9093/api/v2/alerts" + headers = { + "Content-Type": "application/json" + } data = { "status": "firing", "labels": { "alertname": alert_name, "service": service, "severity": severity, - "instance": instance, + "instance": instance }, "annotations": { - "summary": summary, + "summary": summary }, - "generatorURL": url, + "generatorURL": url } password = open("/alertmanager/pass").read() - retval = requests.post(url, data=json.dumps([data]), auth=("admin", password)) + retval = requests.post(url, headers=headers, data=json.dumps([data]), auth=("admin", password)) return retval