Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


check_mk_meteohub_linux

Check_MK - Meteohub script

#!/bin/bash

IFS=' '

fivemin=`date --utc +%Y%m%d%H%M%S --date="5 min ago"`
th0="buiten"
th1="zolder"
thb0="huiskamer"
uv0="UVindex"
wind0="wind"
rain0="regen"

wget -qO- "http://localhost/meteolog.cgi?mode=data" | while read line
do
 arr=($line)
 # If data is not older than 5 min.
 if [ ${arr[0]} -ge $fivemin ]; then
   case ${arr[1]} in
     th0)
      echo "0 sensor-$th0 temp=${arr[2]}|hum=${arr[3]}|dew=${arr[4]} Temp: ${arr[2]} deg. Celcius"
      ;;
     th1)
      if [ $(echo "${arr[2]} < 30" | bc)  -eq 1 ]; then
        echo "0 sensor-$th1 temp=${arr[2]};30;35;10;40|hum=${arr[3]};;;0;100|dew=${arr[4]} Temp: ${arr[2]} deg. Celcius"
      elif [ $(echo "${arr[2]} >=  30" | bc) -eq 1 -a $(echo "${arr[2]} < 35" | bc) -eq 1 ]; then
        echo "1 sensor-$th1 temp=${arr[2]};30;35;10;40|hum=${arr[3]};;;0;100|dew=${arr[4]} Temp: ${arr[2]} deg. Celcius"
      elif [ $(echo "${arr[2]} >= 35" | bc) -eq 1 ]; then
        echo "2 sensor-$th1 temp=${arr[2]};30;35;10;40|hum=${arr[3]};;;0;100|dew=${arr[4]} Temp: ${arr[2]} deg. Celcius"
      fi
      ;;
     thb0)
      case ${arr[7]} in
         0)
          forecast="rainy"
          ;;
         1)
          forecast="cloudy"
          ;;
         2)
          forecast="some clouds"
          ;;
         3)
          forecast="sunny"
          ;;
         4)
          forecast="snowy"
          ;;
         5)
          forecast="clouds at night"
          ;;
         6)
          forecast="clear night"
          ;;
      esac
      echo "0 sensor-$thb0 temp=${arr[2]}|hum=${arr[3]}|dew=${arr[4]}|press=${arr[5]}|seapress=${arr[6]}|forecast=${arr[7]} Temp: ${arr[2]} deg. Celcius, forecast: $forecast"
      ;;
     wind0)
      echo "0 sensor-$wind0 dir=${arr[2]}|gust=${arr[3]};20;25|avgspeed=${arr[4]};20;25|wchill=${arr[5]} Wind from ${arr[2]} deg. ${arr[4]} m/s avg. speed"
      ;;
     uv0)
      echo "0 sensor-$uv0 uvindex=${arr[2]} UV index: ${arr[2]}"
      ;;
     rain0)
      echo "0 sensor-$rain0 rainrate=${arr[2]}|raintotal=${arr[3]}|delta=${arr[4]} Rain rate: ${arr[2]} mm/h, total ${arr[3]} mm "
      ;;
   esac
 fi
done
check_mk_meteohub_linux.txt · Last modified: 2021/10/09 15:14 by 127.0.0.1