check_snmp_storage: Add 64bit support

This commit is contained in:
Jan Wagner 2014-01-18 00:19:18 +01:00
parent baa90eb96d
commit 258eb2eb89
2 changed files with 169 additions and 0 deletions

View file

@ -5,4 +5,5 @@
05_check_snmp_storage.dpatch
06_check_snmp_win.dpatch
10_fix_net_snmp_version.dpatch
15_check_snmp_storage_64bit.dpatch
50_disable_epn.dpatch

View file

@ -0,0 +1,168 @@
#! /bin/sh /usr/share/dpatch/dpatch-run
## 15_check_snmp_storage_64bit by Martin Fürstenau
##
## DP: Fixing Net::SNMP version
## DP: (see https://wiki.icinga.org/display/howtos/check_snmp#checksnmp-Argumentv601isntnumericinnumericlt)
## @DPATCH@
## From 144c57a0adda190000bef500f3274425cb90d6ba Mon Sep 17 00:00:00 2001
## From: Michael Friedrich <michael.friedrich@gmail.com>
## Date: Wed, 26 Sep 2012 16:32:40 +0200
## Subject: [PATCH] =?UTF-8?q?apply=20check=5Fsnmp=5Fstorage=20patch=20and=20?=
## =?UTF-8?q?1.3.3=20from=20Martin=20F=C3=BCrstenau?=
## MIME-Version: 1.0
## Content-Type: text/plain; charset=UTF-8
## Content-Transfer-Encoding: 8bit
##
## http://www.monitoring-portal.org/wbb/index.php?page=Thread&threadID=12031
---
plugins/check_snmp_storage.pl | 54 ++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 18 deletions(-)
@DPATCH@
diff --git a/plugins/check_snmp_storage.pl b/plugins/check_snmp_storage.pl
index 1b8a398..a3c784f 100644
--- a/plugins/check_snmp_storage.pl
+++ b/plugins/check_snmp_storage.pl
@@ -6,7 +6,7 @@
# Help : http://nagios.manubulon.com
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO :
-# Contribs : Dimo Velev, Makina Corpus, A. Greiner-Bär
+# Contribs : Dimo Velev, Makina Corpus, A. Greiner-B\ufffdr
#################################################################
#
# help : ./check_snmp_storage -h
@@ -80,7 +80,7 @@
my $o_perf= undef; # Output performance data
my $o_short= undef; # Short output parameters
my @o_shortL= undef; # output type,where,cut
-my $o_reserve= 0; # % reserved blocks (A. Greiner-Bär patch)
+my $o_reserve= 0; # % reserved blocks (A. Greiner-B\ufffdr patch)
my $o_giga= undef; # output and levels in gigabytes instead of megabytes
# SNMPv3 specific
my $o_login= undef; # Login for snmpv3
@@ -89,6 +89,7 @@
my $o_authproto='md5'; # Auth protocol
my $o_privproto='des'; # Priv protocol
my $o_privpass= undef; # priv password
+my $UOM_float= 4; # decimal places
# SNMP Message size parameter (Makina Corpus contrib)
my $o_octetlength=undef;
@@ -112,8 +113,10 @@ sub is_pattern_valid { # Test for things like "<I\s*[^>" or "+5-i"
# Get the alarm signal (just in case snmp timout screws up)
$SIG{'ALRM'} = sub {
- print ("ERROR: General time-out (Alarm signal)\n");
- exit $ERRORS{"UNKNOWN"};
+# print ("ERROR: General time-out (Alarm signal)\n");
+# exit $ERRORS{"UNKNOWN"};
+ print ("Waiting for info\n");
+ exit $ERRORS{"OK"};
};
sub isnnum { # Return true if arg is not a number
@@ -315,7 +318,7 @@ sub check_options {
if (defined ($o_octetlength) && (isnnum($o_octetlength) || $o_octetlength > 65535 || $o_octetlength < 484 )) {
print "octet lenght must be < 65535 and > 484\n";print_usage(); exit $ERRORS{"UNKNOWN"};
}
- #### reserved blocks checks (A. Greiner-Bär patch).
+ #### reserved blocks checks (A. Greiner-B\ufffdr patch).
if (defined ($o_reserve) && (isnnum($o_reserve) || $o_reserve > 99 || $o_reserve < 0 )) {
print "reserved blocks must be < 100 and >= 0\n";print_usage(); exit $ERRORS{"UNKNOWN"};
}
@@ -348,6 +351,7 @@ sub check_options {
-authpassword => $o_passwd,
-authprotocol => $o_authproto,
-port => $o_port,
+ -retries => 10,
-timeout => $o_timeout
);
} else {
@@ -361,6 +365,7 @@ sub check_options {
-privpassword => $o_privpass,
-privprotocol => $o_privproto,
-port => $o_port,
+ -retries => 10,
-timeout => $o_timeout
);
}
@@ -373,6 +378,7 @@ sub check_options {
-version => 2,
-community => $o_community,
-port => $o_port,
+ -retries => 10,
-timeout => $o_timeout
);
} else {
@@ -382,6 +388,7 @@ sub check_options {
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
+ -retries => 10,
-timeout => $o_timeout
);
}
@@ -491,18 +498,28 @@ sub check_options {
my $result=undef;
-if (Net::SNMP->VERSION lt 4) {
- $result = $session->get_request(@oids);
-} else {
- if ($session->version == 0) {
- # snmpv1
- $result = $session->get_request(Varbindlist => \@oids);
- } else {
- # snmp v2c or v3 : get_bulk_request is not really good for this, so do simple get
- $result = $session->get_request(Varbindlist => \@oids);
- foreach my $key ( keys %$result) { verb("$key : $$result{$key}"); }
- }
-}
+if (Net::SNMP->VERSION lt 4)
+ {
+ $result = $session->get_request(@oids);
+ }
+else
+ {
+ $result = $session->get_request(Varbindlist => \@oids);
+ foreach my $key ( keys %$result)
+ {
+ # Fix for filesystems larger 2 TB. More than 2 TB will cause an error because
+ # as defined in the RFC hrStorageSize is a 32 bit integer. So filesystems
+ # larger 2 TB report a negative value because the first bit will be interpreted
+ # as an algebraic sign. (0 = +, all others will be -). You simply have to add
+ # 2 to the power of 32 (4294967296) and it is fixed.
+ # Martin Fuerstenau, Oce Printing Systems, 25th Sept 2012
+ if ($$result{$key} < 0)
+ {
+ $$result{$key} = $$result{$key} + 4294967296;
+ }
+ verb("$key x $$result{$key}");
+ }
+ }
if (!defined($result)) { printf("ERROR: Size table :%s.\n", $session->error); $session->close;
exit $ERRORS{"UNKNOWN"};
@@ -547,6 +564,7 @@ sub check_options {
verb("Size : $$result{$size_table . $tindex[$i]}");
verb("Used : $$result{$used_table . $tindex[$i]}");
verb("Alloc : $$result{$alloc_units . $tindex[$i]}");
+
if (!defined($$result{$size_table . $tindex[$i]}) ||
!defined($$result{$used_table . $tindex[$i]}) ||
!defined ($$result{$alloc_units . $tindex[$i]})) {
@@ -623,7 +641,7 @@ sub check_options {
}
}
# Performance output (in MB)
- $perf_out .= "'".$Pdescr. "'=" . round($bu,0) . $output_metric ."B;" . round($p_warn,0)
+ $perf_out .= "'".$Pdescr. "'=" . round($bu,$UOM_float) . $output_metric ."B;" . round($p_warn,0)
. ";" . round($p_crit,0) . ";0;" . round($to,0);
}
--
1.8.5.1