Title: [opsview] [11389] Updated check_snmp_weblogic_deploymentstatus to use SNMPv3 library
- Revision
- 11389
- Author
- hstevenson
- Date
- 2013-02-08 13:49:03 +0000 (Fri, 08 Feb 2013)
Log Message
Updated check_snmp_weblogic_deploymentstatus to use SNMPv3 library
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_weblogic_deploymentstatus
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_weblogic_deploymentstatus 2013-02-08 12:14:32 UTC (rev 11388)
+++ trunk/opsview-core/nagios-plugins/check_snmp_weblogic_deploymentstatus 2013-02-08 13:49:03 UTC (rev 11389)
@@ -20,101 +20,59 @@
# 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 warnings;
+
+use FindBin qw($Bin);
+use lib "/opt/opsview/perl/lib/perl5", "$Bin/../lib";
use Net::SNMP;
-use DBI;
-use Getopt::Std;
+use Opsview::NagiosPlugin::SNMP;
-# About us
-my $script = "check_snmp_weblogic_deploymentstatus";
-my $script_version = "0.1";
-my $script_description =
- "Checks deployment status of weblogic application servers";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "check_snmp_weblogic_deploymentstatus",
+ version => "0.2",
+ blurb => "Checks deployment status of weblogic application servers",
+ snmp => { "snmp-version" => 1, },
+);
-my $hostname;
+$np->add_arg(
+ spec => "list|L=s",
+ help => qq{-L, --list=INTEGER
+ Lists available servers},
+);
-# Performance data
-my $perfdata = "";
+$np->add_arg(
+ spec => "server|S=s",
+ help => qq{-S, --server=STRING
+ Server name},
+);
-# SNMP variables
-my $oid_testoid =
- ".1.3.6.1.4.1.140.625.10.1.0"; # Used to check whether SNMP is responding
-my $webServerName_base_oid = ".1.3.6.1.4.1.140.625.430.1.25.32";
-my $is_deployed_oid = ".1.3.6.1.4.1.140.625.430.1.30.32";
-my $is_deployed;
-my $community = "public"; # Default community
-my $timeout = 2; # SNMP timeout
-my $retval = 0; # Innocent until proven guilty
-my $retmsg = ""; # Text to return from plugin
-my $uptime = 0;
-my $version = "2c";
+$np->getopts;
+
my $list_servers = 0;
my $server_name;
-my $server_oid;
-my $port = 161;
-our ( $s, $e );
-# Command line arguments
-our ( $opt_h, $opt_H, $opt_c, $opt_L, $opt_S, $opt_p );
-getopts( "hH:c:LS: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_L) {
+if ( $np->opts->list ) {
$list_servers = 1;
}
-elsif ($opt_S) {
- $server_name = $opt_S;
+elsif ( $np->opts->server ) {
+ $server_name = $np->opts->server;
}
else {
- print "Must specify server name.\n";
- usage();
+ print "Must specify a server name.\n";
exit 1;
}
-if ($opt_p) {
- $port = $opt_p;
-}
-sub usage {
- print <<EOF
---------------------------------------------------------------------
+my $s = $np->snmp;
-$script $script_version
+my $oid_testoid = ".1.3.6.1.4.1.140.625.10.1.0";
+my $webServerName_base_oid = ".1.3.6.1.4.1.140.625.430.1.25.32";
+my $is_deployed_oid = ".1.3.6.1.4.1.140.625.430.1.30.32";
-$script_description
+my $server_oid;
+my $is_deployed;
-Usage: $script -H <hostname> -c <community> [-L|...]
-
-Options: -H Hostname or IP address
- -p Port (default: 161)
- -c Community (default is public)
- -L Lists available servers
- -S Server name
-
---------------------------------------------------------------------
-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
-------------------------------------------------------------------
-EOF
-
-}
-
# Call this when you know you'll get a single value back
sub get_oid_value {
our ( $oid, $result, $status, $returnstring );
@@ -141,31 +99,10 @@
return $result;
}
-# Create the SNMP session
-$version = "1";
-( $s, $e ) = Net::SNMP->session(
- -community => $community,
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
-);
-
if ( !defined( $s->get_request($oid_testoid) ) ) {
- # If we can't connect using SNMPv1 lets try as SNMPv2
- $s->close();
- sleep 0.5;
- $version = "2c";
- ( $s, $e ) = Net::SNMP->session(
- -community => $community,
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
- );
if ( !defined( $s->get_request($oid_testoid) ) ) {
- print "Agent not responding, tried SNMP v1 and v2\n";
+ print "Agent not responding\n";
exit 1;
}
}
_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins