ajout de la supervision
|
1 |
# vim: ft=sh |
2 | ||
3 |
function _systemctl () { |
|
4 |
test -n "$1" || return |
|
5 |
eval $(systemctl show $1 | egrep '^(ExecMainStatus|Result|ActiveState|SubState|Type)=') |
|
6 |
if test -n "$Type"; then |
|
7 |
test $ExecMainStatus -eq 0 \ |
|
8 |
&& test $Result = 'success' \ |
|
9 |
&& test $ActiveState = 'active' \ |
|
10 |
&& [[ ( $Type =~ ^(simple|forking|notify)$ && $SubState = 'running' ) || ( $Type = 'oneshot' && $SubState = 'exited' ) ]] \ |
|
11 |
|| echo "état du service anormal" |
|
12 |
else |
|
13 |
echo "service $1 inexistant" |
|
14 |
fi |
|
15 |
} |
|
16 | ||
17 |
function sys_state () { |
|
18 |
local failed_units= |
|
19 |
eval $(systemctl show | egrep '^(SystemState|NFailedUnits)=') |
|
20 |
if test $SystemState != "running" -o $NFailedUnits -ne 0; then |
|
quelques corrections sur la ...
|
21 |
echo "$SystemState mode ($NFailedUnits units failed):" |
22 |
echo "$(systemctl --failed --no-legend | awk ' |
|
ajout de la supervision
|
23 |
{ |
24 |
split($1, units, ".") |
|
25 |
failed[units[2]][units[1]]=1 |
|
26 |
numfailed[units[2]]++ |
|
27 |
} |
|
28 |
END { |
|
29 |
for (ut in failed) { |
|
quelques corrections sur la ...
|
30 |
print ut |
ajout de la supervision
|
31 |
for (un in failed[ut]) { |
32 |
last = --numfailed[ut] == 0 ? 1 : 0 |
|
quelques corrections sur la ...
|
33 |
print last ? "└─" : "├─", un |
ajout de la supervision
|
34 |
} |
35 |
} |
|
quelques corrections sur la ...
|
36 |
}')" |
ajout de la supervision
|
37 |
fi |
38 |
} |
|
ajout d'un test de mise à jo...
|
39 | |
ajout d'une fonction de test
|
40 |
function autotest () { |
41 |
local testfile=/dev/shm/monitoring.autotest |
|
42 |
test -e $testfile && echo "it works" && rm -f $testfile |
|
ajout d'un test de mise à jo...
|
43 |
} |
monitoring des cerificats
|
44 | |
45 |
function certificates () { |
|
vérification des certificats...
|
46 |
_turn 24 || return |
monitoring des cerificats
|
47 |
for domain in /etc/letsencrypt/live/*; do |
48 |
local notAfter="$(openssl x509 -enddate -noout -in $domain/fullchain.pem)" |
|
49 |
local enddate=$(date +%s -d"${notAfter#*=}") |
|
50 |
local delay=$(date +%_j -d@$(($enddate - $now))) |
|
51 |
if test $delay -lt 10; then |
|
52 |
echo "${domain##*/} expire dans $delay jours" |
|
53 |
fi |
|
54 |
done |
|
55 |
} |
|
déplacement de l'autit de ch...
|
56 | |
57 |
function load_avg () { |
|
58 |
local procs=$(grep -c "^processor" /proc/cpuinfo) |
|
59 |
local load=($(</proc/loadavg)) |
|
60 |
local avg=(1 5 15) |
|
61 |
for ((i=0; i<${#avg[@]}; i++)); do |
|
62 |
test ${load[i]%.*} -ge $procs && echo "charge moyenne à ${avg[i]}min = ${load[i]}" |
|
63 |
done |
|
64 |
} |
|
déplacement de fonction pour...
|
65 | |
66 |
function upgrades () { |
|
67 |
local log="/var/log/unattended-upgrades/unattended-upgrades.log" |
|
68 |
test -r $log || return |
|
69 |
local lastline=$(tail -1 $log) |
|
70 |
local lastentry=$(date +%s -d "$(cut -f1,2 -d' ' <<< $lastline)") |
|
71 |
test -n "$lastentry" || return |
|
72 |
local status=$(cut -f3 -d' ' <<< $lastline) |
|
73 |
test $(($lastentry + 86400)) -lt $now && echo "pas de mise à jour depuis le ${lastline%% *}" |
|
74 |
} |