Alert using SMS

Requirements

Installing the SMS Dispatcher Server

Server Features:

  • fault tolerance by using a locally connected GSM modem as backup.
  • local buffering using a MySQL database.
  • scheduling

First, setup the database smsd:

CREATE DATABASE smsd;

GRANT ALL PRIVILEGES ON smsd.* to 'nagios'@'localhost' IDENTIFIED BY 'secretpw';

USE smsd;

CREATE TABLE `sms_queue` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `queue_date` int(11) unsigned NOT NULL default '0',
  `phone_no` varchar(20) NOT NULL default '',
  `sent_date` int(11) unsigned default NULL,
  `sent` enum('0','1') NOT NULL default '0',
  `tries` tinyint(4) unsigned default '0',
  `send_via` enum('G','L') default NULL,
  `sms_text` varchar(160) NOT NULL default '',
  `not_before` int(11) unsigned default NULL,
  `not_after` int(11) unsigned default NULL,
  `done` enum('0','1') default '0',
  `error` varchar(255) default NULL,
  `last_update` int(11) unsigned default NULL,
  PRIMARY KEY  (`id`),
  KEY `active_jobs_idx` (`not_after`,`not_before`,`done`),
  KEY `expired_jobs_idx` (`not_after`,`done`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE `sms_done_queue` (
  `id` int(11) unsigned NOT NULL default '0',
  `queue_date` int(11) unsigned NOT NULL default '0',
  `phone_no` varchar(20) NOT NULL default '',
  `sent_date` int(11) unsigned default NULL,
  `sent` enum('0','1') NOT NULL default '0',
  `tries` tinyint(4) unsigned default '0',
  `send_via` enum('G','L') default NULL,
  `sms_text` varchar(160) NOT NULL default '',
  `not_before` int(11) unsigned default NULL,
  `not_after` int(11) unsigned default NULL,
  `done` enum('0','1') default '0',
  `error` varchar(255) default NULL,
  `last_update` int(11) unsigned default NULL,
  PRIMARY KEY  (`id`),
  KEY `sent_idx` (`sent_date`,`sent`),
  KEY `jobs_idx` (`queue_date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Put the SMS Dispatcher Server script in /usr/sbin, its configuration file in /etc, and start it by this init script.

chown root:root smsd.pl
chmod 755 smsd.pl
cp smsd.pl /usr/sbin/

chown root:nagios smsd.conf
chmod 650 smsd.conf
cp smsd.conf /etc/

chown root:root smsd-init
chmod 755 smsd-init
cp smsd-init /etc/init.d/smsd
chkconfig --add smsd
chkconfig smsd on

Client script

A simple client script ssms.pl is used to insert jobs to the server. Install it to /usr/local/bin/:

chmod 755 ssms.pl
chown root:root ssms.pl
cp ssms.pl /usr/local/bin/

Configuration

Define the command to send SMS alert:

# host notify (set expire to default notification_interval = 7200 seconds)
define command{
        command_name    host-notify-by-smsd
        command_line    /usr/bin/perl /usr/local/bin/ssms.pl -t $NOTIFICATIONTYPE$ -a HOST -g $HOSTGROUPNAME$ -H $HOSTNAME$ -d $HOSTSTATEID$ -n $CONTACTPAGER$ -e 7200
        }  
              
# service notify (set expire to default notification_interval = 7200 seconds)
define command{
        command_name    service-notify-by-smsd
        command_line    /usr/bin/perl /usr/local/bin/ssms.pl -t $NOTIFICATIONTYPE$ -a SVC -g $HOSTGROUPNAME$ -H $HOSTNAME$ -s "$SERVICEDESC$" -d $SERVICESTATEID$ -o "$SERVICEOUTPUT$" -n $CONTACTPAGER$ -e 7200
        }  

Define a contact to use SMS alert:

define contact{
        ...
        service_notification_commands   service-notify-by-smsd
        host_notification_commands      host-notify-by-smsd
        pager                           85291234567
        ...
        }

Note - The mobile phone number must be prefix with country code.

Check SMS service credit

Put the check_sms_credit.pl script into the /usr/lib/nagios/plugins/ folder.

Check command definition:

# check SMS Service credits
define command{
        command_name    check_sms_credit
        command_line    $USER1$/check_sms_credit.pl -u $ARG1$ -p $ARG2$ -w $ARG3$ -c $ARG4$
        } 

Example service check definition:

define service{
    ...    
    service_description             SMS Credits
    normal_check_interval           60
    check_command                   check_sms_credit!username!password!30!10
    ...
        }
nagios/alert_using_sms.txt · Last modified: 2011-03-20 11:43 by admin
Back to top
GNU Free Documentation License 1.3
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0