From 3c57c113cde585aaadc50625cdcf0a89e4c995b0 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 20 Oct 2020 17:52:12 +0100 Subject: [PATCH] Add the ability to disabled resolved messages Resolves #5 --- README.md | 11 ++++++----- alertify.py | 11 ++++++++--- example.yaml | 5 +++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0b11bf3..406e803 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,12 @@ optional arguments: -H, --healthcheck simply exit with 0 for healthy or 1 when unhealthy The following environment variables will override any config or default: - * LISTEN_PORT (default: 8080) - * GOTIFY_SERVER (default: localhost) - * GOTIFY_PORT (default: 80) - * GOTIFY_KEY (default: None) - * VERBOSE (default: False) + * DISABLE_RESOLVED (default: False) + * GOTIFY_KEY (default: None) + * GOTIFY_PORT (default: 80) + * GOTIFY_SERVER (default: localhost) + * LISTEN_PORT (default: 8080) + * VERBOSE (default: False) ``` diff --git a/alertify.py b/alertify.py index 01c0dbe..631c63a 100644 --- a/alertify.py +++ b/alertify.py @@ -15,10 +15,11 @@ from http.server import HTTPServer, SimpleHTTPRequestHandler import yaml DEFAULTS = { - 'listen_port': int(8080), - 'gotify_server': str('localhost'), - 'gotify_port': int(80), + 'disable_resolved': bool(False), 'gotify_key': str(), + 'gotify_port': int(80), + 'gotify_server': str('localhost'), + 'listen_port': int(8080), 'verbose': bool(False), } @@ -92,6 +93,10 @@ class HTTPHandler(SimpleHTTPRequestHandler): try: if alert['status'] == 'resolved': + if self.config.get('disable_resolved'): + print('Ignoring resolved messages') + self._respond(200, 'Ignored. "resolved" messages are disabled') + return prefix = 'Resolved' else: prefix = alert['commonLabels'].get( diff --git a/example.yaml b/example.yaml index a283a42..b406df7 100644 --- a/example.yaml +++ b/example.yaml @@ -1,6 +1,7 @@ --- -# verbose: true -gotify_server: gotifyserver.example.net +disable_resolved: false gotify_key: sOmEsEcReTkEy1 gotify_port: "80" +gotify_server: gotifyserver.example.net listen_port: "8080" +verbose: true