Adding patchtes/21_check_snmp_load_abstract_snmp_version_check

Via 846165c880.patch
This commit is contained in:
Jan Wagner 2015-10-02 09:48:10 +02:00
parent bcecc23a6f
commit a8f8669e82
2 changed files with 122 additions and 0 deletions

View file

@ -0,0 +1,121 @@
From 846165c880793a97a2e727f4d13e23df40e8f1a4 Mon Sep 17 00:00:00 2001
From: morgajel <morgajel@gmail.com>
Date: Wed, 13 May 2015 12:33:21 -0400
Subject: [PATCH] Abstracted snmp version check to circumvent error and bug
There are two issues:
1) Net::SNMP changed it's VERSION to be a quoted string rather than a bare mess. This caused
Argument "v6.0.1" isn't numeric in numeric lt (<) at /opt/manubulon/plugins/check_snmp_load.pl line 368.
2) the rest of the file used lt rather than <, which means they were using ascii sorting rather than digit comparison
Both of these issues have now been resolved; This fix has only been applied to this one script, but it may
need to be implemented in the other scripts.
---
check_snmp_load.pl | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/check_snmp_load.pl b/check_snmp_load.pl
index c8661aa..751c6ec 100755
--- a/check_snmp_load.pl
+++ b/check_snmp_load.pl
@@ -280,6 +280,18 @@ sub check_options {
}
}
+# This is required to get around all of the silly historical methods of
+# versioning with Net::SNMP.
+sub is_legacy_snmp_version {
+ my $version=Net::SNMP->VERSION; #using a variable for easier testing
+ if ($version=~/^\D*(\d)/ and $1 < 4){
+ print "$1 wee";
+ return 1;
+ }else{
+ return 0;
+ }
+}
+
########## MAIN #######
check_options();
@@ -365,7 +377,7 @@ sub check_options {
verb("Checking linux load");
# Get number of CPUs
-my $resultat = (Net::SNMP->VERSION < 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_table($proc_id)
: $session->get_table(Baseoid => $proc_id);
@@ -378,7 +390,7 @@ sub check_options {
my $ncpu = keys %$resultat;
# Get load table
-$resultat = (Net::SNMP->VERSION lt 4) ?
+$resultat = (is_legacy_snmp_version()) ?
$session->get_table($linload_table)
: $session->get_table(Baseoid => $linload_table);
@@ -445,7 +457,7 @@ sub check_options {
if ($o_check_type eq "cisco") {
my @oidlists = ($cisco_cpu_5m, $cisco_cpu_1m, $cisco_cpu_5s);
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_request(@oidlists)
: $session->get_request(-varbindlist => \@oidlists);
@@ -499,7 +511,7 @@ sub check_options {
############## Cisco N5K CPU Check ###################
if ($o_check_type eq "n5k") {
my @oidlists = ($n5k_cpu);
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_request(@oidlists)
: $session->get_request(-varbindlist => \@oidlists);
if (!defined($resultat)) {
@@ -542,7 +554,7 @@ sub check_options {
if ($o_check_type eq "cata") {
my @oidlists = ($ciscocata_cpu_5m, $ciscocata_cpu_1m, $ciscocata_cpu_5s);
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_request(@oidlists)
: $session->get_request(-varbindlist => \@oidlists);
@@ -597,7 +609,7 @@ sub check_options {
if ($o_check_type eq "nsc") {
my @oidlists = ($nsc_cpu_5m, $nsc_cpu_1m, $nsc_cpu_5s);
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_request(@oidlists)
: $session->get_request(-varbindlist => \@oidlists);
@@ -654,7 +666,7 @@ sub check_options {
# Get load table
my @oidlist = $cpu_oid{$o_check_type};
verb("Checking OID : @oidlist");
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_request(@oidlist)
: $session->get_request(-varbindlist => \@oidlist);
if (!defined($resultat)) {
@@ -702,7 +714,7 @@ sub check_options {
verb("Checking hpux load");
my @oidlists = ($hpux_load_1_min, $hpux_load_5_min, $hpux_load_15_min);
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_request(@oidlists)
: $session->get_request(-varbindlist => \@oidlists);
@@ -755,7 +767,7 @@ sub check_options {
########## Standard cpu usage check ############
# Get desctiption table
-my $resultat = (Net::SNMP->VERSION lt 4) ?
+my $resultat = (is_legacy_snmp_version()) ?
$session->get_table($base_proc)
: $session->get_table(Baseoid => $base_proc);

View file

@ -6,5 +6,6 @@
18_check_snmp_process_tmp_file
19_check_snmp_load_n5k
20_check_snmp_load_multiple_cpus
21_check_snmp_load_abstract_snmp_version_check
50_disable_epn
51_fix_privacy_doc