File: 10_check_snmp_storage_error_handling

package info (click to toggle)
nagios-snmp-plugins 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,244 kB
  • sloc: perl: 7,453; sh: 309; makefile: 50
file content (42 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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...