keine limits
[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 =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_args --base 1000'
73         echo 'graph_vlabel Temperature'
74         echo 'graph_info Shows the temperature of different thermometers'
75     else
76         echo 'graph_title Humidity'
77         #echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
78         echo 'graph_args --base 1000'
79         echo 'graph_vlabel Humidity'
80         echo 'graph_info Shows the air humidity of different thermometers (in %)'
81     fi
82     echo 'graph_scale no'
83     echo 'graph_category sensors'
84
85     #FIXME: warning/critical values
86     for i in $sensors; do
87         eval "name=\$sensor$i"
88         echo "sensor$i.label $name"
89     done
90
91     exit 0
92 fi
93
94 #split by semicolons
95 OLDIFS="$IFS"
96 IFS=";"
97 read -r startzeichen zustand zeitstempel\
98     t0 t1 t2 t3 t4 t5 t6 t7\
99     h0 h1 h2 h3 h4 h5 h6 h7\
100     tc hc ws ns rain checksum\
101     < "$logfile"
102 IFS=$OLDIFS
103
104 #FIXME: check startzeichen
105 #FIXME: check timestamp
106
107 if [ "$TYPE" = "temperature" ]; then
108     varprefix=t
109 else
110     varprefix=h
111 fi
112
113
114 for i in $sensors; do
115     eval "value=\$$varprefix$i"
116     value=`echo $value|sed s/,/./`
117     echo "sensor$i.value $value"
118 done