The Guru College

SMS responses for nagios commands

With the recent upgrade to the MultiModem GPRS SMS radios for the nagios boxes at work came a new, feature I wasn’t expecting: the ability to easily receive SMS messages sent to the phone line. Even better yet, the messages are automatically stored in a mysql table, allowing simple programatic access to them.

Here is the plan – if a message about a host has been sent to an administrator’s mobile phone via SMS, the admin is able to respond with an SMS for the next 10 minutes. They name the host and the actions they want taken: recheck, maint, unmaint. These commands are then sent to the nagios command buffer where they will be executed as if the web interface had been used. For security, the daemon only listens for messages from the numbers it has sent messages to, and further, it only allows action to be taken on hosts it has sent alerts about. If you can think of any glaring security concerns with this, let me know, but I’m pretty sure that by keeping it simple, it’s not going to be open to abuse.

Honestly the hardest part of this was writing the perl script to properly daemonize, listen for sigkill / sigterm, and make sure the database connections are dropped cleanly when exiting in a controlled manner. There was one other small gotcha, for people looking to write their own 90 line perl daemon: gnokii-smsd records the country code on messages in the inbox, but does not require it for messages being sent (+9195550199 in the inbox, but 9195550199 in the outbox), so there is a minor bit of trickiness to validate and then compare the two sets of messages.

Lion FTW | Home | gurufoto.net