Benutzer-Werkzeuge

Webseiten-Werkzeuge


public:checkmk:local-temp-check

Beta version local Temp Check for CheckMK

generate file

/usr/lib/check_mk_agent/local/501_hw_sensors


make it executable

Content:
#!/bin/bash
 
CPU_WARN=85
CPU_CRIT=95
BOARD_WARN=80
BOARD_CRIT=90
NIC_WARN=90
NIC_CRIT=100
 
SENSORS_BIN="/usr/bin/sensors"
[ -x "$SENSORS_BIN" ] || exit 0
 
out="$("$SENSORS_BIN" 2>/dev/null)"
[ -n "$out" ] || exit 0
 
cpu_temp=""
board_temp=""
nic_temp=""
nic_name=""
 
extract_temp_from_line() {
    sed -nE 's/^[^:]+:[[:space:]]*\+?([0-9]+(\.[0-9]+)?).*/\1/p'
}
 
emit_temp_check() {
    service_name="$1"
    temp_value="$2"
    warn_value="$3"
    crit_value="$4"
    summary="$5"
 
    [ -n "$temp_value" ] || return 0
 
    temp_int="${temp_value%.*}"
    [ -n "$temp_int" ] || return 0
 
    state=0
    if [ "$temp_int" -ge "$crit_value" ]; then
        state=2
    elif [ "$temp_int" -ge "$warn_value" ]; then
        state=1
    fi
 
    echo "$state \"$service_name\" temp=${temp_int};${warn_value};${crit_value} $summary - ${temp_int}C"
}
 
cpu_temp="$(printf '%s\n' "$out" | awk '
    /^Package id 0:/ { print; exit }
' | extract_temp_from_line)"
 
if [ -z "$cpu_temp" ]; then
    cpu_temp="$(printf '%s\n' "$out" | awk '
        /^Tctl:/ { print; exit }
    ' | extract_temp_from_line)"
fi
 
if [ -z "$cpu_temp" ]; then
    cpu_temp="$(printf '%s\n' "$out" | awk '
        /^Tdie:/ { print; exit }
    ' | extract_temp_from_line)"
fi
 
if [ -z "$cpu_temp" ]; then
    cpu_temp="$(printf '%s\n' "$out" | awk '
        /^Physical id 0:/ { print; exit }
    ' | extract_temp_from_line)"
fi
 
board_temp="$(printf '%s\n' "$out" | awk '
    /^acpitz-acpi-0$/ { in_block=1; next }
    in_block && /^temp1:/ { print; exit }
    /^$/ { in_block=0 }
' | extract_temp_from_line)"
 
while IFS= read -r line; do
    case "$line" in
        *-mdio-*|*r8169*|*igc*|*e1000*|*mlx*|*atlantic*|*bnx*|*tg3*)
            current_block="$line"
            in_nic_block=1
            ;;
        "")
            in_nic_block=0
            current_block=""
            ;;
        temp1:*)
            if [ "${in_nic_block:-0}" -eq 1 ] && [ -z "$nic_temp" ]; then
                nic_temp="$(printf '%s\n' "$line" | extract_temp_from_line)"
                nic_name="$current_block"
            fi
            ;;
    esac
done <<< "$out"
 
emit_temp_check "CPU Package Temperature" "$cpu_temp" "$CPU_WARN" "$CPU_CRIT" "CPU package"
emit_temp_check "Board Temperature" "$board_temp" "$BOARD_WARN" "$BOARD_CRIT" "Board/ACPI"
 
if [ -n "$nic_temp" ]; then
    emit_temp_check "NIC Temperature" "$nic_temp" "$NIC_WARN" "$NIC_CRIT" "${nic_name:-NIC}"
fi

reinitilize service scan of host

Enjoy!

public/checkmk/local-temp-check.txt · Zuletzt geändert: von gerson

Seiten-Werkzeuge