bundles/icinga2: implement SMS notifications
This commit is contained in:
parent
22d5ba12ee
commit
8c6c691e5e
3 changed files with 39 additions and 10 deletions
|
@ -3,10 +3,14 @@
|
|||
import email.mime.text
|
||||
import smtplib
|
||||
from argparse import ArgumentParser
|
||||
from requests import get
|
||||
from json import dumps
|
||||
from requests import post
|
||||
from subprocess import run
|
||||
from sys import argv
|
||||
|
||||
SIPGATE_USER='${node.metadata['icinga2']['sipgate_user']}'
|
||||
SIPGATE_PASS='${node.metadata['icinga2']['sipgate_pass']}'
|
||||
|
||||
parser = ArgumentParser(
|
||||
prog='icinga_notification_wrapper',
|
||||
description='Icinga2 Notification Wrapper',
|
||||
|
@ -55,14 +59,34 @@ def log_to_syslog(message):
|
|||
|
||||
|
||||
def notify_per_sms():
|
||||
log_to_syslog('SMS requested, but not implemented yet!') # FIXME TODO
|
||||
return
|
||||
msg = 'ICINGA: {host}/{service} is {state}: {output}'.format(
|
||||
host=args.host_name,
|
||||
service=args.service_name,
|
||||
state=args.state,
|
||||
output=args.output
|
||||
)
|
||||
message = {
|
||||
'message': 'ICINGA: {host}/{service} is {state}: {output}'.format(
|
||||
host=args.host_name,
|
||||
service=args.service_name,
|
||||
state=args.state.upper(),
|
||||
output=args.output
|
||||
),
|
||||
'smsId': 's0', # XXX what does this mean? Documentation is unclear
|
||||
'recipient': args.sms
|
||||
}
|
||||
headers = {
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
try:
|
||||
r = post(
|
||||
'https://api.sipgate.com/v2/sessions/sms',
|
||||
json=message,
|
||||
headers=headers,
|
||||
auth=(SIPGATE_USER, SIPGATE_PASS),
|
||||
)
|
||||
|
||||
if r.status_code == 204:
|
||||
log_to_syslog('Sent a SMS to "{}"'.format(args.sms))
|
||||
else:
|
||||
r.raise_for_status()
|
||||
except Exception as e:
|
||||
log_to_syslog('Sending a SMS to "{}" failed: {}'.format(args.sms, repr(e)))
|
||||
|
||||
|
||||
def notify_per_mail():
|
||||
|
@ -88,7 +112,7 @@ State: {state}
|
|||
mail = email.mime.text.MIMEText(text.format(
|
||||
host=args.host_name,
|
||||
service=args.service_name,
|
||||
state=args.state,
|
||||
state=args.state.upper(),
|
||||
output=args.output
|
||||
),
|
||||
'plain',
|
||||
|
|
|
@ -93,6 +93,7 @@ files = {
|
|||
},
|
||||
'/etc/icinga2/scripts/icinga_notification_wrapper': {
|
||||
'source': 'scripts/icinga_notification_wrapper',
|
||||
'content_type': 'mako',
|
||||
'mode': '0755',
|
||||
},
|
||||
'/etc/icinga2/features-available/ido-pgsql.conf': {
|
||||
|
|
|
@ -26,6 +26,10 @@ nodes['ovh.icinga2'] = {
|
|||
'php-imagick': {},
|
||||
},
|
||||
},
|
||||
'icinga2': {
|
||||
'sipgate_user': vault.decrypt('encrypt$gAAAAABfujAmCUnicSAllq8MskXnPodKp3cGcfA6Abvef-rAYwB2CtCwt9oBRVKFskJPVArDaF1wfjNTfLwgX3gTP7xFutJ1HA=='),
|
||||
'sipgate_pass': vault.decrypt('encrypt$gAAAAABfui_4B7UmOosI_gsQ-xvmd3X_BUDSl-G2KF_Tg8O6RpUvk0gHexOKsrTb6se1ipXsh7RC9pbZCKMtesW0C6j24LHXDKCOjkqI77oO0ZjnG6SUwfcJqg61biNiRlXy8z-9LCGA'),
|
||||
},
|
||||
'nginx': {
|
||||
'vhosts': {
|
||||
'icingaweb': {
|
||||
|
|
Loading…
Reference in a new issue