-#!/usr/bin/env bash
-
-# kw, kwh, th_hr Bureau, th_hr Chambre_RDC, th_hr Exterieure, th_hr
-# Garage, th_hr Mezzanine, th_hr Sejour, th_hr Soufflage
-
-alert=$(date +"%F %H:%M:%S" -d "3 hours ago")
-res=$(curl https://maison.bbc.bouya.org/stats.php)
-
-ignored_text="Exterieure Soufflage Mezzanine"
-
-ignored_bat="^(Temp_Nord|Exterieure|Soufflage|Mezzanine)$"
-ignored="^(th_hr Exterieure|th_hr Soufflage|th_hr Mezzanine)$"
-
-missing() {
- echo "to_entries|[.[]|select(.value < \"$alert\" and .key != \"bat\" $1)|.key + \": \" + .value]|join(\" ; \")"
-}
-
-missing_check=$(echo "$res" | jq -r "$(missing "and (.key | test(\"$ignored\") | not)")")
-missing_show=$(echo "$res" | jq -r "$(missing "")")
-
-battery() {
- echo ".bat|to_entries|[.[]|select((.value[0] < \"$alert\" or (.value[1] | test(\"^0|1|2$\") | not)) $1)|.key + \": \" + .value[0] + \" bat \" + .value[1]]|join(\" ; \")"
-}
-
-bat_check=$(echo "$res" | jq -r "$(battery "and (.key | test(\"$ignored_bat\") | not)")")
-bat_show=$(echo "$res" | jq -r "$(battery "")")
-
-if [ -n "$missing_check" -o -n "$bat_check" ]; then
- text=""
- if [ -n "$missing_show" ]; then
- text="$text - Dernières dates: $missing_show"
- fi
- if [ -n "$bat_show" ]; then
- text="$text - Batteries: $bat_show"
- fi
- echo "Zibase CRITICAL$text"
- exit 2
-else
- echo "Zibase OK - Derniers événements il y a moins de 3h (ignorés : $ignored_text)"
- exit 0
-fi