Sipsak package Was: Re: Invitation to join pkg-voip team (iaxmodem in NEW )

Daniel Pocock daniel at readytechnology.co.uk
Thu Mar 16 19:09:07 UTC 2006



Jérôme Warnier wrote:

>Le mercredi 15 mars 2006 à 23:42 +0100, Jan Janak a écrit :
>  
>
>>Tzafrir Cohen wrote:
>>    
>>
>>>On Wed, Mar 15, 2006 at 09:39:50PM +0100, Jan Janak wrote:
>>>      
>>>
>>>>BTW, another package which might be of interest for pkg-voip-maintainers is
>>>>sipsak. It is a general purpose command line test tool for SIP equipment:
>>>>
>>>>Package: sipsak
>>>>        
>>>>
>>>Frankly, I never managed to find any real use of sipsak. I did use sipp
>>>(called sip-tester in Debian).
>>>      
>>>
>>  One useful feature in sipsak is the ping mode, which can be used for
>>  automated testing of SIP servers, when you need to find out whether
>>  your SIP server is still alive.
>>    
>>
>Do you have already any service monitoring definition for Nagios using
>it?
>  
>
This perl script has been floating around, it is GPL and you are welcome 
to include it in any package.

I've modified it a little for the following:
- add username and password on the command line, use -u and -s
- add `-p' option so you can force the request to a specific proxy IP, 
good for clusters where several proxies are linked to the same DNS A 
record or DNS SRV


define command{
        command_name    check_sip
        command_line    /usr/local/bin/check_sip $ARG1$ -p $HOSTADDRESS$ 
-w 100000 -c 700000
        }


#! /usr/bin/perl -w
#
# check_ser: Nagios plugin for checking SER using sipsak.
# Alex Mayrhofer, nic.at <axelm at nic.at>
# no warranty, licensed GPL2
# modified to work with Asterisk by <ricvil at telesip.net>
# extended by Daniel Pocock, www.readytechnology.co.uk

use strict;
use Getopt::Long;
use vars qw($opt_w $opt_c $opt_p $opt_u $opt_s $opt_U $param $PROGNAME 
$warning
  $url $host $password);
use lib "/usr/lib/nagios/plugins";
use utils qw(%ERRORS &print_revision &support &usage);
$PROGNAME="check_ser";

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,
 "p|proxy=s"    => \$opt_p,
 "u|user=s"     => \$opt_u,
 "s|secret=s"   => \$opt_s,
 "U|url=s" => \$opt_U,);

($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\.]+)$/);

my $proxy = $opt_p;

($url) || usage("Invalid URL: $opt_U\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;

my $auth=0;

if($opt_u) {
  $auth = "-u $opt_u -a $opt_s";
}

#Put UDP port that the SER SIP stack is listening on after the '-r' below
$param =  "-p $proxy -s $url -vv -r 5060 $auth" ;

$sig = `/usr/bin/sipsak $param`;

if ($sig =~ m/received ICMP packet (\(.*\))/) {
  printf "SIP CRITICAL - ICMP [$1] received\n";
  exit $ERRORS{'CRITICAL'};
}

if ($sig =~ m/404 Not Found/) {
   print "SIP CRITICAL - missing 404 reply\n";
   exit $ERRORS{'CRITICAL'};
}

if ($sig =~ m/reply received after ([0-9\.]+) ms/) {
  if ($sig =~ m/reply received ([0-9\.]+) ms after first send/) {
    print "SIP CRITICAL - missing duration value\n";
    exit $ERRORS{'CRITICAL'};
  } else {
    $sig = $1;
  }
} else {
  $sig = $1;
}

if ($sig * 1000 > $critical) {
  print "SIP CRITICAL - Test Duration: $sig ms\n";
  exit $ERRORS{'CRITICAL'};
}

if ($sig * 1000 > $warning) {
  print "SIP WARNING - Test Duration: $sig ms\n";
  exit $ERRORS{'WARNING'}
}

print "SIP OK - Test Duration: $sig ms\n";
exit $ERRORS{'OK'};

sub print_usage () {
  print "Usage: $PROGNAME  -U <sip url> -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 Asterisk SIP Channel.

";
print_usage();
  print "
  -U, --url=STRING
    SIP URL to use for check
  -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 Pkg-voip-maintainers mailing list