ajout de la supervision
|
1 |
# vim: ft=sh |
ajout du monitoring des diff...
|
2 |
dir=$1 |
ajout de la supervision
|
3 | |
4 |
function nginx () { |
|
5 |
nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local" |
|
6 |
nc -zw2 sebmarque.hd.free.fr 80 || echo "injoignable sur port 80 distant" |
|
7 |
nc -zw2 sebmarque.hd.free.fr 443 || echo "injoignable sur port 443 distant" |
|
8 |
} |
|
9 | ||
10 |
function searx () { |
|
espace les tests des applis
|
11 |
_turn 5 || return |
ajout de la supervision
|
12 |
nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888" |
13 |
} |
|
14 | ||
15 |
function gitprep () { |
|
espace les tests des applis
|
16 |
_turn 5 || return |
ajout de la supervision
|
17 |
nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020" |
18 |
} |
|
19 | ||
ajout du monitoring des diff...
|
20 |
function webapps () { |
espace les tests des applis
|
21 |
_turn 3 || return # test toutes les 3 heures |
réécriture complète de l'aud...
|
22 |
awk -v sq="'" ' |
23 |
/^[^#]+#\s*monitoring\s/ { |
|
24 |
if ($1 == "listen") { |
|
fix gensub/awk warning
|
25 |
port = ":" gensub(";", "", "1", $2) |
26 |
proto = gensub(";", "", "1", $3) == "ssl" ? "https" : "http" |
|
avertissement gensub sur 3èm...
|
27 |
pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/, "1", "1") |
réécriture complète de l'aud...
|
28 |
if (proto == "https" && port == ":443") port = "" |
29 |
} |
|
30 |
if ($1 == "server_name") { |
|
fix gensub/awk warning
|
31 |
server_name = gensub(";", "", "1", $2) |
avertissement gensub sur 3èm...
|
32 |
sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/, "1", "1") |
réécriture complète de l'aud...
|
33 |
} |
34 |
if ($1 == "location" && sname != "" && pname != "" && sname == pname) { |
|
fix gensub/awk warning
|
35 |
l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "1") |
réécriture complète de l'aud...
|
36 |
split(l, location, /\s*,\s*/) |
37 |
if (location[2] == sname) { |
|
38 |
monitoring[location[2]][location[1]]["monitoring"] = location[3] |
|
39 |
monitoring[location[2]][location[1]]["response_code"] = location[4] |
|
40 |
monitoring[location[2]][location[1]]["url"] = proto "://" server_name port location[1] location[5] |
|
41 |
if (location[6] != "") |
|
42 |
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq location[6] sq |
|
43 |
else |
|
44 |
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq "Mozilla/5 (monitoring)" sq |
|
45 |
} |
|
46 |
} |
|
47 |
} |
|
48 |
END { |
|
49 |
for (mid in monitoring) { |
|
50 |
for (locid in monitoring[mid]) { |
|
51 |
curl = sprintf("curl --silent --max-time 2 --output /dev/null --write-out %{response_code} --output /dev/null %s %s", |
|
52 |
monitoring[mid][locid]["user-agent"], |
|
53 |
monitoring[mid][locid]["url"]) |
|
54 |
curl | getline response_code |
|
55 |
close(curl) |
|
ne considère pas le code ret...
|
56 |
if (response_code != monitoring[mid][locid]["response_code"] && response_code != "000") |
réécriture complète de l'aud...
|
57 |
printf("%s (%s)\n", monitoring[mid][locid]["monitoring"], response_code) |
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
' /etc/nginx/sites-enabled/* |
|
ajout du monitoring des diff...
|
62 |
} |
63 | ||
ajoute monitoring extérieur ...
|
64 |
function section () { |
65 |
nc -zw5 cloud.paris12.pcf.fr 443 || echo "cloud inaccessible" |
|
66 |
nc -zw5 cloud.paris12.pcf.fr 2200 || echo "section inaccessible" |
|
67 |
} |
|
68 | ||
ajout de la supervision
|
69 |
function core_temp () { |
70 |
local min=60 |
|
71 |
local level=("warning" "severe" "danger!") |
|
72 |
local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) )) |
|
c'est bientôt l'été
|
73 |
# if test $step -gt 1; then |
74 |
if test $step -gt 5000; then # en été il fait plus chaud, c'est normal que ça monte à 60° régulièrement |
|
ajout de la supervision
|
75 |
step=$((step / 10000)) |
fix typo
|
76 |
test $step -le 2 || step=2 |
ajout de la supervision
|
77 |
echo "${level[step]}: température > $((min + step * 10))°" |
78 |
fi |
|
79 |
} |
|
80 | ||
81 |
function core_alim () { |
|
82 |
eval $(/opt/vc/bin/vcgencmd measure_volts core) |
|
improve volatge check
|
83 |
volt_fmt=${volt/\.} |
84 |
volt_fmt=${volt_fmt/V} |
|
85 |
test $volt_fmt -lt 12000 -o $volt_fmt -gt 15000 && echo "$volt" |
|
ajout de la supervision
|
86 |
} |
87 | ||
refresh swap if possible
|
88 |
function clean_swap () { |
89 |
_turn 2 || return |
|
libère le cache plus réguliè...
|
90 |
echo 1 > /proc/sys/vm/drop_caches |
91 |
if LANG=C free -m | awk ' |
|
refresh swap if possible
|
92 |
/^Swap:/ { |
93 |
used = $3 |
|
94 |
} |
|
95 |
END { |
|
fix bad return code
|
96 |
bash_exit_code = !(used > 62) |
97 |
exit bash_exit_code |
|
refresh swap if possible
|
98 |
} |
99 |
'; then |
|
100 |
systemctl stop dphys-swapfile \ |
|
101 |
&& systemctl stop zram \ |
|
102 |
&& systemctl start zram \ |
|
103 |
&& systemctl start dphys-swapfile \ |
|
104 |
|| echo 'erreur' |
|
105 |
fi |
|
106 |
} |
|
107 | ||
ajout de la supervision
|
108 |
function mem_pressure () { |
109 |
local meminfo=($(</proc/meminfo)) |
|
110 |
local level=(danger severe warning) |
|
111 |
local margin=30000 |
|
112 |
for ((i=0; i<${#meminfo[@]}; i+=3)); do |
|
113 |
test ${meminfo[i]} == 'MemAvailable:' && break |
|
114 |
done |
|
115 |
meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 )) |
|
116 |
test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB" |
|
117 |
} |
|
118 | ||
vérifie existence d'albums p...
|
119 |
function piwigo_private () { |
120 |
_turn 20 || return |
|
121 |
test "$(curl --silent 'http://192.168.0.71/photos/ws.php?format=json&method=pwg.categories.getList' | sum)" = "00569 1" || echo "albums visibles publiquement" |
|
ajout de la supervision
|
122 |
} |
ajout vérification de nouvel...
|
123 | |
124 |
function snappymail_version () { |
|
125 |
_turn 24 || return |
|
126 |
local installed_version=$(</var/www/rainloop/data/VERSION) |
|
127 |
local release_url='https://api.github.com/repos/the-djmaze/snappymail/releases/latest' |
|
128 |
local version=$(curl -sL -H "Accept: application/vnd.github+json" $release_url | jq -r '.name | ltrimstr("v")') |
|
129 |
if test $version != $installed_version; then |
|
130 |
echo "nouvelle version dispo: $version" |
|
131 |
fi |
|
132 |
} |
|
133 | ||
134 |
function navidrome_version () { |
|
135 |
_turn 24 || return |
|
136 |
local installed_version=$(find ~navidrome/navidrome -printf "%C@") |
|
137 |
local release_url='https://api.github.com/repos/navidrome/navidrome/releases/latest' |
|
138 |
local version=$(curl -sL -H "Accept: application/vnd.github+json" $release_url \ |
|
139 |
| jq -r '.assets | .[] | select(.name | contains("linux_armv7")) | .updated_at | fromdateiso8601') |
|
140 |
if test $version -gt ${installed_version%.*}; then |
|
141 |
echo "nouvelle version dispo" |
|
142 |
fi |
|
143 |
} |