Source code for accre.paging
"""
Convenience interface to create pages for sysadmins or other ACCRE staff
via phone, SMS, etc.
Currently xMatters is used to handle on-call schedule and rotation, and
twilio may be set up as a fallback to also send SMS messages to staff (TODO).
"""
import getpass
import socket
import sys
import requests
from accre.config import get_config
from accre.util import accre_argparser
CONFIG = get_config()
[docs]def xmatters_page(device, incident_id, situation, group):
"""
Create an xmatters incident for the specified group
:param str device: Entity creating this incident (RT, nagios, etc...)
:param str incident_id: If possible, some identification for the
incident such as an RT ticket number
:param str situation: Description of the problem that will be
displayed on the SMS message to the on-call staff.
:param str group: XMatters group to receive the page
"""
api_url = CONFIG['paging']['xmatters_api_url']
user = CONFIG['paging']['xmatters_api_user']
password = CONFIG['paging']['xmatters_api_password']
payload = {
'properties': {
'device': device,
'incident_id': incident_id,
'situation': situation,
'message': ''
},
'recipients': [group]
}
resp = requests.post(api_url, json=payload, auth=(user, password))
resp.raise_for_status()
[docs]def xmatters_page_cluster_support(device, incident_id, situation):
"""
Create an xmatters incident for the Cluster Support Group.
:param str device: Entity creating this incident (RT, nagios, etc...)
:param str incident_id: If possible, some identification for the
incident such as an RT ticket number
:param str situation: Description of the problem that will be
displayed on the SMS message to the on-call staff.
"""
xmatters_page(device, incident_id, situation, 'Cluster Group')
[docs]def xmatters_page_cli():
"""
CLI entry point for xmatters paging
"""
description = "Create xMatters Incident for ACCRE On-Call Support"
parser = accre_argparser('xmatters', description=description)
parser.add_argument('-i', '--incident',
action='store',
default=None,
required=True,
help="Incident ID"
)
parser.add_argument('-s', '--situation',
action='store',
default=None,
required=True,
help="Description of the situation to be displayed in the SMS message"
)
parser.add_argument('-g', '--group',
action='store',
default='Cluster Group',
help="XMatters group to page, defaults to Cluster Group"
)
args = parser.parse_args()
device = '{0}-on-{1}'.format(getpass.getuser(), socket.gethostname())
xmatters_page(device, args.incident, args.situation, args.group)