SMS alerts My how-to

Kyriacos Sakkas sakkas at unimedcy.com
Thu Oct 21 16:46:21 CEST 2004


Hi all,
    This is my quick and dirty way od doing SMS alerts. I anybody ccan  
sugest improvments or a   better way, let me know. ( I will point out a 
couple of what I consider problem spots).

    First the System : Dell Optiplex GX270 running Debian Testing Kernel 
2.4.27.
    Siemens S55 phone conected via serial port (ttyS0), phone will 
change, as this is my        personal mobile phone...
    I am using only oficial debs for this.
    Software : Nagios 1.2, gsm-utils, libgsmme1c102.
       From gsm-utils I use the gsmsendsms command to do the actuall SMS 
sending.

Now the dirty work:
(creation a notification method by using gsmsendsms as part of the 
actual notify command didn't work)
So,
1. Create a script that can transfer file contents to gsmsendsms:
Script name smsspool.sh placed in /usr/local/scripts/ although this is a 
personal choice.
Actual Script below-----------
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/scripts

for i in /var/spool/sms/sms*
do
num=`cut -d @ -f 2 $i`
msg=`cut -d @ -f 1 $i`
/usr/bin/gsmsendsms -b 9600 -d /dev/mobilephone $num "$msg"
logger "SMS Message Send to: $num"
rm -f $i
done

exit 0
Script end-------------
As you can see this script uses a spool directory. This needs to be rw 
to nagios(or globally).
Now, getting nagios to create a spooled sms:
In misccommands.cfg (in /etc/nagios/ for my setup) I defined an new 
notification method,(two actually, service and host, but currently they 
are exactly the same)
Here is the notificaton command---------
define command{
        command_name    notify-by-sms
        command_line    /usr/bin/printf "%b" "$NOTIFICATIONTYPE$: 
$HOSTNAME$: $SERVICEDESC$ is $SERVICE STATE$ ($OUTPUT$)@$CONTACTPAGER$"  
 > /var/spool/sms/sms`date +%d%m%Y%H%M%S%N`
        }
End of notification command------
Now all that is left is getting smsspool.sh to scan that directory 
periodicaly, a perfect job for cron :

*  *    * * *   root    /usr/local/scripts/smsspool.sh

Now the setup is complete, and nagios can bother you in the middle of 
the nigh abou anything it feels like...

So, this works, but I have a small problem which,  to be frank is not 
very importand, but its being a busy day, so if somenoe can tell me what 
I missed, I'd be gratefull...
Problem : As you can see I use the logger command, in my script, in 
order to get something miningfull in my syslog, in case I need to check 
on whats going on. Problem is that even when there are no files in the 
spool directory the for loop is entered, generating unnesesary log traffic:

Oct 21 17:36:05 localhost logger: SMS Message Send to:

If there is a simple solution, that would solve this while not getting 
the script too complex,
I would like to know... I'm sure its something simple (a while loop? - 
cant figure out a _simple_ way to hand it a file list as a condition), 
but it's got me stuck for now.

So, thanks in advance for any feedback,

Kyriacos Sakkas




-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list