File: 20_check_snmp_load_multiple_cpus

package info (click to toggle)
nagios-snmp-plugins 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,008 kB
  • ctags: 381
  • sloc: perl: 7,178; sh: 309; makefile: 50
file content (64 lines) | stat: -rw-r--r-- 2,004 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
## 19_check_snmp_load_n5k by Luis I. Perez Villota
##
## DP: Add support for n5k to check_snmp_load.pl

## From 1fcf4f4220edb886fb85931792542d962cf02ecb Mon Sep 17 00:00:00 2001
## From: Michael Friedrich <michael.friedrich@gmail.com>
## Date: Sat, 25 Apr 2015 15:20:32 +0200
## Subject: [PATCH] check_snmp_load.pl - Linux load multiple CPUs

## Linux load doesn't handle multiple CPUs properly. Here is a patch that makes
## the plugin to get the number of CPUs for a particular system and multiply
## warning and critical limits by this number.

fixes #6
---
check_snmp_load.pl | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

--- a/check_snmp_load.pl
+++ b/check_snmp_load.pl
@@ -363,11 +363,25 @@
 if ($o_check_type eq "netsl") {
 
 verb("Checking linux load");
+
+# Get number of CPUs
+my $resultat =  (Net::SNMP->VERSION < 4) ?
+	  $session->get_table($proc_id)
+	: $session->get_table(Baseoid => $proc_id);
+
+if (!defined($resultat)) {
+   printf("ERROR: Description table : %s.\n", $session->error);
+   $session->close;
+   exit $ERRORS{"UNKNOWN"};
+}
+
+my $ncpu = keys %$resultat;
+
 # Get load table
-my $resultat = (Net::SNMP->VERSION lt 4) ? 
+$resultat = (Net::SNMP->VERSION lt 4) ?
 		  $session->get_table($linload_table)
-		: $session->get_table(Baseoid => $linload_table); 
-		
+		: $session->get_table(Baseoid => $linload_table);
+
 if (!defined($resultat)) {
    printf("ERROR: Description table : %s.\n", $session->error);
    $session->close;
@@ -397,10 +411,13 @@
 
 for (my $i=0;$i<3;$i++) { $load[$i] = $$resultat{$linload_load . "." . $iload[$i]}};
 
-print "Load : $load[0] $load[1] $load[2] :";
+print "Load (CPUs: $ncpu) : $load[0] $load[1] $load[2] :";
 
 $exit_val=$ERRORS{"OK"};
 for (my $i=0;$i<3;$i++) {
+  # Multiply warning and critical levels by the number of CPUs
+  $o_warnL[$i] *= $ncpu;
+  $o_critL[$i] *= $ncpu;
   if ( $load[$i] > $o_critL[$i] ) {
    print " $load[$i] > $o_critL[$i] : CRITICAL";
    $exit_val=$ERRORS{"CRITICAL"};