SMS Benachrichtigungen und Alarme mit Nagios via GSM

Die vernetzten IT Überwachungsgeräte der Modellreihen 500/500-DC/600/700 können mit einem GSM Modem ausgerüstet werden. Dieses interne Didactum GSM-Modem kann von Nagios bzw. Nagios-Forks direkt angesprochen werden, um per SMS Benachrichtigungen und Alarmmeldungen an die Admins und IT-Verantwortlichen abzusetzen.

 

Auf die Beschaffung eines zusätzlichen GSM Modems für den Versand von SMS Alarmen unter Nagios kann somit verzichtet werden.

 

Hierzu stellt Didactum folgendes Skript bereit. Dieses Skript können Sie hier herunterladen.

 

sendsms_didactum

#!/bin/bash

usage()

{

cat << EOF

usage: $0 options

 OPTIONS:

 

   -?,-h   Show this message
   -H      Hostname or IP address
   -p      password
   -P      Phone for sending
   -m      Message for sending

 

EOF

}

 

HOST=

PASSWD=

TOPHONE=

MESSAGE='Test'

 

while getopts “hH:p:P:m:” OPTION

do

     case $OPTION in

         h)

             usage

             exit 1

             ;;

         H)

             HOST=$OPTARG

             ;;

         p)

             PASSWD=$OPTARG

             ;;

         P)

             TOPHONE=$OPTARG

             ;;

         m)

             MESSAGE=$OPTARG

             ;;

         ?)

             usage

             exit

             ;;

         

     esac

done

 

#echo $HOST

#echo $PASSWD

#echo $TOPHONE

#echo $MESSAGE 

 

if [[ -z $HOST ]] || [[ -z $PASSWD ]] || [[ -z $TOPHONE ]] || [[ -z $MESSAGE ]]

then

     usage

     exit 1

fi

 

curl -d "epassword=${PASSWD}&

querytype=send_sms_message" --data-urlencode "to_phone=${TOPHONE}" --data-urlencode "message=${MESSAGE}" $HOST/engine.htm  > /dev/null 2>&1

SMS send script for versions from 2.4.x

#!/bin/bash

# SMS send script for versions from 2.4.x 

usage()

{

cat << EOF

usage: $0 options

OPTIONS:

   -?,-h   Show this message

   -H      Hostname or IP address

   -u      User name

   -p      Password

   -P      Phone for sending

   -m      Message for sending

EOF

}

HOSTIP=

USERNAME=

PASSWORD=

TOPHONE=

MESSAGE='Test'

while getopts “hH:u:p:P:m:” OPTION

do

     case $OPTION in

         h)

             usage

             exit 1

             ;;

         H)

             HOSTIP=$OPTARG

             ;;

         u)

             USERNAME=$OPTARG

             ;;

         p)

             PASSWORD=$OPTARG

             ;;

         P)

             TOPHONE=$OPTARG

             ;;

         m)

             MESSAGE=$OPTARG

             ;;

         ?)

             usage

             exit

             ;;

          

     esac

done

if [[ -z $HOSTIP ]] || [[ -z $USERNAME ]] || [[ -z $PASSWORD ]] || [[ -z $TOPHONE ]] || [[ -z $MESSAGE ]]

then

     usage

     exit 1

fi

 

# 1) hash

HASH=`echo -n ${PASSWORD} | openssl dgst -sha1 | awk '{print $NF}'`

# 2) autorisation

RESPONSE=`curl -s -d "querytype=auth&name=${USERNAME}&h=${HASH}" "${HOSTIP}/engine.htm"`

# 3) session key

KEY=`echo -n  ${RESPONSE} | awk -F"\"" '{print $4}'`

# 4) send SMS

curl -d "querytype=send_sms_message&k=${KEY}" --data-urlencode "to_phone=${TOPHONE}" --data-urlencode "message=${MESSAGE}" ${HOSTIP}/engine.htm > /dev/null 2>&1

Send SMS through a script example:

/etc/nagios/objects/schosts.cfg

./sendsms_didactum -H 192.168.0.193 -p secret -P +777 -m 'This is a text'

where 192.168.0.193 - address of the master unit with GSM-modem;

       secret  - user password for the master unit with GSM-modem;

       +777 - phone number to send a message; 

       'This is a text' - forwarded message text;

In order to bind the current script to Nagios, you must create a notification command in the Nagios configuration file:

/etc/nagios/objects/commands.cfg

define command{

        command_name notify-service-by-sms

        command_line $USER1$/sendsms_didactum -H 192.168.1.190 -p guest -P $CONTACTPAGER$ -m "Nagios – $NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"

}

define command{

        command_name notify-host-by-sms

        command_line $USER1$/sendsms_didactum -H 192.168.1.190 -p guest -P $CONTACTPAGER$ -m "Nagios – $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$"

}

You must also create or edit a Nagios contact: 

/etc/nagios/objects/contacts.cfg

define contact{

        contact_name                    nagiosadmin             ; Short name of user

        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

        alias                           Nagios Admin            ; Full name of user

        service_notification_options    w,u,c,r

        host_notification_options       d,u,r

        service_notification_commands   notify-service-by-email,notify-service-by-sms

        host_notification_commands      notify-host-by-email,notify-host-by-sms

        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        pager                           +499999999999           ; <<***** CHANGE THIS TO YOUR PHONE NUMBER ******

}