1 contributor
# vim: ft=sh
dir=$1
function nginx () {
nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local"
nc -zw2 sebmarque.hd.free.fr 80 || echo "injoignable sur port 80 distant"
nc -zw2 sebmarque.hd.free.fr 443 || echo "injoignable sur port 443 distant"
}
function searx () {
_turn 5 || return
nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888"
}
function gitprep () {
_turn 5 || return
nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020"
}
function webapps () {
_turn 3 || return # test toutes les 3 heures
awk -v sq="'" '
/^[^#]+#\s*monitoring\s/ {
if ($1 == "listen") {
port = ":" gensub(";", "", "", $2)
proto = gensub(";", "", "", $3) == "ssl" ? "https" : "http"
pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/,"", "")
if (proto == "https" && port == ":443") port = ""
}
if ($1 == "server_name") {
server_name = gensub(";", "", "", $2)
sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/,"", "")
}
if ($1 == "location" && sname != "" && pname != "" && sname == pname) {
l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "")
split(l, location, /\s*,\s*/)
if (location[2] == sname) {
monitoring[location[2]][location[1]]["monitoring"] = location[3]
monitoring[location[2]][location[1]]["response_code"] = location[4]
monitoring[location[2]][location[1]]["url"] = proto "://" server_name port location[1] location[5]
if (location[6] != "")
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq location[6] sq
else
monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq "Mozilla/5 (monitoring)" sq
}
}
}
END {
for (mid in monitoring) {
for (locid in monitoring[mid]) {
curl = sprintf("curl --silent --max-time 2 --output /dev/null --write-out %{response_code} --output /dev/null %s %s",
monitoring[mid][locid]["user-agent"],
monitoring[mid][locid]["url"])
curl | getline response_code
close(curl)
if (response_code != monitoring[mid][locid]["response_code"] && response_code != "000")
printf("%s (%s)\n", monitoring[mid][locid]["monitoring"], response_code)
}
}
}
' /etc/nginx/sites-enabled/*
}
function core_temp () {
local min=60
local level=("warning" "severe" "danger!")
local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) ))
if test $step -gt 0; then
step=$((step / 10000))
test $step -le 3 || step=2
echo "${level[step]}: température > $((min + step * 10))°"
fi
}
function core_alim () {
eval $(/opt/vc/bin/vcgencmd measure_volts core)
test $volt == "1.2000V" || echo "$volt"
}
function mem_pressure () {
local meminfo=($(</proc/meminfo))
local level=(danger severe warning)
local margin=30000
for ((i=0; i<${#meminfo[@]}; i+=3)); do
test ${meminfo[i]} == 'MemAvailable:' && break
done
meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 ))
test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB"
}
function mpd_tablette () {
local tablette=192.168.0.53
local port=6600
local media='/media/musique'
local nfs=$(ss -no state established 'sport = :nfs' dst $tablette | grep -c $)
test $nfs -lt 2 && echo "tablette non connectée à la zique"
nc -zw2 $tablette $port || echo "MPD injoignable"
test $(showmount --all --no-headers | grep -c $tablette:$media) -eq 1 || echo "$media pas exporté"
}