SMS Notifications
Subscribe

From OpenNMS

Jump to: navigation, search

Creating SMS Notifications with a GSM Modem

This system is based on OpenNMS 1.3.5, though I believe should work with any version of 1.3.*. We had it installed on Suse 10.2, though again the underlying operating system shouldn't matter. A nice thing about the components we use is that it allows us to use SMS messages to acknowledge notifications sent from the OpenNMS system by setting it up to process incoming SMS messages.

The components used are as follows:

Hardware

  • Siemens MC35i GSM Modem stater kit

This is a GSM/GPRS dual band modem for Europe so it'd be GSM-900 and GSM-1800

  • SIM Card from a provider

Software

  • Stefan Frings SMS Server Tools

This software package is available at SMS Server Tools, where he also has some very easy to follow simple tutorials on how to compile, install, setup and run the sms daemon.

Configuration

SMS Server Tools

I'll assume that you followed the guides on the SMS Server Tools website for compiling and installing the software. Our configuration file /etc/smsd.conf is as follows:

devices = GSM1
logfile = /var/log/smsd.log
loglevel = 7
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed
incoming = /var/spool/sms/incoming
sent = /var/spool/sms/sent
stats = /var/smstools/stats
stats_interval = 3600
eventhandler = /usr/local/sbin/smsevent

[GSM1]
device = /dev/ttyS0
incoming = yes
memory_start = 1
mode = new
baudrate = 19200
rtscts = yes
report = no
#pin = 1111

As you can see, you can have multiple GSM modems. We are only using one. All the necessary queues are in /var/spool/sms/ and we have a script at /usr/local/sbin/smsevent which the eventhandler calls whenever the modem receives an incoming SMS message for the sms daemon to process, detailed below.

The modem interface is RS-232, so some fields in the configuration contained in the section [GSM1] contains values for communicating with it. The device=/dev/ttyS0 and even the baudrate=19200 may differ depending on the Operating System and hardware of your server, and whether you use RS-232 or USB.

We accept incoming messages with incoming=yes and as we did not have our SIM card PIN protected we have commented out the field 'pin'.

Start the sms daemon and test sending an SMS message using the instructions on the SMS Server Tool's site.

OpenNMS

Here's what we need to configure in the OpenNMS file notificationCommands.xml:

<command binary="true">
      <name>smsgw</name>
      <execute>/usr/local/bin/sendsms</execute>
      <comment>Class for sending GSM SMS notifications</comment>
      <argument streamed="false">
        <switch>-np</switch>
      </argument>
      <argument streamed="false">
        <switch>-tm</switch>
      </argument>
</command>

We are using the numerical pin field in the User Accounts file $OPENNMS_HOME/etc/users.xml to store the mobile number and the text message field in $OPENNMS_HOME/etc/notifications.xml for the notification details.

The program /usr/local/bin/sendsms takes a mobile number and message body on the commandline as parameters, i.e. sendsms <mobile#> "text message", so this is all you need.


Next is just an example of how we use the smsgw class we set up in notificationCommands.xml in the destinationPaths.xml file

<path name="SMS-L1" initial-delay="1s">
        <target interval="0s">
            <name xmlns="">l1-support</name>
            <autoNotify xmlns="">auto</autoNotify>
            <command xmlns="">javaEmail</command>
        </target>
        <escalate delay="30s">
            <target interval="0m">
                <name xmlns="">DaySupportDesk</name>
                <autoNotify xmlns="">auto</autoNotify>
                <command xmlns="">smsgw</command>
            </target>
        </escalate>
        <escalate delay="5m">
            <target interval="0m">
                <name xmlns="">NightSupportDesk</name>
                <autoNotify xmlns="">auto</autoNotify>
                <command xmlns="">smsgw</command>
            </target>
        </escalate>
    </path>

Nice Tricks

We also can send back sms messages with the notification id as the message body to acknowledge notifications and stop any escalations. This is a bash script referenced under the eventhandler attribute in smsd.conf above. In our case at /usr/local/sbin/smsevent

# This section is for OpenNMS SMS Notification Acknowledgements

if [ "$1" = "RECEIVED" ]; then
        mobileNum=`head -n 1 $2 | awk '{print $2}'`
        notifyId=`tail -n 1 $2 | awk '{print $1}'`
        sudo -u postgres psql -U opennms -c "update notifications set
respondtime=now(),answeredby=$mobileNum where notifyid=$notifyId;"
fi

We're taking any SMS that has being received and extracting two data fields from it. The sending mobile number and the notification id. We're then running an sql statement to update the relevent notifications row with a timestamp (as this sets the notification to acknowledged) in respondtime, and answered by as the senders mobile for record purposes.

Just to give the above script a bit more meaning, the following is and example of the contents of a message file in the incoming queue in SMS Server Tools. (I've hidden the sending mobile number).

From_SMSC: 353876xxxxxx
Sent: 07-11-08 12:33:29
Received: 07-11-08 12:34:32
Subject: GSM1
Alphabet: ISO
UDH: false

80827

What else would be nice?

  • I'd like a phone that's a bit easier to extract a number from an SMS message to reply with that number as the text body. The older Nokias used to be able to do that, but with the latest one's it's a gymnastic feat. Any suggestions welcome?
  • I would like it if my script could parse the users.xml file and extract the users name from the xml based on the mobile number, to populate the answered by field in the notifications table, but I'm afraid I not yet up to the task. I was messing around with Java and Xerces. Does anyone have an idea for this?