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