another fixme
[usb-wde1-tools.git] / munin / usb-wde1_
index 388a9b4161fd3655e9b2faba0a29f43ddd48e444..b3863b6ef1f7f4781a700d8ce79424e0bab8fda3 100755 (executable)
@@ -8,12 +8,16 @@
 usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
 
 =head1 CONFIGURATION
+ The plugin offers two modes: temperature and humidity graphing.
+
+ Symlink usb-wde1_ as "usb-wde1_temperature" and/or "usb-wde1_humidity".
 
 =head2 EXAMPLE CONFIGURATION
 
- [usb-wde1]
+ [usb-wde1_temperature]
   env.logfile /var/log/usb-wde1.log
   env.host_name House
+  env.sensors 0 1 2 3 4 7
   env.sensor0 Living room
   env.sensor1 Kitchen
 
@@ -24,17 +28,15 @@ usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
 
 =cut
 
-# params:
-# - logfile
-# - sensor names
-# - type (temperature / humidity)
-# - hostname
+TYPE=`basename $0 | sed 's/^.*_//g'`
 
 if [ "$1" = "autoconf" ]; then
-    if [ -r "$logfile" ]; then
-        echo yes
-    else
+    if [ ! -r "$logfile" ]; then
         echo "no (Logfile \"$logfile\" does not exist)"
+    elif [ "$TYPE" != "temperature" -a "$TYPE" != "humidity" ]; then
+        echo "no (Type \"$TYPE\" not supported, try \"./usb-wde1_ suggest\")"
+    else
+        echo yes
     fi
     exit 0
 
@@ -44,9 +46,20 @@ elif [ "$1" = "suggest" ]; then
     exit 0
 fi
 
-
+###############
 #load variables
-TYPE=`basename $0 | sed 's/^.*_//g'`
+###############
+
+# Sensors to display
+if [ "$sensors" = "" ]; then
+    sensors="0 1 2 3 4 5 6 7"
+fi
+# Sensor names
+for i in $sensors; do
+    code="sensor$i=\${sensor$i:=Sensor $i}"
+    eval $code
+done
+# FIXME: Warning/critical values
 
 
 if [ "$1" = "config" ]; then
@@ -57,12 +70,46 @@ if [ "$1" = "config" ]; then
         echo 'graph_title Temperature'
         echo 'graph_args --base 1000 --lower-limit -30 --upper-limit 60'
         echo 'graph_vlabel Temperature'
+        echo 'graph_info Shows the temperature of different thermometers'
     else
         echo 'graph_title Humidity'
         echo 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
         echo 'graph_vlabel Humidity'
+        echo 'graph_info Shows the air humidity of different thermometers (in %)'
     fi
     echo 'graph_scale no'
     echo 'graph_category sensors'
+
     #FIXME: warning/critical values
-fi
\ No newline at end of file
+    for i in $sensors; do
+        eval "name=\$sensor$i"
+        echo "sensor$i.label $name"
+    done
+
+    exit 0
+fi
+
+#split by semicolons
+OLDIFS="$IFS"
+IFS=";"
+read -r startzeichen zustand zeitstempel\
+    t0 t1 t2 t3 t4 t5 t6 t7\
+    h0 h1 h2 h3 h4 h5 h6 h7\
+    tc hc ws ns rain checksum\
+    < "$logfile"
+IFS=$OLDIFS
+
+#FIXME: check startzeichen
+#FIXME: check timestamp
+
+if [ "$TYPE" = "temperature" ]; then
+    varprefix=t
+else
+    varprefix=h
+fi
+
+
+for i in $sensors; do
+    eval "value=\$$varprefix$i"
+    echo "sensor$i.value $value"
+done