Title: [opsview] [11297] Updated check_snmp_apc_exttempprobe to use SNMPv3 library
- Revision
- 11297
- Author
- hstevenson
- Date
- 2013-01-31 11:41:01 +0000 (Thu, 31 Jan 2013)
Log Message
Updated check_snmp_apc_exttempprobe to use SNMPv3 library
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_apc_exttempprobe
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_apc_exttempprobe 2013-01-31 09:58:44 UTC (rev 11296)
+++ trunk/opsview-core/nagios-plugins/check_snmp_apc_exttempprobe 2013-01-31 11:41:01 UTC (rev 11297)
@@ -20,90 +20,49 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-use lib qw ( /usr/local/nagios/perl/lib );
+use strict;
+use warnings;
+
+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_apc_exttempprobe";
-$script_version = "2.1.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "check_snmp_apc_exttempprove",
+ version => "2.1.1",
+ blurb => "APC UPS external temperature probe reading",
+ snmp => { "snmp-version" => 1, },
+);
-$metric = 1;
-$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
+$np->add_arg(
+ spec => "warning|w=s",
+ help => qq{-w, --warning=INTEGER
+ Warning threshold (as %)},
+ default => 30,
+);
-$oid_base = ".1.3.6.1.4.1.16174.1.1.1.3.";
+$np->add_arg(
+ spec => "critical|c=s",
+ help => qq{-c, --critical=INTEGER
+ Critical threshold (as %)},
+ default => 40,
+);
-$oid_SensorTemp = "1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1";
+$np->getopts;
-$ipaddress = "192.168.10.30";
-$version = "1";
-$community = "public";
-$timeout = 2;
-$warning = 30;
-$critical = 40;
-$status = 0;
-$sensor = 1;
-$returnstring = "";
-my $port = 161;
+my $warning = $np->opts->warning;
+my $critical = $np->opts->critical;
-$configfilepath = "/usr/local/nagios/etc";
+my $oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
+my $oid_SensorTemp = "1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1";
-# Do we have enough information?
-if ( @ARGV < 1 ) {
- print "Too few arguments\n";
- usage();
-}
+my $status = 0;
+my $returnstring = "";
-getopts( "hH:C:n:w:c:p:" );
-if ($opt_h) {
- usage();
- exit(0);
-}
-if ($opt_H) {
- $hostname = $opt_H;
+my $s = $np->snmp;
- # print "Hostname $opt_H\n";
-}
-else {
- print "No hostname specified\n";
- usage();
-}
-if ($opt_C) {
- $community = $opt_C;
-
- # print "Using community $opt_C\n";
-}
-else {
-
- # print "Using community $community\n";
-}
-if ($opt_n) {
- $sensor = $opt_n;
-
- # print "Sensor number: $opt_n%\n";
-}
-if ($opt_w) {
- $warning = $opt_w;
-
- # print "Warning threshold: $opt_w%\n";
-}
-if ($opt_c) {
- $critical = $opt_c;
-
- # print "Critical threshold: $opt_c%\n";
-}
-if ($opt_p) {
- $port = $opt_p;
-}
-
-# Create the SNMP session
-my ( $s, $e ) = Net::SNMP->session(
- -community => $community,
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
-);
-
main();
# Close the session
@@ -136,7 +95,9 @@
sub main {
- $oid_RequiredSensorTemp = $oid_SensorTemp;
+ my $oid_RequiredSensorTemp = $oid_SensorTemp;
+ my $RequiredSensorTemp;
+ my $temp;
if ( !defined( $s->get_request($oid_RequiredSensorTemp) ) ) {
if ( !defined( $s->get_request($oid_sysDescr) ) ) {
$returnstring = "SNMP agent not responding";
@@ -167,40 +128,10 @@
}
####################################################################
-# help and usage information #
-####################################################################
-
-sub usage {
- print << "USAGE";
---------------------------------------------------------------------
-$script v$script_version
-
-APC UPS external temperature probe reading
-
-Usage: $script -H <hostname> -c <community> [...]
-Options: -H Hostname or IP address
- -p Port (default: 161)
- -C Community (default is public)
- -n Sensor number
- -w Warning threshold (as %)
- -c Critical threshold (as %)
-
---------------------------------------------------------------------
-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];
+ my $appendstring = $_[0];
$returnstring = "$returnstring$appendstring";
}
_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins