#! /usr/bin/perl -wT # # check_ser: Nagios plugin for checking SER using sipsak. # Alex Mayrhofer, 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 -U -P -w -c \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'}; }