File: digitemp_.in

package info (click to toggle)
munin 2.0.76-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,068 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (111 lines) | stat: -rw-r--r-- 3,085 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!@@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
and create configuration file (default: /etc/digitemp.conf).

=head1 AUTHOR

Copyright (C) 2006 Dagfinn Ilmari Mannsåker <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

 #%# capabilities=autoconf suggest
 #%# family=auto

=cut

# common values: digitemp_DS2490, digitemp_DS9097, digitemp_DS9097U
digitemp_bin=${0##*/}
model=${digitemp_bin##*_}
digitemprc=${digitemprc:-/etc/digitemp.conf}


get_sensor_data() {
    local output_pattern="$1"
    "$digitemp_bin" -c "$digitemprc" -q -a -o "$output_pattern" | grep -v ^Found
}


# find executable files in the search path starting with "digitemp_"
find_digitemp_executables() {
    [ -z "${PATH:-}" ] && return
    # split PATH by colons
    local IFS=":"
    # shellcheck disable=SC2086
    find $PATH -maxdepth 1 -xtype f -executable -name "digitemp_*" -print0 2>/dev/null \
        | xargs -0 -r -n 1 basename
}


if [ "$1" = "suggest" ]; then
    find_digitemp_executables
    exit 0
fi


if [ "$1" = "autoconf" ]; then
    if [ -z "$(find_digitemp_executables)" ]; then
        echo "no (failed to find executable starting with 'digitemp_')"
    elif [ ! -r "$digitemprc" ]; then
        echo "no (failed to read configuration file: $digitemprc)"
    else
        echo "yes"
    fi
    exit 0
fi


# check if the digitemp executable is available
if ! [ -x "$(command -v "$digitemp_bin")" ]; then
    echo "executable '$digitemp_bin' 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"
    get_sensor_data "%R %s" | while read -r serial sensor; 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

get_sensor_data "sensor%R.value %C"