Title: [opsview] [10988] Updated to new SNMP framework
- Revision
- 10988
- Author
- tvoon
- Date
- 2012-12-13 14:22:13 +0000 (Thu, 13 Dec 2012)
Log Message
Updated to new SNMP framework
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_cisco_css_master
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_cisco_css_master 2012-12-13 14:08:54 UTC (rev 10987)
+++ trunk/opsview-core/nagios-plugins/check_snmp_cisco_css_master 2012-12-13 14:22:13 UTC (rev 10988)
@@ -20,136 +20,36 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-use lib qw ( /usr/local/nagios/perl/lib );
+use warnings;
+use strict;
+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_cisco_css_master";
-$script_version = "1.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "CSS_MASTER",
+ version => "2.0",
+ blurb => "Checks whether CSS is master",
+ snmp => {
+ "snmp-version" => "1",
+ "snmp-timeout" => 2,
+ "v1-fallback" => 1,
+ },
+);
-$metric = 1;
-$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
+$np->getopts;
-$oid_HAStatus = ".1.3.6.1.4.1.9.9.368.1.9.8.3.1.4";
+my $oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
-$ipaddress = "192.168.10.30";
-$version = "1";
-$snmpv3_username = "initial"; # SNMPv3 username
-$snmpv3_password = ""; # SNMPv3 password
-$snmpv3_authprotocol = "md5"; # SNMPv3 hash algorithm (md5 / sha)
-$snmpv3_privprotocol = "des"; # SNMPv3 encryption protocol (des / aes / aes128)
-$community = "public"; # Default community string (for SNMP v1 / v2c)
-$timeout = 2;
-$warning = 90;
-$critical = 95;
-$status = 0;
-$returnstring = "";
-my $port = 161;
+my $oid_HAStatus = ".1.3.6.1.4.1.9.9.368.1.9.8.3.1.4";
-$community = "public"; # Default community string
-$configfilepath = "/usr/local/nagios/etc";
+my $status = 0;
+my $returnstring = "";
-# Do we have enough information?
-if ( @ARGV < 1 ) {
- print "Too few arguments\n";
- usage();
-}
+my $s = $np->snmp;
-getopts( "hH:C:U:P:v:a:e:p:" );
-if ($opt_h) {
- usage();
- exit(0);
-}
-if ($opt_H) {
- $hostname = $opt_H;
-}
-else {
- print "No hostname specified\n";
- usage();
-}
-if ($opt_C) {
- $community = $opt_C;
-}
-if ($opt_U) {
- $snmpv3_username = $opt_U;
-}
-if ($opt_P) {
- $snmpv3_password = $opt_P;
-}
-if ($opt_a) {
- $snmpv3_authprotocol = $opt_a;
-}
-if ($opt_e) {
- $snmpv3_privprotocol = $opt_e;
-}
-if ($opt_v) {
- $version = $opt_v;
-}
-if ($opt_p) {
- $port = $opt_p;
-}
-
-# Checks whether requested SNMP version is supported
-if ( $version !~ /^[13]|[2c]$/ ) {
- print "SNMP v$version not supported by this plugin\n";
- exit(1);
-}
-
-# Create the SNMP session
-if ( $version == "3" ) {
- ( $s, $e ) = Net::SNMP->session(
- -username => $snmpv3_username,
- -authpassword => $snmpv3_password,
- -authprotocol => $snmpv3_authprotocol,
- -privprotocol => $snmpv3_privprotocol,
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
- );
- if ($s) {
- }
- else {
- print "Agent not responding, tried SNMP v3 ($e)\n";
- exit(1);
- }
-}
-
-my $triedv2c = 0; # Track whether we've attempted SNMPv2c connection
-if ( $version == "2c" ) {
- ( $s, $e ) = Net::SNMP->session(
- -community => $community,
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
- );
- if ( !defined( $s->get_request($oid_sysDescr) ) ) {
-
- # try SNMP v1 if v2c doesn't work
- $triedv2c = 1;
- $version = 1;
- }
-}
-
-if ( $version == "1" ) {
- ( $s, $e ) = Net::SNMP->session(
- -community => $community,
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- );
- if ( !defined( $s->get_request($oid_sysDescr) ) ) {
- if ( $triedv2c == 1 ) {
- print "Agent not responding, tried SNMP v1 and v2c\n";
- }
- else {
- print "Agent not responding, tried SNMP v1\n";
- }
- exit(1);
- }
-}
-
$status = main();
# Close the session
@@ -194,6 +94,8 @@
return 1;
}
}
+
+ my $HAStatus;
foreach ( $s->var_bind_names() ) {
$HAStatus = $s->var_bind_list()->{$_};
}
@@ -222,45 +124,8 @@
}
-####################################################################
-# help and usage information #
-####################################################################
-
-sub usage {
- print << "USAGE";
---------------------------------------------------------------------
-$script v$script_version
-
-Checks whether CSS is master
-
-Usage: $script -H <hostname> -c <community>
-Options:
- -H Hostname or IP address
- -p Port (default:161)
- -C Community (default: public)
-
---------------------------------------------------------------------
-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];
- $returnstring = "$returnstring$appendstring";
-}
-
sub translatestatuscode {
- my $value = @_[0];
+ my $value = $_[0];
my $returnstring = "";
if ( $value eq "1" ) {
@@ -275,5 +140,8 @@
elsif ( $value eq "4" ) {
$returnstring = "master";
}
+ else {
+ $returnstring = "Unknown for value '$value'";
+ }
return ($returnstring);
}
_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins