From e7472bfb2a39f3536350642b177e5f9e17c5c369 Mon Sep 17 00:00:00 2001
From: Louis Sautier <sautier.louis@gmail.com>
Date: Mon, 29 Jan 2018 09:17:25 +0100
Subject: [PATCH] check_snmp_storage: fix SNMP error handling, see #33

---
 plugins/check_snmp_storage.pl | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/plugins/check_snmp_storage.pl b/plugins/check_snmp_storage.pl
index 2325acc..3593f79 100755
--- a/plugins/check_snmp_storage.pl
+++ b/plugins/check_snmp_storage.pl
@@ -598,6 +598,15 @@ sub check_options {
     $result = $session->get_request(@oids);
 } else {
     $result = $session->get_request(Varbindlist => \@oids);
+}
+
+if (!defined($result)) {
+    printf("ERROR getting OIDs: %s.\n", $session->error);
+    $session->close;
+    exit $ERRORS{"UNKNOWN"};
+}
+
+if (version->parse(Net::SNMP->VERSION) >= 4) {
     foreach my $key (sort keys %$result) {
 
         # Fix for filesystems larger 2 TB. More than 2 TB will cause an error because
@@ -613,12 +622,6 @@ sub check_options {
     }
 }
 
-if (!defined($result)) {
-    printf("ERROR: Size table :%s.\n", $session->error);
-    $session->close;
-    exit $ERRORS{"UNKNOWN"};
-}
-
 $session->close;
 
 # Only a few ms left...
