Welcome to It-Slav.Net blog
Peter Andersson

I've already got a female to worry about. Her name is the Enterprise.
-- Kirk, "The Corbomite Maneuver", stardate 1514.0

After got the 1-wire stuff working it is time to use the temperature probes to get some use of measuring your environment. This article describe how you can create an op5 Monitor or Nagios plugin to monitor your temperatures.

Read my previous articles to get the 1-wire bus up and running:

I found a 1-wire temperature Nagios plugin on internet, but it had some disadvantages:

  • Used Fahrenheit instead of Celsius
  • Did not accept thresholds below zero degrees, in Sweden that is quite common temperature during winter.
  • Strange License, it just said Copyright and a name and email address that bounced.

The Nagios plugin was written in Perl so it was straight forward to modify and fix the obstacles I found. But the copyright bothered me because I wanted to publish the changes, I tried to email the email address I found in the script but it bounced, so I decided to write my own plugin.

I have published the script at nagiosexchange.

The files

The plugin check_1-wiretemp version 1.0 can be found here or below.

#!/usr/bin/perl -w
# Check temperature of 1Wire device
# Requires use of owfs
# By Peter Andersson
# peter@it-slav.net
# http://www.it-slav.net/blogs/?p=115
# Licence GPLv2
# Version 1.0

use strict;
use Getopt::Std;
use OW;

my $owserver = "";
my(%ERRORS) = ( OK=>0, WARNING=>1, CRITICAL=>2, UNKNOWN=>3 );

my $temperature;
my $status=$ERRORS{OK};;
my $message;

my $debug_flag=0;

our($opt_c, $opt_w, $opt_W, $opt_C, $opt_h, $opt_o, $opt_i);


