Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_sip

Rating
2 votes
Favoured:
1
Hits
121351
Files:
FileDescription
nagios-check_sip-1.0.tar.gzcheck_sip 1.0
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
This plugin will test a SIP server/device for availability and response time.
Requirements:
- A working Nagios install
- Perl 5 or above
Reviews (2)
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." $TIMEOUT\n";
-$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."-> $TIMEOUT\n";
+ $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: $method\n"; exit $ERRORS{'UNKNOWN'}
+ }
unless ($socket) { print "Unable to connect to $host\n"; 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.\n\n";
- print "Usage: $PROGNAME -u sip:uri\@example.com [-H host -p PORT -f sip:fromuri\@example.com -w WARNTIME -s]\n";
+ print "Usage: $PROGNAME -u sip:uri\@example.com [-H host -p PORT -f sip:fromuri\@example.com -w WARNTIME -s -m METHOD]\n";
print " $PROGNAME [-h | --help]\n";
print " $PROGNAME [-V | --version]\n\n";
print "Options:\n";
@@ -245,6 +289,8 @@
print " Port to connect to\n";
print " -f sip:fromuri\@example.com\n";
print " Full SIP uri, will be used for the \"From:\"-Header\n";
+ print " -m [tcp,udp,tls1_1,tls1_2,tls1_3]\n";
+ print " Method to use to connect, default udp\n";
print " -s\n";
print " Changes default behavior: all SIP-responses will result in an \"OK\"\n\n";
byckujau, September 4, 2010
1 of 1 people found this review helpful
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 =