From 85ca9fab166d17eb022fad80aaf0910bb9c5b4ed Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Thu, 24 Feb 2022 10:54:34 -0500 Subject: [PATCH 1/2] Added Pushover.net support --- configs/config.dev.yaml | 11 ++++++ src/iris/bin/sender.py | 3 +- src/iris/constants.py | 1 + src/iris/vendors/iris_pushover.py | 61 +++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/iris/vendors/iris_pushover.py diff --git a/configs/config.dev.yaml b/configs/config.dev.yaml index c7ee3f63..1c62a05a 100644 --- a/configs/config.dev.yaml +++ b/configs/config.dev.yaml @@ -119,6 +119,7 @@ sender: workers_per_mode: email: 500 #hipchat: 10 + #pushover: 10 ## Default sender to reach out to if we can't determine one programmatically leader_sender: @@ -233,6 +234,16 @@ vendors: [] # base_url: 'https://api.hipchat.com' # room_id: 1234567 +## Pushover support requires adding a new mode called "pushover", in iris' mode table +## Also, uncomment the pushover workers to the sender['workers_per_mode'] hash above +#- type: iris_pushover +# name: pushover +# debug: False +# app_token: '' +# priority: 1 +# sound: 'climb' +# api_url: 'https://api.pushover.net/1/messages.json' + ## Metrics metrics: dummy # output metrics to logs #metrics: prometheus diff --git a/src/iris/bin/sender.py b/src/iris/bin/sender.py index acad53ac..76c489e9 100644 --- a/src/iris/bin/sender.py +++ b/src/iris/bin/sender.py @@ -271,7 +271,8 @@ 'send_queue_sms_size': 0, 'send_queue_drop_size': 0, 'new_incidents_cnt': 0, 'workers_respawn_cnt': 0, 'message_retry_cnt': 0, 'message_ids_being_sent_cnt': 0, 'notifications': 0, 'deactivation': 0, 'new_msg_count': 0, 'poll': 0, 'queue': 0, 'aggregations': 0, 'hipchat_cnt': 0, 'hipchat_fail': 0, - 'hipchat_total': 0, 'hipchat_sent': 0, 'hipchat_max': 0, 'hipchat_min': 0 + 'hipchat_total': 0, 'hipchat_sent': 0, 'hipchat_max': 0, 'hipchat_min': 0, + 'pushover_cnt': 0, 'pushover_fail': 0, 'pushover_total': 0, 'pushover_sent': 0, 'pushover_max': 0, 'pushover_min': 0 } # TODO: make this configurable diff --git a/src/iris/constants.py b/src/iris/constants.py index 5a8c05a1..41b44db1 100644 --- a/src/iris/constants.py +++ b/src/iris/constants.py @@ -13,6 +13,7 @@ IM_SUPPORT = 'im' SLACK_SUPPORT = 'slack' HIPCHAT_SUPPORT = 'hipchat' +PUSHOVER_SUPPORT = 'pushover' # Priorities listed in order of severity, ascending PRIORITY_PRECEDENCE = ('low', 'medium', 'high', 'urgent') diff --git a/src/iris/vendors/iris_pushover.py b/src/iris/vendors/iris_pushover.py new file mode 100644 index 00000000..805360db --- /dev/null +++ b/src/iris/vendors/iris_pushover.py @@ -0,0 +1,61 @@ +import logging +import requests +import time +from iris.constants import PUSHOVER_SUPPORT + +logger = logging.getLogger(__name__) + + +class iris_pushover(object): + supports = frozenset([PUSHOVER_SUPPORT]) + + def __init__(self, config): + self.config = config + self.modes = { + 'pushover': self.send_message + } + self.proxy = None + if 'proxy' in self.config: + host = self.config['proxy']['host'] + port = self.config['proxy']['port'] + self.proxy = {'http': '%s:%s' % (host, port), + 'https': '%s:%s' % (host, port)} + self.app_token = self.config.get('app_token') + self.priority = int(self.config.get('priority')) + self.sound = self.config.get('sound') + self.debug = self.config.get('debug') + self.api_url = self.config.get('api_url') + self.timeout = config.get('timeout', 10) + + + def send_message(self, message): + start = time.time() + + data = { + 'token': self.app_token, + 'priority': self.priority, + 'sound': self.sound, + 'user': message['destination'], + 'message': message['body'], + 'title': message['context']['title'] + } + + if self.debug: + logger.info('debug: %s', data) + else: + try: + response = requests.post(self.api_url, + data=data, + proxies=self.proxy, + timeout=self.timeout) + if response.status_code == 200 or response.status_code == 204: + return time.time() - start + else: + logger.error('Failed to send message to pushover: %d', + response.status_code) + logger.error("Response: %s", response.content) + except Exception as err: + logger.exception('Pushover post request failed: %s', err) + + def send(self, message, customizations=None): + return self.modes[message['mode']](message) From cb100e636680a209f4673db18eb9d25304fb8b22 Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Thu, 24 Feb 2022 10:58:17 -0500 Subject: [PATCH 2/2] Added dummy data for Pushover.net --- db/dummy_data.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dummy_data.sql b/db/dummy_data.sql index 26df1293..99675ea3 100644 --- a/db/dummy_data.sql +++ b/db/dummy_data.sql @@ -1,7 +1,7 @@ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -- DEFAULT DB VALUES LOCK TABLES `mode` WRITE; -INSERT INTO `mode` VALUES (26,'call'),(35,'email'),(17,'slack'),(8,'sms'),(36,'drop'); +INSERT INTO `mode` VALUES (26,'call'),(35,'email'),(17,'slack'),(8,'sms'),(36,'drop'),(99,'pushover'); UNLOCK TABLES; LOCK TABLES `priority` WRITE;