Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Pushover.net support #674

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions configs/config.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion db/dummy_data.sql
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/iris/bin/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/iris/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
61 changes: 61 additions & 0 deletions src/iris/vendors/iris_pushover.py
Original file line number Diff line number Diff line change
@@ -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)