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 DATABASE 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 and start it by this init script.

Client script

A simple client script ssms.pl is used to insert jobs to the server.

Configuration

Define the command to send SMS alert:

# host notify (abort retry after 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 (abort retry after 7200 seconds)
define command{
        command_name    svc-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   svc-notify-by-smsd
        host_notification_commands      host-notify-by-smsd
        pager                           85291234567
        ...
        }
nagios/alert_using_sms.txt · Last modified: 2010-02-15 15:57 by admin
Back to top
GNU Free Documentation License 1.2
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