Nagios SMS Notifications

Sending SMS alerts from Nagios is not as difficult as it may seem. Nagios notifications are basically nothing more than external commands being launched with Nagios macro's passed as arguments.

To be able to send notifications a SMS device is needed. In the example below a 'dongle' is used. The dongle presents itself to the OS as a /dev/ttyUSB modem which can be controlled using the AT command set. The dongle used is a 'Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem' which is controlled by SMS Server Tools 3 The config file for the sms tools, /etc/smsd.conf looks as follows:

devices = GSM1
loglevel = 7
autosplit = 3
incoming = /var/spool/sms/incoming
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed
sent = /var/spool/sms/sent
logfile = /var/log/smsd.log
 
[GSM1]
device = /dev/ttyUSB0
incoming = no
init2=AT+CSQ
pin = 0000

When done configuring smstools make sure to start smsd at boot time:

chkconfig smsd on

Start smsd:

service smsd start

Check that everything works fine:

smssend  “Message…”

Next step is to create a shell script that will receive the notification from Nagios and submit it to the smsd process. We've created a script named /usr/local/bin/nagios-send-sms with the following content:

 
#!/bin/bash
#
# This script takes input from STDIN and queues it in the outgoing
# directory of the sms tools
#
# The message has to be formatted in a specific way:
# To: <destination>\n\n<message>
#
# (c) 2010 Marco Verleun, marco at marcoach.nl
 
# Get the message from STDIN
MESSAGE=$(cat /dev/stdin)
echo $MESSAGE
 
# Create a file in the outging queue
SMSFILE=$(mktemp /var/spool/sms/outgoing/send_XXXXXX)
# Fill it with the contents of the message
cat > $SMSFILE<< EOT
$MESSAGE
EOT

Finally add a command to nagios that can be used to send the notifications for hosts:

define command {
 command_name notify-host-by-sms
 command_line /usr/bin/printf "%b" "To: $CONTACTPAGER$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"  | /usr/local/bin/nagios-send-sms
}

 

Add comment


Security code
Refresh

Nederlands - nl-NLEnglish (United Kingdom)
Search
Powered by MarCoach
Banner
Powered by MarCoach
Banner
Powered by MarCoach
Banner
Powered by MarCoach
Banner
Powered by MarCoach
Banner
Powered by MarCoach
Banner
Powered by MarCoach
Banner
Powered by MarCoach
Banner