add support for warning/critical values
[usb-wde1-tools.git] / munin / usb-wde1_
1 #!/bin/sh
2 # -*- sh -*-
3
4 : << =cut
5
6 =head1 NAME
7
8 usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
9
10 =head1 CONFIGURATION
11  The plugin offers two modes: temperature and humidity graphing.
12
13  Symlink usb-wde1_ as "usb-wde1_temperature" and/or "usb-wde1_humidity".
14
15 =head2 EXAMPLE CONFIGURATION
16
17  [usb-wde1_*]
18   env.logfile /tmp/usb-wde1-last
19   env.host_name House
20   env.sensors 0 1 7
21   env.sensor0 Living room
22   env.sensor1 Kitchen
23   env.sensor7 Outside
24
25  Warning/critical values for all sensors:
26   env.warning 10
27   env.critical 5
28
29  Warning/critical values for single sensors:
30   env.sensor7_warning 40
31   env.sensor7_critical 50
32
33 =head1 AUTHOR
34
35 Christian Weiske <cweiske@cweiske.de>
36
37 =head1 LICENSE
38
39 AGPL
40 http://www.gnu.org/licenses/agpl.html
41
42 =head1 MAGIC MARKERS
43
44  #%# family=manual
45  #%# capabilities=autoconf suggest
46
47 =cut
48
49 . "$MUNIN_LIBDIR/plugins/plugin.sh"
50
51 TYPE=`basename $0 | sed 's/^.*_//g'`
52
53 if [ "$1" = "autoconf" ]; then
54     if [ ! -r "$logfile" ]; then
55         echo "no (Logfile \"$logfile\" does not exist)"
56     elif [ "$TYPE" != "temperature" -a "$TYPE" != "humidity" ]; then
57         echo "no (Type \"$TYPE\" not supported, try \"./usb-wde1_ suggest\")"
58     else
59         echo yes
60     fi
61     exit 0
62
63 elif [ "$1" = "suggest" ]; then
64     echo temperature
65     echo humidity
66     exit 0
67 fi
68
69 ###############
70 #load variables
71 ###############
72
73 # Sensors to display
74 if [ "$sensors" = "" ]; then
75     sensors="0 1 2 3 4 5 6 7"
76 fi
77 # Sensor names
78 for i in $sensors; do
79     code="sensor$i=\${sensor$i:=Sensor $i}"
80     eval $code
81 done
82
83
84 if [ "$1" = "config" ]; then
85     if [ "$host_name" != "" ]; then
86         echo "host_name $host_name"
87     fi
88     if [ "$TYPE" = "temperature" ]; then
89         echo 'graph_title Temperature'
90         #echo 'graph_args --base 1000 --lower-limit -30 --upper-limit 60'
91         echo 'graph_args --base 1000'
92         echo 'graph_vlabel Temperature'
93         echo 'graph_info Shows the temperature of different thermometers'
94     else
95         echo 'graph_title Humidity'
96         #echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
97         echo 'graph_args --base 1000'
98         echo 'graph_vlabel Humidity'
99         echo 'graph_info Shows the air humidity of different thermometers (in %)'
100     fi
101     echo 'graph_scale no'
102     echo 'graph_category sensors'
103
104     for i in $sensors; do
105         eval "name=\$sensor$i"
106         echo "sensor$i.label $name"
107         print_warning "sensor$i"
108         print_critical "sensor$i"
109     done
110
111     exit 0
112 fi
113
114 #Beispielausgabe USB-WDE1:
115 # $1;1;;13,8;22,7;22,6;17,8;22,2;21,2;22,9;;59;35;38;49;38;40;35;;;;;;;0
116 # Doku des Formats in 92030_USB_WDE1_V1.0_UM.pdf bei elv.de verf├╝gbar
117 # Format ist "Logview openformat"
118 # http://www.logview.info/cms/d_formatbeschreibung.phtml
119
120
121 #split by semicolons
122 OLDIFS="$IFS"
123 IFS=";"
124 read -r sign state timestamp\
125     t0 t1 t2 t3 t4 t5 t6 t7\
126     h0 h1 h2 h3 h4 h5 h6 h7\
127     tc hc ws ns rain checksum\
128     < "$logfile"
129 IFS=$OLDIFS
130
131 if [ "$sign" != '$1' ]; then
132     echo Log line does not begin with \$1
133     exit 2
134 fi
135
136 curdate=`date +%s`
137 if [ "$timestamp" -lt `expr $curdate - 600` ]; then
138     #timestamp is too old, data are too old
139     exit
140 fi
141
142
143 if [ "$TYPE" = "temperature" ]; then
144     varprefix=t
145 else
146     varprefix=h
147 fi
148
149
150 for i in $sensors; do
151     eval "value=\$$varprefix$i"
152     value=`echo $value|sed s/,/./`
153     echo "sensor$i.value $value"
154 done