Title: [opsview] [11409] Updated check_snmp_weblogic_jmsmsgbridge to use SNMPv3 library
- Revision
- 11409
- Author
- hstevenson
- Date
- 2013-02-12 10:14:28 +0000 (Tue, 12 Feb 2013)
Log Message
Updated check_snmp_weblogic_jmsmsgbridge to use SNMPv3 library
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_weblogic_jmsmsgbridge
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_weblogic_jmsmsgbridge 2013-02-12 10:13:58 UTC (rev 11408)
+++ trunk/opsview-core/nagios-plugins/check_snmp_weblogic_jmsmsgbridge 2013-02-12 10:14:28 UTC (rev 11409)
@@ -19,115 +19,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 FindBin qw($Bin $Script);
-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 Storable qw(lock_store lock_retrieve);
-use File::Path;
+use Opsview::NagiosPlugin::SNMP;
-# About us
-my $script = "check_snmp_weblogic_jmsmsgbridge";
-my $script_version = "1.0";
-my $script_description = "Checks state of JMS Messaging Bridge";
-my $store_dir = "$Bin/../var/plugins/${Script}";
-my $store;
-my $max_use = 10 + int( rand(10) ); # random number between 10 and 20
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "check_snmp_weblogic_jmsmsgbridge",
+ version => "1.1",
+ blurb => "Checks state of JMS Messaging Bridge",
+ snmp => {
+ "snmp-version" => 2,
+ "v1-fallback" => 1,
+ },
+);
-if ( !-d $store_dir ) {
- mkpath($store_dir) || die "Unable to create $store_dir directory: $!", $/;
-}
+$np->add_arg(
+ spec => "bridge|b=s",
+ help => qq{-b, --bridge=INTEGER
+ Bridge name},
+ required => 1,
+);
-my $hostname;
+$np->getopts;
-# Performance data
-my $perfdata = "";
+my $bridge_name = $np->opts->bridge;
-# SNMP variables
-my $oid_testoid =
- ".1.3.6.1.4.1.140.625.10.1.0"; # Used to check whether SNMP is responding
+my $oid_testoid = ".1.3.6.1.4.1.140.625.10.1.0";
my $msgbridgename_base_oid = ".1.3.6.1.4.1.140.625.354.1.15";
my $bridge_state_oid = ".1.3.6.1.4.1.140.625.354.1.21";
my $bridge_error_oid = ".1.3.6.1.4.1.140.625.354.1.22";
-my $is_active;
-my $community = "public"; # Default community
-my $timeout = 10; # SNMP timeout
-my $retval = 0; # Innocent until proven guilty
-my $retmsg = ""; # Text to return from plugin
-my $uptime = 0;
-my $version = "2c";
-my $bridge_name;
+
+my $perfdata = "";
+my $store;
my $bridge_oid;
-my $port = 161;
-our ( $s, $e );
+my $max_use = 10 + int( rand(10) );
+my $is_active;
-# Command line arguments
-our ( $opt_h, $opt_H, $opt_C, $opt_b, $opt_p );
-getopts( "hH:C:b: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_b) {
- $bridge_name = $opt_b;
-}
-else {
- print "Must specify bridge name with -b\n";
- usage();
- exit 1;
-}
-if ($opt_p) {
- $port = $opt_p;
-}
+my $s = $np->snmp;
-sub usage {
- print <<EOF
---------------------------------------------------------------------
-
-$script $script_version
-
-$script_description
-
-Usage: $script -H <hostname> -C <community> [-L|...]
-
-Options: -H Hostname or IP address
- -p Port (default: 161)
- -C Community (default is public), you will
- probably need to use public\@servername
- -b Bridge 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
-
-}
-
-my $store_file = $store_dir . "/${opt_H}_${opt_b}.dat";
-
-if ( -f $store_file ) {
-
- # if lock_retrieve fails, file is corrupt - just carry on with empty store
- eval { $store = lock_retrieve($store_file); };
-}
-
# Call this when you know you'll get a single value back
sub get_oid_value {
our ( $oid, $result, $status, $returnstring );
@@ -154,29 +88,7 @@
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";
exit 1;
@@ -230,8 +142,6 @@
$store->{$bridge_name}->{max_use} = $max_use;
}
-lock_store( $store, $store_file );
-
$is_active = get_oid_value( "$bridge_state_oid$bridge_oid" );
# Show appropriate message (we don't have a critical state)
_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins