From f1aa6777948cc306594936890c38e4daf187a549 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Sat, 2 Nov 2019 15:54:00 +0100 Subject: [PATCH] Inital commit --- README.md | 52 ++++++++++++++++++++++++++++++ cellsyntuser.sh | 2 ++ sms-host-notification.sh | 60 +++++++++++++++++++++++++++++++++++ sms-service-notification.sh | 63 +++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 README.md create mode 100644 cellsyntuser.sh create mode 100644 sms-host-notification.sh create mode 100644 sms-service-notification.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..6467cb6 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Cellsynt SMS notification +These scripts sends out SMS notifictions for Icinga2 via the Swedish company +Cellsynt. There is one script for hosts, and one for services. + +I have used the two scripts `mail-host-notification.sh` and `mail-service-notification.sh` +as templates for my scripts. + +# Usage and installation +Drop the scripts `sms-host-notification.sh` and `sms-service-notification.sh` in */etc/icinga2/scripts/*. +Place `cellsyntuser.sh` in */etc/icinga2/* and set the username and password to match your account at +Cellsynt. + +Next you need to define the command in either *commands.conf* or by using Director. Below is an example of +my own *commands.conf* for host notifications. + + +``` +object NotificationCommand "SMS Host Notification" { + import "plugin-notification-command" + command = [ "/etc/icinga2/scripts/sms-host-notification.sh" ] + arguments += { + "-4" = { + required = true + value = "$host.address$" + } + "-6" = { + required = false + value = "$host.address6$" + } + "-l" = { + required = true + value = "$host.name$" + } + "-o" = { + required = true + value = "$host.output$" + } + "-p" = { + required = true + value = "$user.pager$" + } + "-s" = { + required = true + value = "$host.state$" + } + "-t" = { + required = true + value = "$notification.type$" + } + } +} +``` diff --git a/cellsyntuser.sh b/cellsyntuser.sh new file mode 100644 index 0000000..0c3ac7a --- /dev/null +++ b/cellsyntuser.sh @@ -0,0 +1,2 @@ +username=myEpicUser +password=myEpicPassword diff --git a/sms-host-notification.sh b/sms-host-notification.sh new file mode 100644 index 0000000..b8e2b90 --- /dev/null +++ b/sms-host-notification.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# Maintained by Jack-Benny Persson +# Released under GPLv2+ +# Thanks to Icinga GmbH + +source /etc/icinga2/cellsyntuser.sh + +## Function helpers +Usage() { +cat << EOF + +Required parameters: + -4 HOSTADDRESS (\$host.address\$) + -6 HOSTADDRESS6 (\$host.address6\$) + -l HOSTNAME (\$host.name\$) + -o HOSTOUTPUT (\$host.output\$) + -p CONTACTPAGER (\$user.pager\$) + -s HOSTSTATE (\$host.state\$) + -t NOTIFICATIONTYPE (\$notification.type\$) + +EOF +} + +Help() { + Usage; + exit 0; +} + +Error() { + if [ "$1" ]; then + echo $1 + fi + Usage; + exit 1; +} + +## Main +while getopts 4:6:p:l:o:s:t: opt +do + case "$opt" in + 4) HOSTADDRESS=$OPTARG ;; + 6) HOSTADDRESS6=$OPTARG ;; + h) Help ;; + l) HOSTNAME=$OPTARG ;; # required + o) HOSTOUTPUT=$OPTARG ;; # required + p) CONTACTPAGER=$OPTARG ;; # required + s) HOSTSTATE=$OPTARG ;; # required + t) NOTIFICATIONTYPE=$OPTARG ;; # required + \?) echo "ERROR: Invalid option -$OPTARG" >&2 + Error ;; + :) echo "Missing option argument for -$OPTARG" >&2 + Error ;; + *) echo "Unimplemented option: -$OPTARG" >&2 + Error ;; + esac +done + +shift $((OPTIND - 1)) + +/bin/echo "http://se-1.cellsynt.net/sms.php?username=$username&password=$password&destination=$CONTACTPAGER&type=text&allowconcat=6&text=Notification%20Type:%20$NOTIFICATIONTYPE%0AHost:%20$HOSTNAME%0AState:%20$HOSTSTATE%0AAddress:%20$HOSTADDRESS%20$HOSTADDRESS6%0AAdditional%20Info:%20$HOSTOUTPUT&originatortype=alpha&originator=CyberInfo" | sed 's/ /%20/g' | /usr/bin/wget -i - -O /tmp/sms_log diff --git a/sms-service-notification.sh b/sms-service-notification.sh new file mode 100644 index 0000000..dff5d76 --- /dev/null +++ b/sms-service-notification.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# Maintained by Jack-Benny Persson +# Released under GPLv2+ +# Thanks to Icinga GmbH + +source /etc/icinga2/cellsyntuser.sh + +## Function helpers +Usage() { +cat << EOF + +Required parameters: + -4 HOSTADDRESS (\$host.address\$) + -6 HOSTADDRESS6 (\$host.address6\$) + -e SERVICENAME (\$service.name\$) + -l HOSTNAME (\$host.name\$) + -o SERVICEOUTPUT (\$host.output\$) + -p CONTACTPAGER (\$user.pager\$) + -s SERVICESTATE (\$host.state\$) + -t NOTIFICATIONTYPE (\$notification.type\$) + +EOF +} + +Help() { + Usage; + exit 0; +} + +Error() { + if [ "$1" ]; then + echo $1 + fi + Usage; + exit 1; +} + +## Main +while getopts 4:6:p:l:o:s:t:e: opt +do + case "$opt" in + 4) HOSTADDRESS=$OPTARG ;; + 6) HOSTADDRESS6=$OPTARG ;; + h) Help ;; + e) SERVICENAME=$OPTARG ;; + l) HOSTNAME=$OPTARG ;; # required + o) SERVICEOUTPUT=$OPTARG ;; # required + p) CONTACTPAGER=$OPTARG ;; # required + s) SERVICESTATE=$OPTARG ;; # required + t) NOTIFICATIONTYPE=$OPTARG ;; # required + \?) echo "ERROR: Invalid option -$OPTARG" >&2 + Error ;; + :) echo "Missing option argument for -$OPTARG" >&2 + Error ;; + *) echo "Unimplemented option: -$OPTARG" >&2 + Error ;; + esac +done + +shift $((OPTIND - 1)) + + +/bin/echo -e "http://se-1.cellsynt.net/sms.php?username=$username&password=$password&destination=$CONTACTPAGER&type=text&allowconcat=6&text=Notification%20Type:%20$NOTIFICATIONTYPE%0AService:%20$SERVICENAME%0AHost:%20$HOSTNAME%0AAddress:%20$HOSTADDRESS%20$HOSTADDRESS6%0AState:%20$SERVICESTATE%0AAdditional%20Info:%20$SERVICEOUTPUT&originatortype=alpha&originator=CyberInfo" | sed 's/ /%20/g' | /usr/bin/wget -i - -O /tmp/sms_log