add support for warning/critical values
[usb-wde1-tools.git] / munin / usb-wde1_
index 9bd730fb2b09b5e614a2b0bd0a6808422e973fb7..485432b59325ac36a24e16388ca28bbe9b19d9da 100755 (executable)
@@ -22,18 +22,32 @@ usb-wde1 -  Munin plugin to report usb-wde1 temperature and humidity data
   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
 
  #%# family=manual
  #%# capabilities=autoconf suggest
 
-=head1 AUTHOR and LICENSE
-
-License: http://www.gnu.org/licenses/agpl.html AGPL
-Author: Christian Weiske <cweiske@cweiske.de>
-
 =cut
 
+. "$MUNIN_LIBDIR/plugins/plugin.sh"
+
 TYPE=`basename $0 | sed 's/^.*_//g'`
 
 if [ "$1" = "autoconf" ]; then
@@ -65,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
@@ -88,10 +101,11 @@ if [ "$1" = "config" ]; then
     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
@@ -107,19 +121,23 @@ fi
 #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
 
-if [ "$startzeichen" != '$1' ]; then
+if [ "$sign" != '$1' ]; then
     echo Log line does not begin with \$1
     exit 2
 fi
 
-#FIXME: check timestamp
+curdate=`date +%s`
+if [ "$timestamp" -lt `expr $curdate - 600` ]; then
+    #timestamp is too old, data are too old
+    exit
+fi
 
 
 if [ "$TYPE" = "temperature" ]; then