26de11a90629832c2c96723dbd9b78effcb25e73
[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 /var/log/usb-wde1.log
19   env.host_name House
20   env.sensors 0 1 2 3 4 7
21   env.sensor0 Living room
22   env.sensor1 Kitchen
23
24 =head1 MAGIC MARKERS
25
26  #%# family=manual
27  #%# capabilities=autoconf suggest
28
29 =head1 AUTHOR and LICENSE
30
31 License: http://www.gnu.org/licenses/agpl.html AGPL
32 Author: Christian Weiske <cweiske@cweiske.de>
33
34 =cut
35
36 TYPE=`basename $0 | sed 's/^.*_//g'`
37
38 if [ "$1" = "autoconf" ]; then
39     if [ ! -r "$logfile" ]; then
40         echo "no (Logfile \"$logfile\" does not exist)"
41     elif [ "$TYPE" != "temperature" -a "$TYPE" != "humidity" ]; then
42         echo "no (Type \"$TYPE\" not supported, try \"./usb-wde1_ suggest\")"
43     else
44         echo yes
45     fi
46     exit 0
47
48 elif [ "$1" = "suggest" ]; then
49     echo temperature
50     echo humidity
51     exit 0
52 fi
53
54 ###############
55 #load variables
56 ###############
57
58 # Sensors to display
59 if [ "$sensors" = "" ]; then
60     sensors="0 1 2 3 4 5 6 7"
61 fi
62 # Sensor names
63 for i in $sensors; do
64     code="sensor$i=\${sensor$i:=Sensor $i}"
65     eval $code
66 done
67 # FIXME: Warning/critical values
68
69
70 if [ "$1" = "config" ]; then
71     if [ "$host_name" != "" ]; then
72         echo "host_name $host_name"
73     fi
74     if [ "$TYPE" = "temperature" ]; then
75         echo 'graph_title Temperature'
76         #echo 'graph_args --base 1000 --lower-limit -30 --upper-limit 60'
77         echo 'graph_args --base 1000'
78         echo 'graph_vlabel Temperature'
79         echo 'graph_info Shows the temperature of different thermometers'
80     else
81         echo 'graph_title Humidity'
82         #echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
83         echo 'graph_args --base 1000'
84         echo 'graph_vlabel Humidity'
85         echo 'graph_info Shows the air humidity of different thermometers (in %)'
86     fi
87     echo 'graph_scale no'
88     echo 'graph_category sensors'
89
90     #FIXME: warning/critical values
91     for i in $sensors; do
92         eval "name=\$sensor$i"
93         echo "sensor$i.label $name"
94     done
95
96     exit 0
97 fi
98
99 #Beispielausgabe USB-WDE1:
100 # $1;1;;13,8;22,7;22,6;17,8;22,2;21,2;22,9;;59;35;38;49;38;40;35;;;;;;;0
101 # Doku des Formats in 92030_USB_WDE1_V1.0_UM.pdf bei elv.de verfügbar
102 # Format ist "Logview openformat"
103 # http://www.logview.info/cms/d_formatbeschreibung.phtml
104
105
106 #split by semicolons
107 OLDIFS="$IFS"
108 IFS=";"
109 read -r startzeichen zustand zeitstempel\
110     t0 t1 t2 t3 t4 t5 t6 t7\
111     h0 h1 h2 h3 h4 h5 h6 h7\
112     tc hc ws ns rain checksum\
113     < "$logfile"
114 IFS=$OLDIFS
115
116 #FIXME: check startzeichen
117 #FIXME: check timestamp
118
119 if [ "$TYPE" = "temperature" ]; then
120     varprefix=t
121 else
122     varprefix=h
123 fi
124
125
126 for i in $sensors; do
127     eval "value=\$$varprefix$i"
128     value=`echo $value|sed s/,/./`
129     echo "sensor$i.value $value"
130 done