Fix negative temperature value alert in check_pcmeasure2 plugin

Written by - 0 comments

Published on December 3rd 2013 - Listed in Nagios Monitoring

A few months ago I wrote about temperatures way above the mean temperature in Zurich, Switzerland. These temperatures were all measured with temperature sensors and the Nagios plugin by 

Now its winter in Switzerland and temperatures dropped significantly:

Temperature Sensor Graph

On November 28th, the temperature dropped below 0° Celcius and the plugin turned CRITICAL, although the thresholds were set to 37 and 40 degrees:

./  -H outsidesensor -p 4000 -S com1.2 -w 37 -c 40 -l temperature -F "%.1fC"
T CRITICAL - -0.1C | temperature=-0.1;37;40

Of course it doesn't make sense that the plugin now is in a CRITICAL status only because the temperature value became negative.

To fix this, I have modified to not pass the current temperature ($value) to the Nagios::Plugin (perl plugin):

# -----------------------------------------------
# finish: return to caller
# -----------------------------------------------
#my $result = $np->check_threshold($value);

# 2013-11-28 Claudio Kuenzler: fix threshold check when negative values occur
my $result = "";
if ( $value > $crit_threshold ) {
  $result = "CRITICAL";
elsif ( $value > $warn_threshold ) {
  $result = "WARNING";
else {
  $result = "OK";

# -- for future use alarm(0);
my $text_output = sprintf "$format_string", $value;
$np->nagios_exit($result, $text_output);

Another possible fix, which I haven't tested though, is to define the thresholds according to the Nagios Plugin Development Guidelines:

# -- thresholds
   warning  => ~:$warn_threshold,
   critical => ~:$crit_threshold,

Note the "~:" in front of the threshold variables? This declares a negative infinity. But as written above, I haven't tested this fix.

After my fix, the negative values are now handled correctly:

./  -H -p 4000 -S com1.2 -w 37 -c 40 -l temperature -F "%.1fC"
T OK - -0.1C | temperature=-0.1;37;40

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.