add support for warning/critical values
[usb-wde1-tools.git] / munin / usb-wde1_
index b3863b6ef1f7f4781a700d8ce79424e0bab8fda3..485432b59325ac36a24e16388ca28bbe9b19d9da 100755 (executable)
@@ -14,12 +14,30 @@ usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
 
 =head2 EXAMPLE CONFIGURATION
 
- [usb-wde1_temperature]
-  env.logfile /var/log/usb-wde1.log
+ [usb-wde1_*]
+  env.logfile /tmp/usb-wde1-last
   env.host_name House
-  env.sensors 0 1 2 3 4 7
+  env.sensors 0 1 7
   env.sensor0 Living room
   env.sensor1 Kitchen
+  env.sensor7 Outside
+
+ Warning/critical values for all sensors:
+  env.warning 10
+  env.critical 5
+
+ Warning/critical values for single sensors:
+  env.sensor7_warning 40
+  env.sensor7_critical 50
+
+=head1 AUTHOR
+
+Christian Weiske <cweiske@cweiske.de>
+
+=head1 LICENSE
+
+AGPL
+http://www.gnu.org/licenses/agpl.html
 
 =head1 MAGIC MARKERS
 
@@ -28,6 +46,8 @@ usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
 
 =cut
 
+. "$MUNIN_LIBDIR/plugins/plugin.sh"
+
 TYPE=`basename $0 | sed 's/^.*_//g'`
 
 if [ "$1" = "autoconf" ]; then
@@ -59,7 +79,6 @@ for i in $sensors; do
     code="sensor$i=\${sensor$i:=Sensor $i}"
     eval $code
 done
-# FIXME: Warning/critical values
 
 
 if [ "$1" = "config" ]; then
@@ -68,39 +87,58 @@ if [ "$1" = "config" ]; then
     fi
     if [ "$TYPE" = "temperature" ]; then
         echo 'graph_title Temperature'
-        echo 'graph_args --base 1000 --lower-limit -30 --upper-limit 60'
+        #echo 'graph_args --base 1000 --lower-limit -30 --upper-limit 60'
+        echo 'graph_args --base 1000'
         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_args --base 1000 --lower-limit 0 --upper-limit 100'
+        echo 'graph_args --base 1000'
         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
     for i in $sensors; do
         eval "name=\$sensor$i"
         echo "sensor$i.label $name"
+        print_warning "sensor$i"
+        print_critical "sensor$i"
     done
 
     exit 0
 fi
 
+#Beispielausgabe USB-WDE1:
+# $1;1;;13,8;22,7;22,6;17,8;22,2;21,2;22,9;;59;35;38;49;38;40;35;;;;;;;0
+# Doku des Formats in 92030_USB_WDE1_V1.0_UM.pdf bei elv.de verfügbar
+# Format ist "Logview openformat"
+# http://www.logview.info/cms/d_formatbeschreibung.phtml
+
+
 #split by semicolons
 OLDIFS="$IFS"
 IFS=";"
-read -r startzeichen zustand zeitstempel\
+read -r sign state timestamp\
     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 [ "$sign" != '$1' ]; then
+    echo Log line does not begin with \$1
+    exit 2
+fi
+
+curdate=`date +%s`
+if [ "$timestamp" -lt `expr $curdate - 600` ]; then
+    #timestamp is too old, data are too old
+    exit
+fi
+
 
 if [ "$TYPE" = "temperature" ]; then
     varprefix=t
@@ -111,5 +149,6 @@ fi
 
 for i in $sensors; do
     eval "value=\$$varprefix$i"
+    value=`echo $value|sed s/,/./`
     echo "sensor$i.value $value"
 done