Fix negative temperature value alert in check_pcmeasure2 plugin

Written by - 0 comments

Published on - 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 check_pcmeasure2.pl by www.messpc.de. 

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:

./check_pcmeasure2.pl  -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 check_pcmeasure2.pl 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
$np->set_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:

./check_pcmeasure2.pl  -H 212.71.111.200 -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.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder