munin plugin should basically work nwo
[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_temperature]
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 =cut
30
31 TYPE=`basename $0 | sed 's/^.*_//g'`
32
33 if [ "$1" = "autoconf" ]; then
34     if [ ! -r "$logfile" ]; then
35         echo "no (Logfile \"$logfile\" does not exist)"
36     elif [ "$TYPE" != "temperature" -a "$TYPE" != "humidity" ]; then
37         echo "no (Type \"$TYPE\" not supported, try \"./usb-wde1_ suggest\")"
38     else
39         echo yes
40     fi
41     exit 0
42
43 elif [ "$1" = "suggest" ]; then
44     echo temperature
45     echo humidity
46     exit 0
47 fi
48
49 ###############
50 #load variables
51 ###############
52
53 # Sensors to display
54 if [ "$sensors" = "" ]; then
55     sensors="0 1 2 3 4 5 6 7"
56 fi
57 # Sensor names
58 for i in $sensors; do
59     code="sensor$i=\${sensor$i:=Sensor $i}"
60     eval $code
61 done
62 # FIXME: Warning/critical values
63
64
65 if [ "$1" = "config" ]; then
66     if [ "$host_name" != "" ]; then
67         echo "host_name $host_name"
68     fi
69     if [ "$TYPE" = "temperature" ]; then
70         echo 'graph_title Temperature'
71         echo 'graph_args --base 1000 --lower-limit -30 --upper-limit 60'
72         echo 'graph_vlabel Temperature'
73         echo 'graph_info Shows the temperature of different thermometers'
74     else
75         echo 'graph_title Humidity'
76         echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
77         echo 'graph_vlabel Humidity'
78         echo 'graph_info Shows the air humidity of different thermometers (in %)'
79     fi
80     echo 'graph_scale no'
81     echo 'graph_category sensors'
82
83     #FIXME: warning/critical values
84     for i in $sensors; do
85         eval "name=\$sensor$i"
86         echo "sensor$i.label $name"
87     done
88
89     exit 0
90 fi
91
92 #split by semicolons
93 OLDIFS="$IFS"
94 IFS=";"
95 read -r startzeichen zustand zeitstempel\
96     t0 t1 t2 t3 t4 t5 t6 t7\
97     h0 h1 h2 h3 h4 h5 h6 h7\
98     tc hc ws ns rain checksum\
99     < "$logfile"
100 IFS=$OLDIFS
101
102 #FIXME: check timestamp
103
104 if [ "$TYPE" = "temperature" ]; then
105     varprefix=t
106 else
107     varprefix=h
108 fi
109
110
111 for i in $sensors; do
112     eval "value=\$$varprefix$i"
113     echo "sensor$i.value $value"
114 done