diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-05 17:08:32 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-01-05 17:08:32 +0100 |
commit | e820134d38c3b7470ea5112f40a6dc967f039878 (patch) | |
tree | f05a5cefe285d060aa0ebf52829bcfcd35549f8b /modules/private/monitoring/plugins/check_maison_bbc | |
parent | b22ce4895ef1e9723a02061f7293e528cfbf9754 (diff) | |
download | Nix-e820134d38c3b7470ea5112f40a6dc967f039878.tar.gz Nix-e820134d38c3b7470ea5112f40a6dc967f039878.tar.zst Nix-e820134d38c3b7470ea5112f40a6dc967f039878.zip |
Add monitoring host
Diffstat (limited to 'modules/private/monitoring/plugins/check_maison_bbc')
-rwxr-xr-x | modules/private/monitoring/plugins/check_maison_bbc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_maison_bbc b/modules/private/monitoring/plugins/check_maison_bbc new file mode 100755 index 0000000..43a5817 --- /dev/null +++ b/modules/private/monitoring/plugins/check_maison_bbc | |||
@@ -0,0 +1,41 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # kw, kwh, th_hr Bureau, th_hr Chambre_RDC, th_hr Exterieure, th_hr | ||
4 | # Garage, th_hr Mezzanine, th_hr Sejour, th_hr Soufflage | ||
5 | |||
6 | alert=$(date +"%F %H:%M:%S" -d "3 hours ago") | ||
7 | res=$(curl https://maison.bbc.bouya.org/stats.php) | ||
8 | |||
9 | ignored_text="th_hr Exterieure th_hr Soufflage" | ||
10 | |||
11 | ignored_bat="^$" | ||
12 | ignored="^(th_hr Exterieure|th_hr Soufflage)$" | ||
13 | |||
14 | missing() { | ||
15 | echo "to_entries|[.[]|select(.value < \"$alert\" and .key != \"bat\" $1)|.key + \": \" + .value]|join(\" ; \")" | ||
16 | } | ||
17 | |||
18 | missing_check=$(echo "$res" | jq -r "$(missing "and (.key | test(\"$ignored\") | not)")") | ||
19 | missing_show=$(echo "$res" | jq -r "$(missing "")") | ||
20 | |||
21 | battery() { | ||
22 | echo ".bat|to_entries|[.[]|select((.value[0] < \"$alert\" or (.value[1] | test(\"^0|1|2$\") | not)) $1)|.key + \": \" + .value[0] + \" bat \" + .value[1]]|join(\" ; \")" | ||
23 | } | ||
24 | |||
25 | bat_check=$(echo "$res" | jq -r "$(battery "and (.key | test(\"$ignored_bat\") | not)")") | ||
26 | bat_show=$(echo "$res" | jq -r "$(battery "")") | ||
27 | |||
28 | if [ -n "$missing_check" -o -n "$bat_check" ]; then | ||
29 | text="" | ||
30 | if [ -n "$missing_show" ]; then | ||
31 | text="$text - Dernières dates: $missing_show" | ||
32 | fi | ||
33 | if [ -n "$bat_show" ]; then | ||
34 | text="$text - Batteries: $bat_show" | ||
35 | fi | ||
36 | echo "Zibase CRITICAL$text" | ||
37 | exit 2 | ||
38 | else | ||
39 | echo "Zibase OK - Derniers événements il y a moins de 3h (ignorés : $ignored_text)" | ||
40 | exit 0 | ||
41 | fi | ||