[Serusers] trying on a nagios plugin for SER

Alexander Mayrhofer axelm at nic.at
Wed Jan 21 14:55:31 CET 2004


Hi,

i've written a simple plugin for Nagios to monitor SER. It leverages
sipsak to register and "ping" a contact on a SIP server (tested with
SER). 

Please find the plugin below, consider it GPL2-licensed (read: if you
improve it, i want you to let me know ;) and without any warranty. We
never used it to wake up an engineer, but we've been using it for a
few weeks on our test monitoring instance. 

err, not to forger: consider it alpha level software.

share & enjoy.

--
axelm
-------------- next part --------------
#! /usr/bin/perl -wT
# 
# check_ser: Nagios plugin for checking SER using sipsak.
# Alex Mayrhofer, nic.at <axelm at nic.at> 
# no warranty, licensed GPL2

BEGIN {
	if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
		$runtimedir = $1;
		$PROGNAME = $2;
	}
}

use strict;
use Getopt::Long;
use vars qw($opt_H $opt_w $opt_c $opt_U $opt_P $param $PROGNAME $warning
	$url $host $password);
use lib $main::runtimedir;
use utils qw(%ERRORS &print_revision &support &usage);

sub print_help ();
sub print_usage ();

delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions
	("V|version"    => \&version,
	 "h|help"       => \&help,
	 "w|warning=s"  => \$opt_w,
	 "c|critical=s" => \$opt_c,
	 "H|hostname=s" => \$opt_H,
	 "U|url=s" => \$opt_U,
	 "P|password=s" => \$opt_P);

($opt_U) || ($opt_U = shift) || usage("URL not specified\n");
# TODO: allow port and parameters?
my $url = $1 if ($opt_U =~ m/^(sip:[a-zA-Z0-9\+\*#]+\@[a-zA-Z0-9\.]+)$/);
($url) || usage("Invalid URL: $opt_U\n");

($opt_H) || ($opt_H = shift);
$host = $1 if ($opt_H =~ /^([a-z\.0-9]+)$/);
($host) || usage("Invalid host: $opt_H\n");

($opt_P) || ($opt_P = shift);
$password = $1 if ($opt_P =~ /^([a-z\.0-9\@#]+)$/);
($password) || usage("Invalid password: $opt_P\n");

($opt_w) || ($opt_w = shift) || usage("Warning threshold not specified\n");
$warning = $1 if ($opt_w =~ /([0-9]+)$/);
($warning) || usage("Invalid warning threshold: $opt_w\n");

($opt_c) || ($opt_c = shift) || usage("Critical threshold not specified\n");
my $critical = $1 if ($opt_c =~ /([0-9]+)$/);
($critical) || usage("Invalid critical threshold: $opt_c\n");

my $sig=0;
my $param=0;
$param = ($host) ? "-H $host -s $url -a $password -U -M -d" :
	 "-s $url -a $password -U -M -d";
$sig = `/usr/bin/sipsak $param`;

if ($sig !~ m/tests completed successful/) {
   exit $ERRORS{'CRITICAL'};
   }

if ($sig !~ m/message ([0-9\.]+) ms after/) {
   exit $ERRORS{'CRITICAL'};
   }

$sig = $1;

print "Test Duration: $sig ms\n";

exit $ERRORS{'CRITICAL'} if ($sig>$critical);
exit $ERRORS{'WARNING'} if ($sig>$warning);
exit $ERRORS{'OK'};


sub print_usage () {
	print "Usage: $PROGNAME -H <host> -U <sip url> -P <password> -w <warn> -c <crit>\n";
}

sub print_help () {
	print_revision($PROGNAME,'version 0.1');
	print "Copyright (c) 2003 nic.at (Alexander Mayrhofer)

This plugin tests a SIP eXpress Router.

";
	print_usage();
	print "
-U, --url=STRING
   SIP URL to use for check
-P, --password=STRING
   SIP password to use for registering
-w, --warning=INTEGER
   response time in ms above which a WARNING status will result
-c, --critical=INTEGER
   response time in ms above which a CRITICAL status will result

";
	support();
}

sub version () {
	print_revision($PROGNAME,'Version: 0.1');
	exit $ERRORS{'OK'};
}

sub help () {
	print_help();
	exit $ERRORS{'OK'};
}


More information about the sr-users mailing list