Inital commit
This commit is contained in:
commit
f1aa677794
52
README.md
Normal file
52
README.md
Normal file
@ -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$"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
2
cellsyntuser.sh
Normal file
2
cellsyntuser.sh
Normal file
@ -0,0 +1,2 @@
|
||||
username=myEpicUser
|
||||
password=myEpicPassword
|
60
sms-host-notification.sh
Normal file
60
sms-host-notification.sh
Normal file
@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
# Maintained by Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
# 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
|
63
sms-service-notification.sh
Normal file
63
sms-service-notification.sh
Normal file
@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# Maintained by Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
# 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
|
Loading…
x
Reference in New Issue
Block a user