## 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"};
