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 () { |
|
11 |
nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888" |
|
12 |
} |
|
13 | ||
14 |
function gitprep () { |
|
15 |
nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020" |
|
16 |
} |
|
17 | ||
18 |
function cherrymusic () { |
|
19 |
nc -zw2 127.0.0.1 8080 || echo "injoignable sur port 8080" |
|
20 |
} |
|
21 | ||
ajout du monitoring des diff...
|
22 |
function webapps () { |
réécriture complète de l'aud...
|
23 |
awk -v sq="'" ' |
24 |
/^[^#]+#\s*monitoring\s/ { |
|
25 |
if ($1 == "listen") { |
|
26 |
port = ":" gensub(";", "", "", $2) |
|
27 |
proto = gensub(";", "", "", $3) == "ssl" ? "https" : "http" |
|
28 |
pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/,"", "") |
|
29 |
if (proto == "https" && port == ":443") port = "" |
|
30 |
} |
|
31 |
if ($1 == "server_name") { |
|
32 |
server_name = gensub(";", "", "", $2) |
|
33 |
sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/,"", "") |
|
34 |
} |
|
35 |
if ($1 == "location" && sname != "" && pname != "" && sname == pname) { |
|
36 |
l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "") |
|
37 |
split(l, location, /\s*,\s*/) |
|
38 |
if (location[2] == sname) { |
|
39 |
monitoring[location[2]][location[1]]["monitoring"] = location[3] |
|
40 |
monitoring[location[2]][location[1]]["response_code"] = location[4] |
|
41 |
monitoring[location[2]][location[1]]["url"] = proto "://" server_name port location[1] location[5] |
|
42 |
if (location[6] != "") |
|
43 |
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq location[6] sq |
|
44 |
else |
|
45 |
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq "Mozilla/5 (monitoring)" sq |
|
46 |
} |
|
47 |
} |
|
48 |
} |
|
49 |
END { |
|
50 |
for (mid in monitoring) { |
|
51 |
for (locid in monitoring[mid]) { |
|
52 |
curl = sprintf("curl --silent --max-time 2 --output /dev/null --write-out %{response_code} --output /dev/null %s %s", |
|
53 |
monitoring[mid][locid]["user-agent"], |
|
54 |
monitoring[mid][locid]["url"]) |
|
55 |
curl | getline response_code |
|
56 |
close(curl) |
|
57 |
if (response_code != monitoring[mid][locid]["response_code"]) |
|
58 |
printf("%s (%s)\n", monitoring[mid][locid]["monitoring"], response_code) |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
' /etc/nginx/sites-enabled/* |
|
ajout du monitoring des diff...
|
63 |
} |
64 | ||
ajout de la supervision
|
65 |
function core_temp () { |
66 |
local min=60 |
|
67 |
local level=("warning" "severe" "danger!") |
|
68 |
local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) )) |
|
69 |
if test $step -gt 0; then |
|
70 |
step=$((step / 10000)) |
|
71 |
test $step -le 3 || step=2 |
|
72 |
echo "${level[step]}: température > $((min + step * 10))°" |
|
73 |
fi |
|
74 |
} |
|
75 | ||
76 |
function core_alim () { |
|
77 |
eval $(/opt/vc/bin/vcgencmd measure_volts core) |
|
78 |
test $volt == "1.2000V" || echo "$volt" |
|
79 |
} |
|
80 | ||
81 |
function load_avg () { |
|
82 |
local procs=4 |
|
83 |
local load=($(</proc/loadavg)) |
|
84 |
local avg=(1 5 15) |
|
85 |
for ((i=0; i<${#avg[@]}; i++)); do |
|
86 |
test ${load[i]%.*} -ge $procs && echo "charge moyenne à ${avg[i]}min = ${load[i]}" |
|
87 |
done |
|
88 |
} |
|
89 | ||
90 |
function mem_pressure () { |
|
91 |
local meminfo=($(</proc/meminfo)) |
|
92 |
local level=(danger severe warning) |
|
93 |
local margin=30000 |
|
94 |
for ((i=0; i<${#meminfo[@]}; i+=3)); do |
|
95 |
test ${meminfo[i]} == 'MemAvailable:' && break |
|
96 |
done |
|
97 |
meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 )) |
|
98 |
test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB" |
|
99 |
} |
|
100 | ||
101 |
function mpd_tablette () { |
|
102 |
local tablette=192.168.0.53 |
|
103 |
local port=6600 |
|
MPD remonte le montage NFS à...
|
104 |
local media='/media/musique' |
105 |
# local nfs=$(ss -no state established 'sport = :nfs' dst $tablette | grep -c $) |
|
ajout de la supervision
|
106 |
test $nfs -lt 3 && echo "tablette non connectée à la zique" |
107 |
nc -zw2 $tablette $port || echo "MPD injoignable" |
|
MPD remonte le montage NFS à...
|
108 |
test $(showmount --all --no-headers | grep $tablette:$media) -eq 1 || echo "$media pas exporté" |
ajout de la supervision
|
109 |
} |