monitoring-plugins-sentry3/check_sentry3-fix_output_with_missing_sensors.patch

34 lines
1.4 KiB
Diff

--- check_sentry3.orig 2014-04-25 14:43:32.870837097 +0200
+++ check_sentry3 2014-04-25 14:44:50.387659839 +0200
@@ -193,7 +193,20 @@
$count +=1;
# Define the values we are going to test against
- $nagios_value[$count] = sprintf("%.2f",$poll_results{$key});
+ #$nagios_value[$count] = sprintf("%.2f",$poll_results{$key});
+ # Do this after "$count +=1" so we can correctly index results to exact sensors.
+ # If only humidity sensor "1" and "3" are plugged in don't show result for "2".
+ # e.g "SERVERTECH_HUMIDITY WARNING - Humidity1 @ 39.00%, Humidity3 @ 41.00%
+ # | Humidity1=39.00%;30;85 Humidity3=41.00%;30;85".
+ # This also prevents perf data shifting to a new key if you add a sensor.
+ if ($poll_results{$key} >= 0){
+ $nagios_value[$count] = sprintf("%.2f",$poll_results{$key});
+ } else {
+ # Don't add negative numbers to @nagios_value that cause Nagios::Plugin::Range
+ # (via check_threshold) test to fail.
+ # Also don't add empty sensor data to the perf hashes.
+ next;
+ }
# Process the value
if ($cmd_flags{do_temp}){
@@ -255,6 +268,8 @@
}
}
+ # remove undefs now that $message has sensor postions set by $nagios_value[$count]
+ @nagios_value = grep defined, @nagios_value;
# Remove trailing comma from $message
$message =~ s/\,+\s+$//g;