Build precise queries to find exactly what you need
Press ESC to close
Your review has been submitted and is pending approval.
This plugin will test a SIP server/device for availability and response time.
Current Version
Last Release Date
June 18, 2009
Owner
Nagios Exchange
Website
http://bashton.com/osprojects/nagiosplugins/
check_sip 1.0
Requirements: - A working Nagios install - Perl 5 or above
I created following patch, to support also tcp and tls-transport methods. You can also download the script here: https://www.swabian.net/extern/nagios/check_sip --- check_sip 2016-10-29 05:39:08.000000000 +0200 +++ check_sip 2025-04-24 10:28:37.037230951 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w # # check_sip plugin for nagios -# $Revision: 1.3 $ +# $Revision: 1.3.1 $ # # Nagios plugin to check SIP servers # @@ -30,21 +30,24 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support); use vars qw($PROGNAME); use IO::Socket::INET; +use IO::Socket::SSL; +use IO::Select; #use Sys::Hostname; use Time::HiRes qw(gettimeofday ualarm); use Net::Domain qw (hostname hostfqdn hostdomain); use Switch; +use Fcntl; $PROGNAME = "check_sip"; -my $VERSION = "1.3.0"; +my $VERSION = "1.3.1"; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; $ENV{'PATH'}=''; $ENV{'LC_ALL'}='C'; -my ($opt_V,$opt_h,$opt_u,$opt_p,$opt_H, $opt_w, $opt_s, $opt_f); -$opt_V = $opt_h = $opt_u = $opt_p = $opt_H = $opt_w = $opt_s = $opt_f = ''; +my ($opt_V,$opt_h,$opt_u,$opt_p,$opt_H, $opt_w, $opt_s, $opt_f, $opt_m); +$opt_V = $opt_h = $opt_u = $opt_p = $opt_H = $opt_w = $opt_s = $opt_f = $opt_m = ''; my $state = 'UNKNOWN'; @@ -58,7 +61,8 @@ "u=s" => $opt_u, "uri=s" => $opt_u, "p=s" => $opt_p, "port=s" => $opt_p, "H=s" => $opt_H, "host=s" => $opt_H, - "w=s" => $opt_w, "warn=s" => $opt_w + "w=s" => $opt_w, "warn=s" => $opt_w, + "m=s" => $opt_m, "method=s" => $opt_m ); # -h displays help @@ -73,8 +77,14 @@ # Check the sip URI is OK unless ($opt_u) { printHelp(); exit $ERRORS{'UNKNOWN'} } -# Port is 5060 unless otherwise specified -unless ($opt_p) { $opt_p = 5060 } +# Port is 5060/5061 unless otherwise specified +unless ($opt_p) { + if ($opt_m =~ /^tls1_.$/) { + $opt_p = 5061; + } else { + $opt_p = 5060; + } +} # Determine the host from the sip URI if it wasn't specified with -H unless ($opt_H) { $opt_H = hostFromURI($opt_u) } @@ -113,30 +123,32 @@ my $localhost = hostfqdn(); $opt_f = getFromURI($opt_f,$localhost,$opt_p); my $user=getUserPart($opt_f); -my $socket = uconnect($opt_H, $opt_p); +my $socket = uconnect($opt_H, $opt_p,$opt_m); my @localinfo = unpack_sockaddr_in($socket->sockname); my $req = buildReq($localinfo[0], $opt_u, $opt_f,$user,$localhost); ($startsec, $starttime) = gettimeofday; my $response; - +my $selector = IO::Select->new($socket); for($TIMEOUT=0,$resend_times=0,$max_resend=11;$resend_timessend($req); -$response=''; -$resend_times++; -# sip retransmission, totally 35.5 seconds. -switch($resend_times){ - case 1 { ualarm(500000); } - case 2 { $TIMEOUT=1; alarm($TIMEOUT); } - case 3 { $TIMEOUT=2; alarm($TIMEOUT); } - else { $TIMEOUT=4; alarm($TIMEOUT); } -} -#print $resend_times."->".$Total_timeout." $TIMEOUTn"; -$socket->recv($response, 1024) or $state = 'CRITICAL'; # TODO: CHECK and show '503 Service Unavailable' when receiving unreachable ICMP packet. -#get rid of the 100 Trying - provisional response ... -if ($response && getResponseCode($response) eq "100"){ - $socket->recv($response, 1024) or $state = 'CRITICAL'; -} -last if ($response); + $socket->write($req); #send + $response=''; + $resend_times++; + # sip retransmission, totally 35.5 seconds. + switch($resend_times){ + case 1 { ualarm(500000); } + case 2 { $TIMEOUT=1; alarm($TIMEOUT); } + case 3 { $TIMEOUT=2; alarm($TIMEOUT); } + else { $TIMEOUT=4; alarm($TIMEOUT); } + } + if ($selector->can_read(5)) { + #print $resend_times."-> $TIMEOUTn"; + $socket->read($response, 1024) or $state = 'CRITICAL'; # TODO: CHECK and show '503 Service Unavailable' when receiving unreachable ICMP packet. + #get rid of the 100 Trying - provisional response ... + if ($response && getResponseCode($response) eq "100"){ + $socket->read($response, 1024) or $state = 'CRITICAL'; + } + } + last if ($response); } ($finishsec, $finishtime) = gettimeofday; $secdiff=$finishsec-$startsec; @@ -155,9 +167,41 @@ sub uconnect { - my ($host, $port) = @_; - my $socket = new IO::Socket::INET->new(PeerPort=>$port, Proto=>'udp', PeerAddr=>$host); + my ($host, $port, $method) = @_; + my $socket; + if ("$method" eq "tcp") { + $socket = new IO::Socket::INET->new(PeerPort=>$port, Proto=>'tcp', PeerAddr=>$host); + } elsif ("$method" eq "tls1_1") { + $socket = new IO::Socket::SSL->new( + PeerAddr => $host, + PeerPort => $port, + Proto => 'tcp', + SSL_version => 'TLSv1_1', + SSL_verify_mode => SSL_VERIFY_PEER, # You can change this + ); + } elsif ("$method" eq "tls1_2") { + $socket = new IO::Socket::SSL->new( + PeerAddr => $host, + PeerPort => $port, + Proto => 'tcp', + SSL_version => 'TLSv1_2', + SSL_verify_mode => SSL_VERIFY_PEER, # You can change this + ); + } elsif ("$method" eq "tls1_3") { + $socket = new IO::Socket::SSL->new( + PeerAddr => $host, + PeerPort => $port, + Proto => 'tcp', + SSL_version => 'TLSv1_3', + SSL_verify_mode => SSL_VERIFY_PEER, # You can change this + ); + } elsif("$method" eq "udp" || "$method" eq "") { + $socket = new IO::Socket::INET->new(PeerPort=>$port, Proto=>'udp', PeerAddr=>$host); + } else { + print "unsupported method: $methodn"; exit $ERRORS{'UNKNOWN'} + } unless ($socket) { print "Unable to connect to $hostn"; exit $ERRORS{'UNKNOWN'} } + fcntl($socket, F_SETFL, O_NONBLOCK); return $socket; } @@ -229,7 +273,7 @@ sub printHelp { print "This plugin tests the sip service on the specified host.nn"; - print "Usage: $PROGNAME -u sip:[email protected] [-H host -p PORT -f sip:[email protected] -w WARNTIME -s]n"; + print "Usage: $PROGNAME -u sip:[email protected] [-H host -p PORT -f sip:[email protected] -w WARNTIME -s -m METHOD]n"; print " $PROGNAME [-h | --help]n"; print " $PROGNAME [-V | --version]nn"; print "Options:n"; @@ -245,6 +289,8 @@ print " Port to connect ton"; print " -f sip:[email protected]"; print " Full SIP uri, will be used for the "From:"-Headern"; + print " -m [tcp,udp,tls1_1,tls1_2,tls1_3]n"; + print " Method to use to connect, default udpn"; print " -sn"; print " Changes default behavior: all SIP-responses will result in an "OK"nn";
Thanks for this plugin. I applied the following (cosmetic) patch, though: --- check_sip.orig 2010-09-05 07:34:02.000000000 +0200 +++ check_sip 2010-09-05 07:33:27.000000000 +0200 @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl ## # check_sip - (c) 2005-2006 O'Shaughnessy Evans @@ -37,7 +37,7 @@ BEGIN { $Contact_Host = hostname(); $REG_Mode = 0; - $Usage = "$ME -H host [-c contact] [-P proxy] [-p port] [-u user] [-U uri] [-v]"; + $Usage = "$ME -H host [-c contact] [-P proxy] [-p port] [-u user] [-U uri] [-v]n"; $Help =
You must be logged in to submit a review.
To:
From: