#!@@GOODSH@@
# -*- sh -*-

: << =cut

=head1 NAME

digitemp_ - Plugin to monitor Dallas 1-wire temperature sensors using
digitemp

=head1 CONFIGURATION

The following enviroment variables are used by this plugin:

 digitemprc - config file to use. (Default /etc/digitemp.conf)
              This must be generated with digitemp_<model> -i

=head1 USAGE

Symlink as the name of the digitemp program to use, i.e. digitemp_DS2490

=head1 AUTHOR

Copyright (C) 2006 Dagfinn Ilmari Mannsaaker <ilmari@ilmari.org>

=head1 LICENSE

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; version 2 dated June, 1991.

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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

=head1 MAGIC MARKERS

 #%# family=manual

=cut

digitemp=${0##*/}
model=${digitemp##*_}
digitemprc=${digitemprc:-/etc/digitemp.conf}

if ! [ -x "`which $digitemp`" ]; then
    echo "$digitemp not found" >&2
    exit 1
fi

if [ "$1" = "config" ]; then
    echo "graph_title DigiTemp $model temperatures"
    echo 'graph_vlabel degrees C'
    echo 'graph_category sensors'
    echo "graph_info This graph shows the temperature read from $model 1-wire sensors"
    $digitemp -c "$digitemprc" -q -a -o '%s %R' | grep -v ^Found | while read sensor serial; do
	echo "sensor$serial.label sensor #$sensor"
	echo "sensor$serial.type GAUGE"
	echo "sensor$serial.info Temperature from sensor #$sensor"
	echo "sensor$serial.critical 30"
        echo "sensor$serial.warning 25"
   done
   exit 0
fi

$digitemp -c "$digitemprc" -q -a -o 'sensor%R.value %C'|grep -v ^Found
