Modified: trunk/opsview-core/nagios-plugins/check_snmp_template
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_template 2010-11-05 12:12:31 UTC (rev 5320)
+++ trunk/opsview-core/nagios-plugins/check_snmp_template 2010-11-05 14:14:49 UTC (rev 5321)
@@ -42,11 +42,10 @@
my $VERSION = "0.01";
my $np = Nagios::Plugin->new(
- usage => "Usage: %s [-v] [-h] -H <hostname> [-c <community>]\n Check for '$check'",
+ usage => "Usage: %s [-v] [-h] -H <hostname> [ -v <version> ] [-C <community>]\n Check for '$check'",
shortname => "STATUS",
license => "Copyright (C) 2003-2010 Opsera Limited. All rights reserved",
version => $VERSION,
- extra => "\nWill automatically try SNMP version 1 and 2c",
);
$np->add_arg(
@@ -56,8 +55,8 @@
);
$np->add_arg(
- spec => "community|c=s",
- help => "--community, -c <string>\n Community string (default: public)",
+ spec => "community|C=s",
+ help => "--community, -C <string>\n Community string (default: public)",
default => "public",
);
@@ -68,8 +67,10 @@
);
$np->add_arg(
- spec => "server|s=s",
- help => "--server, -s <server_name>\n Server name",
+ spec => "version|v=s",
+ help => "--version, -v <version>\n SNMP version, either 1 or 2c (default 1)",
+ default => "1",
+
);
$np->getopts;
@@ -78,36 +79,19 @@
alarm $np->opts->timeout;
my $community = $np->opts->community;
-$community = $np->opts->server . '@' . $community if ( $np->opts->server );
-my $version = "1";
my ( $session, $error ) = Net::SNMP->session(
-community => $community,
-hostname => $np->opts->hostname,
- -version => $version,
- -timeout => 2,
+ -version => $np->opts->version,
+ -timeout => $np->opts->timeout - 1 || 1,
-port => $np->opts->port,
);
my $result = $session->get_request( -varbindlist => [ $test_oid, $check_oid ], );
if ( !defined($result) ) {
- $session->close;
- sleep 0.5;
- $version = "2c";
- ( $session, $error ) = Net::SNMP->session(
- -community => $community,
- -hostname => $np->opts->hostname,
- -version => $version,
- -timeout => 2,
- -port => $np->opts->port,
- );
-
- $result = $session->get_request( -varbindlist => [ $test_oid, $check_oid ], );
-
- if ( !defined($result) ) {
- $np->nagios_exit( 3, "Agent not responding, tried SNMP v1 and v2" );
- }
+ $np->nagios_exit( 3, "Agent not responding" );
}
if ( !defined( $result->{$check_oid} ) ) {