# 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=$(( $( $((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=($(