scripts / monitoring.d / raspberrypi /
715e9aa 7 years ago
1 contributor
91 lines | 3.139kb
# 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 () {
    nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888"
}

function gitprep () {
    nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020"
}

function cherrymusic () {
    nc -zw2 127.0.0.1 8080 || echo "injoignable sur port 8080"
}

function webapps () {
    local webapps_conf="$dir/${HOSTNAME}.webapps.conf"
    if test -r $webapps_conf; then
        local useragent=
        local host=
        local proto=
        local webapps=()
        local no_access=()
        eval "$(< $webapps_conf)"
        test -z "$useragent" && echo "manque user-agent" && return
        test -z "$host" && echo "manque hôte" && return
        test -z "$proto" && echo "manque protocole" && return
        test $(( ${#webapps[@]} % 3 )) -ne 0 && echo "mauvais nombre de paramètres de tests" && return
        for ((i=0; i<${#webapps[@]}; i+=3)); do
            http_response=$(curl --silent --max-time 2 --user-agent "$useragent" --output /dev/null --write-out "%{response_code}" $proto://$host/${webapps[i]})
            test $http_response -ne ${webapps[i+2]} && no_access[${#no_access[@]}]="${webapps[i+1]} ($http_response)"
        done
        if test ${#no_access[@]} -ne 0; then
            echo "réponse incorrecte: ${no_access[@]}"
        fi
    else
        echo "pas de conf! ($webapps_conf)"
    fi
}

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 load_avg () {
    local procs=4
    local load=($(</proc/loadavg))
    local avg=(1 5 15)
    for ((i=0; i<${#avg[@]}; i++)); do
        test ${load[i]%.*} -ge $procs && echo "charge moyenne à ${avg[i]}min = ${load[i]}"
    done
}

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 3 && echo "tablette non connectée à la zique"
    nc -zw2 $tablette $port || echo "MPD injoignable"
    test $(showmount --all --no-headers | grep $tablette:$media) -eq 1 || echo "$media pas exporté"
}