aa233af 3 years ago
1 contributor
55 lines | 1.94kb
# vim: ft=sh

function nginx () {
    nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local"
    nc -zw2 paris12.pcf.fr 80 || echo "injoignable sur port 80 distant"
    nc -zw2 paris12.pcf.fr 443 || echo "injoignable sur port 443 distant"
}

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 1; then
#    if test $step -gt 5000; then # en été il fait plus chaud, c'est normal que ça monte à 60° régulièrement
        step=$((step / 10000))
        test $step -le 2 || step=2
        echo "${level[step]}: température > $((min + step * 10))°"
    fi
}

function core_alim () {
    eval $(/opt/vc/bin/vcgencmd measure_volts core)
    volt_fmt=${volt/\.}
    volt_fmt=${volt_fmt/V}
    test $volt_fmt -lt 12000 -o $volt_fmt -gt 15000 && 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 printer () {
    _turn 24 || return
    local min=20
    local level=(extreme danger warning info)
    local printer=192.168.1.54
    local prtMarkerSuppliesMaxCapacity=1.3.6.1.2.1.43.11.1.1.8.1
    local prtMarkerSuppliesLevel=1.3.6.1.2.1.43.11.1.1.9.1
    local left=$(snmpget -v 1 -c public $printer ${prtMarkerSuppliesLevel}.4)
    local full=$(snmpget -v 1 -c public $printer ${prtMarkerSuppliesMaxCapacity}.4)

    if test ${full#*:} -ne 0; then
        local step=$(((${left#*:}*100/${full#*:})/5))
        if test $step -le ${#level[@]}; then
            echo "${level[$step]} toner black"
        fi
    fi
}