Title: [opsview] [11915] Updated check_snmp_vmware_gueststatus to use SNMPv3 library
- Revision
- 11915
- Author
- hstevenson
- Date
- 2013-03-22 12:36:32 +0000 (Fri, 22 Mar 2013)
Log Message
Updated check_snmp_vmware_gueststatus to use SNMPv3 library
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_vmware_gueststatus
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_vmware_gueststatus 2013-03-22 12:34:06 UTC (rev 11914)
+++ trunk/opsview-core/nagios-plugins/check_snmp_vmware_gueststatus 2013-03-22 12:36:32 UTC (rev 11915)
@@ -1,7 +1,7 @@
#!/usr/bin/perl
#
# AUTHORS:
-# Copyright (C) 2003-2013 Opsview Limited. All rights reserved
+# Copyright (C) 2003-2012 Opsview Limited. All rights reserved
#
# This file is part of Opsview
#
@@ -20,173 +20,58 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-use strict;
-use lib '/usr/local/nagios/perl/lib';
-use Storable qw(lock_store lock_retrieve);
+iuse 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_gueststate";
-my $script_version = "0.3";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "check_snmp_vmware_gueststate",
+ version => "0.4",
+ blurb => "Checks the power and OS status of guest VMs",
+ snmp => {
+ "snmp-version" => 2 c,
+ "snmp-timeout" => 5,
+ "v1-fallback" => 1,
+ },
+);
-my @hostnames;
+$np->add_arg(
+ spec => "warning|w=s",
+ help => qq{-w, --warning=INTEGER
+ Warning threshold for VMs powered on},
+ default => 0,
+);
-# SNMP variables
-my $oid_sysDescr =
- ".1.3.6.1.2.1.1.1.0"; # Used to check whether SNMP is actually responding
-my $oid_vmbase = ".1.3.6.1.4.1.6876.";
-my $oid_vm_name = "2.1.1.2.";
-my $oid_pwr_state = "2.1.1.6.";
-my $oid_os_state = "2.1.1.8.";
-my $oid_state = $oid_os_state;
-my $community = "public"; # Default community
-my $timeout = 5; # SNMP timeout
-my $retval = 3; # Innocent until proven guilty
-my $retmsg = ""; # Text to return from plugin
-my $version = "2c";
-my $mode = "specificvm";
-my $state_type = "h"; # p = power switch, otherwise host alive (vmtools)
-my $vm_name = "";
-my $runwarn = 0;
-my $runcrit = 0;
-my $pwrwarn = 0;
-my $pwrcrit = 0;
-my $hint_file = "/usr/local/nagios/var/plugins/vmware/";
-my $port = 161;
+$np->add_arg(
+ spec => "critical|c=s",
+ help => qq{-c, --critical=INTEGER
+ Critical threshold for VMs powered on},
+ default => 0,
+);
-our ( $s, $e );
+$np->add_arg(
+ spec => "runningcritical|d=s",
+ help => qq{-d, --runningcritical=INTEGER
+ Critical threshold for VMs running},
+ default => 0,
+);
-# Command line arguments
-our (
- $opt_h, $opt_H, $opt_C, $opt_t, $opt_n,
- $opt_p, $opt_w, $opt_c, $opt_x, $opt_d
+$np->add_arg(
+ spec => "runningwarning|x=s",
+ help => qq{-x, --runningwarning=INTEGER
+ Warning threshold for VMs running},
+ default => 0,
);
-getopts( "hH:c:t:n:pw:C:x:d:" );
-if ($opt_h) {
- usage();
- exit 0;
-}
-if ($opt_H) {
- @hostnames = split( ',', $opt_H );
-}
-else {
- print "No hostnames 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_n) {
- $vm_name = $opt_n;
- $hint_file = "${hint_file}esx_hint-${vm_name}.dat";
-}
-else {
- if ( @hostnames > 1 ) {
- print "Cannot specify more than one hostname unless you use -n\n";
- exit 3;
- }
- $mode = "aggregate";
-}
-if ($opt_p) {
- $state_type = "p";
- $oid_state = $oid_pwr_state;
-}
-if ($opt_p) {
- $port = $opt_p;
-}
+$np->getopts;
-# Thresholds
-if ($opt_w) {
- if ( $opt_w =~ /^\d+$/ ) {
- $runwarn = $opt_w;
- }
- else {
- print "Warning values must be integers\n";
- exit 3;
- }
-}
-if ($opt_c) {
- if ( $opt_c =~ /^\d+$/ ) {
- $runcrit = $opt_c;
- }
- else {
- print "Critical values must be integers\n";
- exit 3;
- }
-}
-if ($opt_x) {
- if ( $opt_x =~ /^\d+$/ ) {
- $pwrwarn = $opt_x;
- }
- else {
- print "Warning values must be integers\n";
- exit 3;
- }
-}
-if ($opt_d) {
- if ( $opt_d =~ /^\d+$/ ) {
- $pwrcrit = $opt_d;
- }
- else {
- print "Critical values must be integers\n";
- exit 3;
- }
-}
+my $warning = $np->opts->warning;
+my $critical = $np->opts->critical;
-# Our hint file is found in here
-if ( !-d $hint_file ) {
- mkdir $hint_file
- or die( "Cannot create temporary data store directory $hint_file" );
-}
+my $s = $np->snmp;
-sub usage {
- print <<EOF
---------------------------------------------------------------------
-$script $script_version
-
-Checks the power and OS status of guest VMs
-
-Usage: $script -H <hostnames> -C <community> [...]
-
-Options: -H Comma separated list of hostnames or IP addresses
- of the VMware ESX hosts on which the VM could be
- found.
- -p Port (default: 161)
- -C SNMP community string
- -t SNMP timeout (in seconds)
- -n Guest name to check state for. If you omit
- this option, the check will provide a summary
- instead.
- -p Check power switch state, not OS state
- -w Warning threshold for VMs powered on
- -c Critical threshold for VMs powered on
- -x Warning threshold for VMs running
- -d Critical threshold for VMs running
-
-Note: 'Powered on' refers to the power 'switch' state in VMware
- 'Running' refers to the OS (VMware tools) state
-
---------------------------------------------------------------------
-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 );
_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins