#!/usr/bin/perl -w # $Id: $ # Copyright (C) 2009 Jonas Genannt # # Munin plugin for Arduino DS1820 Ethernet Sketch # # Copy to /usr/local/ create an link to /etc/munin/plugins/arduino_ds1820_192.168.1.3 # to fetch from 192.168.1.3 the DS1820. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 3 of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with this program; # if not, see . # use strict; use Net::Telnet; use Data::Dumper; my $DEBUG=0; sub get_temperatures ; my $host; if ( $0 =~m/ds1820_(.+)*$/) { $host = $1; } exit 2 unless defined $host; print "[D] Host = $host\n" if ($DEBUG); my %temperatures = get_temeratures(); if ($ARGV[0] and $ARGV[0] eq "config") { print "graph_args --base 1000 --vertical-label temperature\n"; print "graph_category other\n"; print "graph_scale no\n"; print "graph_info Dallas DS1820 sensors via Arduino with Ethershield\n"; print "graph_title temperature sensors\n"; foreach (keys(%temperatures)) { my $desc = $ENV{$_} || $_; print $_ . ".label $desc\n" ; } exit; } foreach (keys(%temperatures)) { print $_ . ".value " . $temperatures{$_} . "\n"; } sub get_temeratures { my %ds1820; my $arduino = new Net::Telnet(Telnetmode => 0); $arduino->open($host); $arduino->print("\n"); my @data = $arduino->getlines(); $arduino->close; foreach my $line (@data) { chomp($line); my @values = split(/:/, $line); if (@values == 4) { $values[2]=~s/^\s+|\s+$//g; $values[3]=~s/^\s+|\s+$//g; if ($values[3]=~m/^([0-9\.]+)$/) { $ds1820{$values[2]} = $values[3]; } else { $ds1820{$values[2]} = -1; } print "[D] SN: " . $values[2] . ": ". $values[3] ."\n" if($DEBUG); } else { print "[D] Could not parse line: $line\n" if ($DEBUG); } } return %ds1820; }