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