Modified: trunk/opsview-core/nagios-plugins/check_snmp_netscaler_httpssl
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_netscaler_httpssl 2013-02-07 09:52:37 UTC (rev 11373)
+++ trunk/opsview-core/nagios-plugins/check_snmp_netscaler_httpssl 2013-02-07 13:53:34 UTC (rev 11374)
@@ -20,110 +20,61 @@
# along with Opsview; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
+use strict;
+use warnings;
-use lib qw ( /usr/local/nagios/perl/lib );
+use FindBin qw($Bin);
+use lib "/opt/opsview/perl/lib/perl5", "$Bin/../lib";
use Net::SNMP;
-use Getopt::Std;
+use Opsview::NagiosPlugin::SNMP;
use Time::HiRes qw(gettimeofday);
-$script = "check_snmp_netscaler_serverconnections";
-$script_version = "2.1.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "check_snmp_netscaler_httpssl",
+ version => "2.1.1",
+ blurb => "Returns Netscaler server connections",
+ snmp => { "snmp-version" => 1, },
+);
-$metric = 1;
+$np->add_arg(
+ spec => "warning|w=s",
+ help => qq{-w, --warning=INTEGER
+ Warning threshold - HTTP requests / min},
+ default => 100,
+);
-# Netscaler root OID= 1.3.6.1.4.1.5951
+$np->add_arg(
+ spec => "critical|c=s",
+ help => qq{-c, --critical=INTEGER
+ Critical threshold - HTTP requests / min},
+ default => 200,
+);
-$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
-$oid_featuressloffloading = ".1.3.6.1.4.1.5951.4.1.1.20.9.0";
-$oid_sslenginestatus = ".1.3.6.1.4.1.5951.4.1.1.47.2.0";
-$oid_totalsslsessions = ".1.3.6.1.4.1.5951.4.1.1.47.3.0";
-$oid_totalunacksyn = ".1.3.6.1.4.1.5951.1.2.1.15.0";
-$oid_totalhttprequests = ".1.3.6.1.4.1.5951.1.2.1.18.1.0";
-$oid_featurecompression = ".1.3.6.1.4.1.5951.4.1.1.20.7.0";
-$oid_totalcompression = ".1.3.6.1.4.1.5951.1.7.1.1";
+$np->getopts;
-$sysDescr = "";
-$featuressloffloading = "";
-$sslenginestatus = "";
-$totalsslsessions = "";
-$totalunacksyn = "";
-$totalhttprequests = "";
-$featurecompression = "";
-$totalcompression = "";
+my $warning = $np->opts->warning;
+my $critical = $np->opts->critical;
-$ipaddress = "192.168.1.1"; # Default IP address
-$version = "1"; # SNMP version
-$community = "public";
-$timeout = 2; # Response timeout (seconds)
-$warning = 100;
-$critical = 200;
-$status = 0;
-$returnstring = "";
-$time = "";
+my $s = $np->snmp;
-@statusdata = ();
+my $oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
+my $oid_featuressloffloading = ".1.3.6.1.4.1.5951.4.1.1.20.9.0";
+my $oid_sslenginestatus = ".1.3.6.1.4.1.5951.4.1.1.47.2.0";
+my $oid_totalsslsessions = ".1.3.6.1.4.1.5951.4.1.1.47.3.0";
+my $oid_totalunacksyn = ".1.3.6.1.4.1.5951.1.2.1.15.0";
+my $oid_totalhttprequests = ".1.3.6.1.4.1.5951.1.2.1.18.1.0";
+my $oid_featurecompression = ".1.3.6.1.4.1.5951.4.1.1.20.7.0";
+my $oid_totalcompression = ".1.3.6.1.4.1.5951.1.7.1.1";
-$defaultcommunity = "public"; # Default community string
-$configfilepath = "/usr/local/nagios/etc";
-$firsttime = 0;
+my $status = 0;
+my $returnstring = "";
-my $port = 161;
+my $configfilepath = "/usr/local/nagios/etc";
+my $statusfile =
+ "/usr/local/nagios/var/status_netscaler_" . $s->hostname() . ".db";
+my $firsttime;
-# Do we have enough information?
-if ( @ARGV < 1 ) {
- print "Too few arguments\n";
- usage();
-}
-
-getopts( "hH:C:w:c:p:" );
-if ($opt_h) {
- usage();
- exit(0);
-}
-if ($opt_H) {
- $hostname = $opt_H;
-
- # print "Hostname $opt_H\n";
-}
-else {
- print "No hostname specified\n";
- usage();
-}
-if ($opt_C) {
- $defaultcommunity = $opt_C;
-
- # print "Using community $opt_C\n";
-}
-else {
-
- # print "Using community $community\n";
-}
-if ($opt_w) {
- $warning = $opt_w;
-
- # print "Warning threshold: $opt_w%\n";
-}
-if ($opt_c) {
- $critical = $opt_c;
-
- # print "Critical threshold: $opt_c%\n";
-}
-if ($opt_p) {
- $port = $opt_p;
-}
-
-$statusfile = "/usr/local/nagios/var/status_netscaler_$hostname.db";
-readstatus();
-
-# Create the SNMP session
-my ( $s, $e ) = Net::SNMP->session(
- -community => return_snmpcommunity($hostname),
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
-);
-
main();
# Close the session
@@ -158,6 +109,20 @@
my $prev_time = "";
my $prev_httprequests = "";
my $prev_unacksyn = "";
+ my $sslenginestatus;
+ my $totalsslsessions;
+ my $totalunacksyn;
+ my $totalcompression;
+ my $totalhttprequests;
+ my $featurecompression;
+ my $string_sslenginestatus;
+ my $string_featurecompression;
+ my $time;
+ my $diff_httprequests;
+ my $diff_time;
+ my $httprequests_min;
+ my $diff_unacksyn;
+ my $unacksyn_min;
if ( !defined( $s->get_request($oid_sslenginestatus) ) ) {
if ( !defined( $s->get_request($oid_sysDescr) ) ) {
@@ -304,9 +269,9 @@
}
( $prev_time, $prev_httprequests, $prev_unacksyn ) = readstatus();
- $time = gettimeofday;
+ $time = Time::HiRes::gettimeofday;
- if ( $totalhttprequests != "" ) {
+ if ( $totalhttprequests ne "" ) {
$diff_httprequests = $totalhttprequests - $prev_httprequests;
$diff_time = $time - $prev_time;
@@ -316,13 +281,13 @@
append( "(HTTP request/min: $httprequests_min), " );
}
- if ( $totalsslsessions != "" ) {
+ if ( $totalsslsessions ne "" ) {
append( "(Total SSL sessions: $totalsslsessions), " );
}
- if ( $totalcompression != "" ) {
+ if ( $totalcompression ne "" ) {
append( "(Total compression: $totalcompression), " );
}
- if ( $totalunacksyn != "" ) {
+ if ( $totalunacksyn ne "" ) {
$diff_unacksyn = $totalunacksyn - $prev_unacksyn;
$diff_time = $time - $prev_time;
@@ -347,35 +312,6 @@
}
####################################################################
-# help and usage information #
-####################################################################
-
-sub usage {
- print << "USAGE";
---------------------------------------------------------------------
-$script v$script_version
-
-Returns Netscaler server connections
-
-Usage: $script -H <hostname> -c <community> [...]
-Options: -H Hostname or IP address
- -p Port (default: 161)
- -C Community (default is public)
- -w Warning threshold - HTTP requests / min
- -c Critical threshold - HTTP requests / min
-
---------------------------------------------------------------------
-Copyright (C) 2003-2012 Opsview Limited. All rights reserved
-
-This program is free software; you can redistribute it or modify
-it under the terms of the GNU General Public License
---------------------------------------------------------------------
-
-USAGE
- exit 1;
-}
-
-####################################################################
# Reads in previous status information #
####################################################################
@@ -383,6 +319,7 @@
my $prev_time = "";
my $prev_httprequests = "";
my $prev_unacksyn = "";
+ my @statusdata;
if ( -e "$statusfile" ) {
open STATUSFILE, "<$statusfile"
@@ -390,8 +327,8 @@
@statusdata = <STATUSFILE>;
close STATUSFILE;
- ( $pref_time, $pref_httprequests, $pref_unacksyn ) =
- split( /:/, @statusdata[0] );
+ ( $prev_time, $prev_httprequests, $prev_unacksyn ) =
+ split( /:/, $statusdata[0] );
return ( $prev_time, $prev_httprequests, $prev_unacksyn );
}
@@ -406,9 +343,9 @@
####################################################################
sub writestatus {
- my $httprequests = @_[0];
- my $unacksyn = @_[1];
- $time = gettimeofday;
+ my $httprequests = $_[0];
+ my $unacksyn = $_[1];
+ my $time = gettimeofday;
open STATUSFILE, ">$statusfile" or die "Can't open file $statusfile: $1";
print STATUSFILE "$time:$httprequests:$unacksyn:\n";
@@ -420,7 +357,7 @@
####################################################################
sub append {
- my $appendstring = @_[0];
+ my $appendstring = $_[0];
$returnstring = "$returnstring$appendstring";
}
@@ -428,38 +365,3 @@
# Returns the SNMP community string for a given hostname / IP #
####################################################################
-sub return_snmpcommunity {
- my $requiredhostname = @_[0];
- my $returncommunity = $defaultcommunity;
- my $tempcommunity = "";
- my $temphostname = "";
-
- my $row = 0;
- my $nullval = 0;
-
- if ( -e "$configfilepath/livehosttable.db" ) {
- open INFILE, "<$configfilepath/livehosttable.db"
- or die "Can't open file $configfilepath/livehosttable.db $1";
- foreach $line (<INFILE>) {
- (
- $temphostname, $nullval, $nullval, $nullval, $nullval, $nullval,
- $nullval, $tempcommunity
- ) = split( /:/, $line );
- if ( $temphostname eq $requiredhostname ) {
- if ( $tempcommunity eq "" ) {
- $returncommunity = $defaultcommunity;
- }
- else {
- $returncommunity = $tempcommunity;
-
- # print "lookup for $temphostname successful: $tempcommunity\n";
- }
- last;
- }
- }
- }
- else {
- }
- close INFILE;
- return ($returncommunity);
-}