#!/usr/bin/perl ## Script written by Noah Guttman and Copyright (C) 2011 Noah Guttman. This script is released and distributed under the terms of the GNU General Public License #Libraries to use use strict; use Getopt::Std; use vars qw($opt_h $opt_H $opt_M $opt_P); my $returnmessage = ""; my $baseport; my $returnname=""; my $n; my @output; my @line; my $val; my $sessions_created; my $active_sessions; my $active_streams; my $gah; my $testerrortotal; my $exitcode=3; my $threadsinroute; ##init(); # Get the options if ($#ARGV le 0) { $opt_h = 1; } else { getopts('hH:M:P:'); } ## Display Help if ($opt_h){ print "::RtpProxy Check Instructions::\n\n"; print " -h, Display this help information\n"; print " -H, Hostname or IP to check\n"; print " -M, Specify a message to return on failure\n"; print " -P, Port to monitor\n"; print " The default is 7899\n"; print "Script written by Noah Guttman and Copyright (C) 2011 Noah Guttman.\n"; print "This script is released and distributed under the terms of the GNU\n"; print "General Public License. >>>> http://www.gnu.org/licenses/\n"; print ""; print "This program is free software: you can redistribute it and/or modify\n"; print "it under the terms of the GNU General Public License as published by\n"; print "the Free Software Foundation.\n\n"; print "This program is distributed in the hope that it will be useful,\n"; print "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"; print "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"; print "GNU General Public License for more details.\n"; print ">>>> http://www.gnu.org/licenses/\n"; exit 0; } ##Set custom output if any set if ($opt_M){ $returnmessage=$opt_M; }else{ $returnmessage=""; } if ($opt_P){ $baseport=$opt_P; }else{ $baseport=7899; } #Check that the thread is responding $testerrortotal = 0; for ($n=0; $n < 4; $n++){ $gah = (`echo \"nagios_123456789 I\"|nc -w 1 -D -u $opt_H $baseport`); if ((($gah =~ /nagios_123456789 sessions created/i) && ($gah =~ /active sessions/i)) && ($gah =~ /active streams/i)){ chomp $gah; @output = split ("\n",$gah); foreach my $val (@output) { if ($val =~ /sessions created/i) { @line = split (":", $val); $sessions_created = substr(@line[1],1)."c"; }elsif ($val =~ /active sessions/i){ @line = split (":", $val); $active_sessions = substr(@line[1],1); }elsif ($val =~ /active streams/i){ @line = split (":", $val); $active_streams = substr(@line[1],1); } } if ($testerrortotal == 0){ print ("OK: RTP Proxy $opt_H:$baseport responded on the first attempt. It has $active_sessions active sessions with $active_streams active streams.|Active_Sessions=$active_sessions;; Active_Streams=$active_streams;; Sessions_Created=$sessions_created;; Errors=$testerrortotal;;\n"); exit 0; }else{ print ("WARNING: RTP Proxy $opt_H:$baseport responded after $testerrortotal failures. It has $active_sessions active sessions with $active_streams active streams.|Active_Sessions=$active_sessions;; Active_Streams=$active_streams;; Sessions_Created=$sessions_created;; Errors=$testerrortotal;;\n"); exit 1; } } $testerrortotal++; sleep (1); } print ("CRITICAL: RTP Proxy $opt_H:$baseport has not responded correctly after $testerrortotal attempts. $opt_M|Errors=$testerrortotal;;\n"); exit 2;