# vim: ft=sh function _systemctl () { test -n "$1" || return eval $(systemctl show $1 | egrep '^(ExecMainStatus|Result|ActiveState|SubState|Type)=') if test -n "$Type"; then test $ExecMainStatus -eq 0 \ && test $Result = 'success' \ && test $ActiveState = 'active' \ && [[ ( $Type =~ ^(simple|forking|notify)$ && $SubState = 'running' ) || ( $Type = 'oneshot' && $SubState = 'exited' ) ]] \ || echo "état du service anormal" else echo "service $1 inexistant" fi } function sys_state () { local failed_units= eval $(systemctl show | egrep '^(SystemState|NFailedUnits)=') if test $SystemState != "running" -o $NFailedUnits -ne 0; then echo "$SystemState mode ($NFailedUnits units failed):" echo "$(systemctl --failed --no-legend | awk ' { split($1, units, ".") failed[units[2]][units[1]]=1 numfailed[units[2]]++ } END { for (ut in failed) { print ut for (un in failed[ut]) { last = --numfailed[ut] == 0 ? 1 : 0 print last ? "└─" : "├─", un } } }')" fi } function autotest () { local testfile=/dev/shm/monitoring.autotest test -e $testfile && echo "it works" && rm -f $testfile } function certificates () { _turn 24 || return for domain in /etc/letsencrypt/live/*; do local notAfter="$(openssl x509 -enddate -noout -in $domain/fullchain.pem)" local enddate=$(date +%s -d"${notAfter#*=}") local delay=$(date +%_j -d@$(($enddate - $now))) if test $delay -lt 10; then echo "${domain##*/} expire dans $delay jours" fi done } function load_avg () { local procs=$(grep -c "^processor" /proc/cpuinfo) local load=($(