Title: [opsview] [11366] Updated check_snmp_netscaler_clientconnections to use SNMPv3 library
Revision
11366
Author
hstevenson
Date
2013-02-06 14:36:29 +0000 (Wed, 06 Feb 2013)

Log Message

Updated check_snmp_netscaler_clientconnections to use SNMPv3 library

Modified Paths


Modified: trunk/opsview-core/nagios-plugins/check_snmp_netscaler_clientconnections
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_netscaler_clientconnections	2013-02-06 13:56:18 UTC (rev 11365)
+++ trunk/opsview-core/nagios-plugins/check_snmp_netscaler_clientconnections	2013-02-06 14:36:29 UTC (rev 11366)
@@ -20,86 +20,49 @@
 #    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;
 
-$script         = "check_snmp_netscaler_clientconnections";
-$script_version = "2.1.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+    usage     => "Usage: %s",
+    shortname => "check_snmp_netscaler_clientconnections",
+    version   => "2.1.1",
+    blurb     => "Returns Netscaler client connections",
+    snmp      => { "snmp-version" => 1, },
+);
 
-$metric = 1;
+$np->add_arg(
+    spec => "warning|w=s",
+    help => qq{-w, --warning=INTEGER
+    Warning threshold},
+    default => 80,
+);
 
-# Netscaler root OID= 1.3.6.1.4.1.5951
+$np->add_arg(
+    spec => "critical|c=s",
+    help => qq{-c, --critical=INTEGER
+    Critical threshold},
+    default => 90,
+);
 
-$oid_sysDescr          = ".1.3.6.1.2.1.1.1.0";
-$oid_clientconnections = ".1.3.6.1.4.1.5951.4.1.1.46.2.0";
+$np->getopts;
 
-$ipaddress    = "192.168.1.1"; # Default IP address
-$version      = "1";           # SNMP version
-$community    = "public";
-$timeout      = 2;             # Response timeout (seconds)
-$warning      = 80;
-$critical     = 90;
-$status       = 0;
-$returnstring = "";
-my $port = 161;
+my $warning  = $np->opts->warning;
+my $critical = $np->opts->critical;
 
-$defaultcommunity = "public";               # Default community string
-$configfilepath   = "/usr/local/nagios/etc";
+my $s = $np->snmp;
 
-# Do we have enough information?
-if ( @ARGV < 1 ) {
-    print "Too few arguments\n";
-    usage();
-}
+my $oid_sysDescr          = ".1.3.6.1.2.1.1.1.0";
+my $oid_clientconnections = ".1.3.6.1.4.1.5951.4.1.1.46.2.0";
 
-getopts( "hH:C:w:c:p:" );
-if ($opt_h) {
-    usage();
-    exit(0);
-}
-if ($opt_H) {
-    $hostname = $opt_H;
+my $status       = 0;
+my $returnstring = "";
 
-    # 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;
-}
-
-# 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
@@ -132,6 +95,9 @@
 
 sub main {
 
+    my $clientconnections;
+    my $temp;
+
     if ( !defined( $s->get_request($oid_clientconnections) ) ) {
         if ( !defined( $s->get_request($oid_sysDescr) ) ) {
             $returnstring = "SNMP agent not responding";
@@ -162,79 +128,11 @@
 }
 
 ####################################################################
-# help and usage information                                       #
-####################################################################
-
-sub usage {
-    print << "USAGE";
---------------------------------------------------------------------	 
-$script v$script_version
-
-Returns Netscaler client 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
-         -c 		Critical threshold
-	 
---------------------------------------------------------------------	 
-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;
-}
-
-####################################################################
 # Appends string to existing $returnstring                         #
 ####################################################################
 
 sub append {
-    my $appendstring = @_[0];
+    my $appendstring = $_[0];
     $returnstring = "$returnstring$appendstring";
 }
 
-####################################################################
-# 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);
-}

_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to