Nagios SMS Notificaties

Het versturen van SMS notifacties vanuit Nagios is niet zo ingewikkeld als vaak wordt gedacht. Om een notificatie te versturen roept Nagios externe scripts aan waarbij macro's worden overgedragen als argumenten.

Om SMS notificaties te kunnen versturen is een SMS device nodig, in het voorbeeld hieronder gebruiken we een dongle.

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.

De dongle presenteert zichzelf als een /dev/ttyUSB modem aan het operating systeem. Dit modem kan met de AT commandoset worden bestuurd. De gebruikte dongle is een  'Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem' welke wordt aangestuurd door SMS Server Tools 3.Het configuratiebestand voor de sms tools, /etc/smsd.conf ziet er als volgt uit:

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

Zodra sms tools geconfigureerd is dient de service tijdens het booten automatisch te worden gestart:

chkconfig smsd on

Start smsd:

service smsd start

Controleer dat alles werkt:

smssend  “Message…”

De volgende stap is het schrijven van een shell script dat de medlingen van Nagios ontvangt en doorgeeft aan smsd. Het volgende script heeft als naam /usr/loca/bin/nagios-send-sms en ziet er als volgt uit:

#!/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

Als laatste definieren we een Nagios commando dat gebruikt zal worden om de meldingen te versturen.:

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
}

 

Plaats reactie


Beveiligingscode
Vernieuwen

NederlandsEnglish (United Kingdom)
Zoeken
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