sub printhelp () {
        print "Usage: check_1-wiretemp [-h] -c lowtempcritical -w lowtempwarning -W higtempwarning -C higtempcritical -i id [-o owserver:port]\n";
        print "-h Help, this text\n-c num Critical threshold for low temp\n-w num Warning threshold for low temp\n";
        print "-W num Warning threshold for hightemp\n-C num Critical threshold for hightemp\n";
        print "-o <name|ip>:port, Servername of 1-wire server and portnumber the owserver use, default\n";
        print "-i 1-wire ID, i.e. 10.DEF05F01080015\n";
        print "\n\t\tby Peter Andersson\n\t\tpeter\@it-slav.net\n\t\thttp://www.it-slav.net/blogs/?p=115\n";
        if ($debug_flag) {
                print "opt_c:$opt_c opt_w:$opt_w opt_W:$opt_W opt_C:$opt_C opt_h:$opt_h owserver:$owserver opt_i:$opt_i Temperture:$temperature\n";

        exit $status;

#sanity check
if (!defined $opt_c||!defined $opt_w||!defined $opt_W||!defined $opt_C||$opt_h) {
        $status= $ERRORS{UNKNOWN};
} elsif ($opt_c > $opt_w) {
        print "Critical low threshold must be higher or equal to warning low threshold\n";
        $status= $ERRORS{UNKNOWN};
} elsif ($opt_w > $opt_W || $opt_c > $opt_C) {
        print "Lower tresholds must be lower then higher thresholds\n";
        $status= $ERRORS{UNKNOWN};
} elsif ($opt_C < $opt_W) {
        print "Higher critical threshold must be higher or equal to higher warning threshold\n";
        $status= $ERRORS{UNKNOWN};

if ($opt_o) {
        $owserver = $opt_o;

unless(OW::init($owserver)) {
        $status = $ERRORS{CRIT};
        $message = "OWServer not running at $owserver\n";
        exit $status;
$temperature = OW::get("$opt_i/temperature");
$temperature =~ s/^\s*(.*?)\s*$/$1/; #remove whitespaces
unless (($temperature =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/) || ($temperature =~ /^[+-]?\d+$/)) #check that it is an integer or decimal returned
        $message="Did not got an integer or a decimal from temperature probe";
$temperature = sprintf("%.2f", $temperature);

if ($debug_flag) {
        print "opt_c:$opt_c opt_w:$opt_w opt_W:$opt_W opt_C:$opt_C opt_h:$opt_h owserver:$owserver opt_i:$opt_i Temperture:$temperature\n";

if ($temperature <= $opt_c) {
} elsif ($temperature > $opt_c && $temperature <= $opt_w) {
} elsif ($temperature >  $opt_w && $temperature <  $opt_W) {
} elsif ($temperature >= $opt_W && $temperature < $opt_C) {
} elsif ($temperature >= $opt_C) {
} else { #This should never happend

print "$message: $temperature C\|temperature=$temperature;$opt_c;$opt_w;$opt_W;$opt_C\n";
exit $status;


The Metadata in op5 Monitor /opt/monitor/etc/checkcommands.cfg or Nagios checkcommands.cfg:

# command 'check_1-wiretemp'
define command{
    command_name                   check_1-wiretemp
    command_line                   $USER1$/custom/check_1-wiretemp -c $ARG1$ -w $ARG2$ -W$ARG3$ -C$ARG4$ -i $ARG5$ -o $ARG6$

The service command definitions /opt/monitor/etc/services.cfg:

# service 'Temperature Outdoor'
define service{
    use                            default-service
    host_name                      monitor
    service_description            Temperature Outdoor
    check_command                  check_1-wiretemp!-20!-15!25!30!10.DEF05F01080015!
    contact_groups                 call_it-slav,it-slav_mail

The graph map /opt/monitor/op5/nagiosgraph/map_custom/1-wiretemp.map:

# peter@it-slav.net
# http://www.it-slav.net/blogs/?p=115
# Service type: 1-wire-temperature
#   output: OK: 22.88 C
#   perfdata: temperature=2.56;-20;-15;25;30
and push @s, [ temperature,
               [ "current", GAUGE, $1 ],
               [ "critical_low", GAUGE, $2 ],
               [ "warning_low", GAUGE, $3 ],
               [ "warning_high", GAUGE, $4 ],
               [ "critical_high", GAUGE, $5 ] ];
Hint: If you do not want to graph the thresholds remove $2, $3 ,$4, $5 gauges

Step by step guide

Step by step guide for op5 Monitor users, Nagios (or op5 Monitor) users can copy and paste the information above to the configuration files:

1. Copy the plugin to the correct path, i.e. /opt/plugins/custom/

2. Test the plugin

[root@op5 custom]# ./check_1-wiretemp -c 0 -w 1 -W 20 -C 23 -i 10.DEF05F01080015
OK: 3.56 C|temperature=3.56;0;1;20;23

Yes it works!

3. Define the command in op5 Monitor (in Nagios edit the


Choose "Add new command"


command name: check_1-wiretemp

command line: $USER1$/custom/check_1-wiretemp -c $ARG1$ -w $ARG2$ -W$ARG3$ -C$ARG4$ -i $ARG5$ -o $ARG6$

Press Apply button

To test:

Press Test this command

Change $ARG1$ $ARG2$ and so on to:

/opt/plugins/custom/check_1-wiretemp -c 0 -w 1 -W20 -C23 -i 10.DEF05F01080015 -o

Press continue

And the test works

Press "Save" to update the configuration files.

4. Configure the check_1-wiretemp

Press "Configure"

Pick the host, i.e. monitor

Press "Go"

Click "Services for monitor"

Choose "Add new service"

Service description i.e: Temperature Outdoor

check_command: check_1-wiretemp

check_command_args: -20!-15!25!30!10.DEF05F01080015!

(Critical low -20 C, Warning low -15 C, Warning high 25 C, Critical High 30 C, ID #10.DEF05F01080015, Host, port 3001)

Choose contact groups according to your preferences

To test, press "Test this service"

If everything looks fine press "Save" and your temperature service check is defined.

5. Create graphs

Copy and paste 1-wiretemp.map from above and put it in /opt/monitor/op5/nagiosgraph/map_custom/1-wiretemp.map


Congratulations, now you monitor your temperature and get alarms if it falls aout och thresholds.





3 Responses to “op5 Monitor or Nagios plugin for 1-wire temperature measurement”

  1. Pages tagged "plugin" Says:

    [...] bookmarks tagged plugin op5 Monitor or Nagios plugin for 1-wire temperatur… saved by 3 others     hannahmontana64 bookmarked on 11/23/08 | [...]

  2. Nagios or op5 Monitor plugin for 1-wire humidity measurement | An It-Slave in the digital saltmine Says:

    [...] In an earlier article I have described a 1-wire temperature plugin. [...]

  3. carsten Says:

    hi peter,

    cool script … but

    ran into problems with the embedded perl in nagios

    # nagios: -epn

    in your script resolved the problem


    have fun

Leave a Reply

× four = 16

Book reviews
FreePBX 2.5
Powerful Telephony Solutions

Asterisk 1.6
Build a feature rich telephony system with Asterisk

Learning NAGIOS 3.0

Cacti 0.8 Network Monitoring,
Monitor your network with ease!