Title: [opsview] [11918] Updated check_snmp_vmware_vmkernel to use SNMPv3 library
Revision
11918
Author
hstevenson
Date
2013-03-22 12:38:24 +0000 (Fri, 22 Mar 2013)

Log Message

Updated check_snmp_vmware_vmkernel to use SNMPv3 library

Modified Paths


Modified: trunk/opsview-core/nagios-plugins/check_snmp_vmware_vmkernel
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_vmware_vmkernel	2013-03-22 12:37:53 UTC (rev 11917)
+++ trunk/opsview-core/nagios-plugins/check_snmp_vmware_vmkernel	2013-03-22 12:38:24 UTC (rev 11918)
@@ -20,86 +20,34 @@
 #    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 lib qw ( /usr/local/nagios/perl/lib );
-use lib qw ( /usr/local/nagios/perl/lib );
+use warnings;
+
+use FindBin qw($Bin);
+use lib "/opt/opsview/perl/lib/perl5", "$Bin/../lib";
 use Net::SNMP;
-use Getopt::Std;
+use Opsview::NagiosPlugin::SNMP;
 
-# About us
-my $script         = "check_snmp_vmware_vmkernel";
-my $script_version = "0.1";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+    usage     => "Usage: %s",
+    shortname => "check_snmp_vmware_vmkernel",
+    version   => "0.2",
+    blurb     => "Checks whether or not the ESX VM Kernel is loaded",
+    snmp      => {
+        "snmp-version" => "2c",
+        "snmp-timeout" => 10,
+        "v1-fallback"  => 1,
+    },
+);
 
-my $hostname = '';
+$np->getopts;
 
-# SNMP variables
-my $oid_sysDescr =
-  ".1.3.6.1.2.1.1.1.0"; # Used to check whether SNMP is actually responding
+my $oid_sysDescr       = ".1.3.6.1.2.1.1.1.0";
 my $oid_vmkernelstatus = ".1.3.6.1.4.1.6876.4.1.1.1.0";
-my $community          = "public";                     # Default community
-my $timeout            = 10;                           # SNMP timeout
-my $retval  = 3;   # Innocent until proven guilty
-my $version = "2c";
-my $port    = 161;
+my $retval             = 3;
 
-our ( $s, $e );
+my $s = $np->snmp;
 
-# Command line arguments
-our ( $opt_h, $opt_H, $opt_C, $opt_t, $opt_p );
-getopts( "hH:C:t:p:" );
-if ($opt_h) {
-    usage();
-    exit 0;
-}
-if ($opt_H) {
-    $hostname = $opt_H;
-}
-else {
-    print "No hostname specified\n";
-    usage();
-    exit 3;
-}
-if ($opt_C) {
-    $community = $opt_C;
-}
-if ($opt_t) {
-
-    # Validity test - must be numeric
-    unless ( $opt_t =~ /^[0-9]+$/ ) {
-        print "Specify time in seconds - $opt_t is not a valid integer\n";
-        exit 3;
-    }
-    $timeout = $opt_t;
-}
-if ($opt_p) {
-    $port = $opt_p;
-}
-
-sub usage {
-    print <<EOF
---------------------------------------------------------------------
-$script $script_version
-
-Checks whether or not the ESX VM Kernel is loaded
-
-Usage: $script -H <hostname> -c <community> [-t <timeout>]
-
-Options: -H     Hostname or IP address
-         -p     Port (default:161)
-         -c     SNMP community string
-         -t     SNMP timeout (in seconds)
-
---------------------------------------------------------------------     
-Copyright (C) 2003-2013 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
-------------------------------------------------------------------
-EOF
-
-}
-
 # Call this when you know you'll get a single value back
 sub get_oid_value {
     our ( $oid, $result, $status, $returnstring );
@@ -124,50 +72,11 @@
     return $result;
 }
 
-# Create the SNMP session
-$version = "2c";
-( $s, $e ) = Net::SNMP->session(
-    -community => $community,
-    -hostname  => $hostname,
-    -version   => $version,
-    -timeout   => $timeout,
-    -port      => $port,
-);
-
 if ( !defined( $s->get_request($oid_sysDescr) ) ) {
-
-    # If we can't connect using SNMPv1 lets try as SNMPv2
-    $s->close();
-    sleep 0.5;
-    $version = "1";
-    ( $s, $e ) = Net::SNMP->session(
-        -community => $community,
-        -hostname  => $hostname,
-        -version   => $version,
-        -timeout   => $timeout,
-        -port      => $port,
-    );
-    if ( !defined( $s->get_request($oid_sysDescr) ) ) {
-        print "Agent not responding, tried SNMP v1 and v2\n";
-        exit 3;
-    }
-}
-
-# Check for an SNMP error first...
-if ( $s->error ) {
-    print "UNKNOWN - " . $s->error . "|\n";
+    print "SNMP agent not responding\n";
     exit 3;
 }
 
-#set the session size to be bigger
-$s->max_msg_size(65535);
-
-# Check for an SNMP error first...
-if ( $s->error ) {
-    print "UNKNOWN - " . $s->error . "|\n";
-    exit 3;
-}
-
 # Check what the value is
 if ( get_oid_value($oid_vmkernelstatus) eq "yes" ) {
     $retval = 0;

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

Reply via email to