Nagios 3.x.x/Icinga 1.x.x Server Integration For SMS Alerts Via FoxBox Devices On Debian Squeeze

Nagios 3.x.x/Icinga 1.x.x Server Integration For SMS Alerts Via FoxBox Devices On Debian Squeeze



This tutorial explains how to integrate a standard Nagios (or Icinga) monitoring server with an SMS notification external device, the FoxBox (www.smsfoxbox.it).


1 Preliminary note


FoxBox, as stated by manufacturers, comes in two similar versions (G25 and LX800) differing on hardware specifics.

In this guide we will refer to SMS Gateway LX800 (we bought this one because of its higher performance, and the CompactFlash storage), but I am confident that it could be extended to other versions without problems.



Our server runs the Nagios Core 3.5.0 (with 1.4.16 Nagios plugins) on a Debian Squeeze. Probably for different distros the paths will change, but the logic remains petty much the same.


2 Installation on the FoxBox side


The device is designed for these kind of communication tasks, so there is not much to do here except:


  • Provide a valid IP address, reachable from our monitoring server;

  • Insert a tested and full working SIM card, to send the SMS.

3 Installation on the Server side


First of all we need to place this script inside of the folder /usr/lib/nagios/plugins/:


#!/usr/bin/perl
use LWP::UserAgent;
use Getopt::Long;
use strict;
use warnings;
use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
use constant UNKNOWN => 3;
use constant SEND_PAGE => "/source/send_sms.php";
my($ host);
my($ username);
my($ password);
my($ number);
my($ message);
sub usage() {
print("Usage: send_sms -h|--host <host> -u|--user <username> --pw|--pass
<password> -n|--number
<phone_number> -m|--message <message>\n\n");
print("<host> - IP address or hostname of the SMS FoxBox\n");
print("<username> - name of the SMS FoxBox administrator\n");
print("
<password> - password of the SMS FoxBox administrator\n");
print("
<phone_number> - phone number where SMS will be sent\n");
print("<message> - message to be sent\n");
}
sub send_sms {
my($ host, $ user, $ pass, $ phonenum, $ text) = @_;
my($ ua);
my($ html_page);
my($ response);
my($ status_code);
$ ua = LWP::UserAgent-&gt;new;
$ ua-&gt;timeout(10);
$ response = $ ua-&gt;post("http://$ host" . SEND_PAGE,
[
"username" =&gt; $ user,
"pwd" =&gt; $ pass,
"from" =&gt; 'Nagios',
"nphone" =&gt; $ phonenum,
"testo" =&gt; $ text,
"nc" =&gt; "http://$ host" . SEND_PAGE
]);
if(!$ response-&gt;is_success) {
print("ERROR: " . $ response-&gt;status_line . "\n");
$ status_code = UNKNOWN;
}
$ html_page = $ response-&gt;content;
if($ html_page =~ /p class="(\w+)"/g) {
if($ 1 eq "confneg") {
print("ERROR: Unable to send SMS\n");
$ status_code = UNKNOWN;
}
else {
$ status_code = OK;
}
}
else {
print("ERROR: Unknown page output\n");
$ status_code = UNKNOWN;
}
return $ status_code;
}
undef $ host;
undef $ username;
undef $ password;
undef $ number;
undef $ message;
GetOptions( 'host|H=s' =&gt; $ host,
'user|u=s' =&gt; $ username,
'pass|pw=s' =&gt; $ password,
'number|n=s' =&gt; $ number,
'message|m=s' =&gt; $ message);
if(!defined $ host || !defined $ username || !defined $ password || !defined $ number || !defined $ message) {
usage();
exit(UNKNOWN);
}

$ message =~ s/\n/\n/g;
my($ ret_status);
$ ret_status = send_sms($ host, $ username, $ password, $ number, $ message);
exit($ ret_status);

It is also important to set properly the permissions on this file, to allow the Nagios user executing it.


Now we should add the new notification commands, working on the SMS channel instead of the classic email one. To do so, we have to add these lines to the file /etc/nagios3/commands.cfg:


# 'notify-host-by-foxbox' command definition
define command{
command_name notify-host-by-foxbox
command_line /usr/lib/nagios/plugins/sendSMS.sh -h "127.0.0.1" -u "nagiosadmin" -pw "nagios" -n "$ CONTACTPAGER$ " -m "Host Alert: $ HOSTNAME$ \nHost State: $ HOSTSTATE$ \nDate/Time: $ LONGDATETIME$ "
}
# 'notify-service-by-foxbox' command definition
define command{
command_name notify-service-by-foxbox
command_line /usr/lib/nagios/plugins/sendSMS.sh -h "127.0.0.1" -u "nagiosadmin" -pw "nagios" -n "$ CONTACTPAGER$ " -m "Service Alert: $ HOSTALIAS$ /$ SERVICEDESC$ \nService State: $ SERVICESTATE$ \nDate/Time: $ LONGDATETIME$ "
}

As you can see, we need a new information for the contacts: the phone number. Thus, we have to define it as “pager” in the file /etc/nagios3/conf.d/contacts_nagios2.cfg.


Moreover, we set up the service/host notification command. By default these are using the email channel, while we want to alert with the new notification commands, so we have to edit the parameters “service_notification_commands” and “host_notification_commands” too:


define contact{
contact_name test-contact
use generic-contact
alias tester
email yourname@domain
host_notification_commands notify-host-by-foxbox
service_notification_commands notify-service-by-foxbox
pager 12453683421
}

Obviously, once finished the configurations we have to restart the Nagios service in order to see their effects.


To check that everything is ok, maybe you could launch the pre-flight check with


nagios3 -v /etc/nagios3/nagios.cfg


As I see, this architecture has also been implemented on a pair of FoxBox versions, providing an all-in-one notification solution (EasyG2 G25 and Monitoring LX800).


(Reference: www.smsfoxbox.it)



Nagios 3.x.x/Icinga 1.x.x Server Integration For SMS Alerts Via FoxBox Devices On Debian Squeeze



Nagios 3.x.x/Icinga 1.x.x Server Integration For SMS Alerts Via FoxBox Devices On Debian Squeeze
Terima kasih telah membaca artikel tentang Nagios 3.x.x/Icinga 1.x.x Server Integration For SMS Alerts Via FoxBox Devices On Debian Squeeze di blog Tutorial Opensource and Linux jika anda ingin menyebar luaskan artikel ini di mohon untuk mencantumkan link sebagai Sumbernya, dan bila artikel ini bermanfaat silakan bookmark halaman ini di web browser anda, dengan cara menekan Ctrl + D pada tombol keyboard anda.

Artikel terbaru :