Domoticz age checker

Last Updated or created 2023-01-03

A script to check the age of sensors.
Sometimes you don’t have a good 433Mhz connection.
Or the battery has died of your sensor.

This script will warn you.

sensoragescript.sh (for cron)

#!/bin/bash
#Call as follows
#sensoragescript.sh <ipdomoticz> <idx-of-sensor> <age-to-test-in-seconds>

now=$(date +%s)
lastupdate=$(curl -s -i -H "Accept: application/json" "http://$1:8080/json.htm?type=devices&rid=$2" |  grep LastUpdate | cut -f4 -d\" )
#echo $lastupdate
seen=$(date -d "$lastupdate" +%s)
#echo $seen
#echo "$(( $now - $seen))"
difftime="$(( $now - $seen))"
if [ $difftime -gt $3 ] ; then
  echo "WARN : too old - $difftime seconds"
  exit 1
else
  echo "OK : $difftime seconds"
  exit 0
fi

Outputs:

./new.sh 192.168.1.1 123 60
OK : 22 seconds

./new.sh 192.168.1.1 123 60
WARN : too old - 69 seconds

check_mk / icinga check

#!/bin/bash
IPDOMO=192.168.1.1
IDX=123
agewarn=300
now=$(date +%s)
lastupdate=$(curl -s -i -H "Accept: application/json" "http://$IPDOMO:8080/json.htm?type=devices&rid=$IDX" |  grep LastUpdate | cut -f4 -d\" )
seen=$(date -d "$lastupdate" +%s)
difftime="$(( $now - $seen))"
if [ $difftime -gt $agewarn ] ; then
  echo "1 \"WARN - Age check Fridge\" realage=$difftime|age=$agewarn Age of fridge"
  exit 1
else
  echo "0 \"OK - Age check Fridge\" realage=$difftime|age=$agewarn Age of fridge"
  exit 0
fi
Spread the love