#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Copyright (c) 2026 hostspezial GmbH # # ============================================================================= # pve-multipath-check # # Prüft eine handgepflegte Multipath-Konfiguration, bevor ein Proxmox-VE- # Cluster auf das von Proxmox VE 9.3 verwaltete Multipath umgestellt wird # (Rechenzentrum → SAN, /etc/pve/multipath.cfg). # # Version 1.0.0 (Datenstand 2026-11-25) # Herausgeber hostspezial GmbH · https://www.hostspezial.de # Kontakt mh@hostspezial.de # Hintergrund https://www.hostspezial.de/aktuelles/proxmox-ve-9-3-san-ansicht-multipath-nvme-of.html # ----------------------------------------------------------------------------- # ZUSAGE # Das Skript liest ausschließlich. Es ändert keine Datei, startet keinen # Dienst neu und legt in Proxmox VE nichts an. Der Modus "plan" gibt Befehle # aus, führt sie aber nicht aus. # # GRENZEN # Die Befunde ersetzen keinen Test. Eine Umstellung gehört zuerst in eine # Testumgebung, dann Knoten für Knoten in ein Wartungsfenster. Vorgaben des # Herstellers Ihres Speichersystems gehen vor. Nutzung ohne Gewähr. # # VORAUSSETZUNGEN # bash >= 4.4, awk, coreutils. Für die Prüfung des laufenden Zustands # zusätzlich root-Rechte sowie (soweit vorhanden) multipath, pvesh, nvme. # ============================================================================= # shellcheck disable=SC1111 # typografische Anführungszeichen in Meldungen sind gewollt if [ -z "${BASH_VERSINFO:-}" ] || [ "${BASH_VERSINFO[0]}" -lt 4 ] || { [ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -lt 4 ]; }; then echo "pve-multipath-check benötigt bash >= 4.4." >&2 exit 3 fi set -Eeuo pipefail shopt -s nullglob export LC_ALL=C.UTF-8 export PATH="${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin" # ----------------------------------------------------------------- Konstanten readonly PROG="pve-multipath-check" readonly VERSION="1.0.0" readonly DATA_DATE="2026-11-25" readonly BLOG_URL="https://www.hostspezial.de/aktuelles/proxmox-ve-9-3-san-ansicht-multipath-nvme-of.html" readonly EXIT_OK=0 # nichts Kritisches gefunden readonly EXIT_WARN=1 # Warnungen readonly EXIT_CONFLICT=2 # Kollision mit dem verwalteten Multipath readonly EXIT_USAGE=3 # Aufruf- oder Laufzeitfehler # Beliebige WWID, mit der Blacklist-Muster auf "trifft alles" geprüft werden. readonly PROBE_WWID="36000000000000000000000000000beef" # Ab dieser Wartezeit (Sekunden) gilt replacement_timeout als auffällig. # Vorgabe von open-iscsi sind 120, das Proxmox-Wiki empfiehlt 15. readonly RT_THRESHOLD=60 # Feldtrenner für interne Datensätze (Unit Separator) readonly SEP=$'\x1f' # -------------------------------------------------------------------- Zustand MODE="check" # check | plan FORMAT="text" # text | json OPT_ROOT="" # --root: kopierter Dateibaum OPT_CONF="" # --conf: einzelne multipath.conf USE_COLOR=1 WIDTH="" # Umbruchbreite; leer = automatisch, 0 = kein Umbruch OFFLINE=0 # 1 = nur Dateien lesen, keine Befehle des Knotens declare -a F_LEVEL=() F_ID=() F_TEXT=() # Befunde declare -i WORST=0 declare -a CONF_FILES=() # ausgewertete eigene Konfigurationsdateien declare -a BL_WWID=() BL_DEVNODE=() EX_WWID=() declare -a DEV_BLOCKS=() # "BlocknummerSchlüsselWert" declare -A MP_ALIAS=() # WWID -> Alias aus multipaths { } declare -i BL_HAS_DEVICE=0 DEV_COUNT=0 DEF_FIND_MULTIPATHS="" DEF_USER_FRIENDLY="" declare -A PVE_ENTRY=() # WWID -> "Alias|paths-expected" declare -A LIVE_MAP=() # WWID -> "Name|aktive Pfade|Pfade gesamt" declare -a SAN_NODES=() # Knoten laut SAN-Status: Name, Zustand, Zusatz declare -a SAN_LUNS=() # LUN je Knoten laut SAN-Status (Felder siehe collect_san_status) declare -A SAN_MANAGED=() # WWID -> "eintrag" | "storage:" | "nativ" declare -i CONF_ONLY=0 # 1 = nur die mit --conf genannte Datei auswerten PVE_VERSION="" MANAGED="unbekannt" # ja | nein | unbekannt # --------------------------------------------------------------- Hilfsfunktionen die() { printf '%s: %s\n' "${PROG}" "$*" >&2 exit "${EXIT_USAGE}" } # shellcheck disable=SC2317 # wird über die ERR-Falle aufgerufen on_error() { # 141 = Leser hat die Ausgabe geschlossen (z. B. "| head"): still beenden. if [ "$2" -eq 141 ]; then exit 141; fi printf '%s: unerwarteter Fehler in Zeile %s (Rückgabewert %s). Bitte mit --help prüfen oder melden: mh@hostspezial.de\n' \ "${PROG}" "$1" "$2" >&2 exit "${EXIT_USAGE}" } trap 'on_error "${LINENO}" "$?"' ERR usage() { cat </dev/null 2>&1 } # Befund aufnehmen: add_finding STUFE KENNUNG TEXT add_finding() { F_LEVEL+=("$1") F_ID+=("$2") F_TEXT+=("$3") case "$1" in KOLLISION) WORST=${EXIT_CONFLICT} ;; WARNUNG) if [ "${WORST}" -lt "${EXIT_WARN}" ]; then WORST=${EXIT_WARN}; fi ;; *) ;; esac } # Passt TEXT auf den regulären Ausdruck RE? Wie multipath: POSIX-ERE, unverankert. re_match() { RE="$1" TXT="$2" awk 'BEGIN { exit !(ENVIRON["TXT"] ~ ENVIRON["RE"]) }' 2>/dev/null } is_wwid() { [[ "$1" =~ ^[0-9a-fA-F]{16,}$ ]] } is_uint() { [[ "$1" =~ ^[0-9]+$ ]] } json_escape() { local s="$1" s="${s//\\/\\\\}" s="${s//\"/\\\"}" s="${s//$'\n'/\\n}" s="${s//$'\t'/ }" printf '%s' "${s}" } # ------------------------------------------------------------------- Argumente parse_args() { while [ $# -gt 0 ]; do case "$1" in check|plan) MODE="$1" ;; --conf) [ $# -ge 2 ] || die "--conf braucht eine Datei." OPT_CONF="$2"; shift ;; --conf=*) OPT_CONF="${1#*=}" ;; --root) [ $# -ge 2 ] || die "--root braucht ein Verzeichnis." OPT_ROOT="$2"; shift ;; --root=*) OPT_ROOT="${1#*=}" ;; --format) [ $# -ge 2 ] || die "--format braucht text oder json." FORMAT="$2"; shift ;; --format=*) FORMAT="${1#*=}" ;; --json) FORMAT="json" ;; --no-color) USE_COLOR=0 ;; --width) [ $# -ge 2 ] || die "--width braucht eine Zahl." WIDTH="$2"; shift ;; --width=*) WIDTH="${1#*=}" ;; -V|--version) printf '%s %s (Datenstand %s)\n' "${PROG}" "${VERSION}" "${DATA_DATE}"; exit "${EXIT_OK}" ;; -h|--help) usage; exit "${EXIT_OK}" ;; *) die "unbekanntes Argument „$1“ (Hilfe: --help)" ;; esac shift done case "${FORMAT}" in text|json) ;; *) die "unbekanntes Format „${FORMAT}“ (erlaubt: text, json)" ;; esac if [ -n "${OPT_ROOT}" ] && [ ! -d "${OPT_ROOT}" ]; then die "Verzeichnis nicht gefunden: ${OPT_ROOT}"; fi if [ -n "${OPT_CONF}" ] && [ ! -r "${OPT_CONF}" ]; then die "Datei nicht lesbar: ${OPT_CONF}"; fi if [ -n "${OPT_ROOT}" ] || [ -n "${OPT_CONF}" ]; then OFFLINE=1; fi if [ -n "${OPT_CONF}" ] && [ -z "${OPT_ROOT}" ]; then CONF_ONLY=1; fi if [ ! -t 1 ] || [ -n "${NO_COLOR:-}" ] || [ "${FORMAT}" = "json" ]; then USE_COLOR=0; fi # Umbruch nur am Terminal; in einer Pipe oder Datei bleibt jeder Befund eine Zeile. if [ -z "${WIDTH}" ]; then if [ -t 1 ]; then WIDTH="${COLUMNS:-$(tput cols 2>/dev/null || echo 100)}" if ! is_uint "${WIDTH}" || [ "${WIDTH}" -lt 60 ]; then WIDTH=100; fi if [ "${WIDTH}" -gt 140 ]; then WIDTH=140; fi else WIDTH=0 fi fi is_uint "${WIDTH}" || die "--width braucht eine Zahl (0 = kein Umbruch)." OPT_ROOT="${OPT_ROOT%/}" } check_dependencies() { local tool for tool in awk sort cut fold sed; do command -v "${tool}" >/dev/null 2>&1 || die "benötigtes Programm fehlt: ${tool}" done } # ------------------------------------------------- multipath.conf zerlegen # Gibt je Einstellung eine Zeile aus: # Abschnittspfad, laufende Nummer des Blocks, Schlüssel, Wert # getrennt durch das Zeichen US (0x1f), damit leere Felder erhalten bleiben. # Versteht geschweifte Klammern auf eigener oder derselben Zeile, Kommentare # mit # und ! sowie Werte in Anführungszeichen. parse_multipath_conf() { awk ' function trim(s) { gsub(/^[ \t\r]+|[ \t\r]+$/, "", s); return s } function current_path( i, p) { p = "" for (i = 1; i <= depth; i++) p = p (i > 1 ? "/" : "") sec[i] return p } function emit(line, key, val) { line = trim(line) if (line == "") return key = line; val = "" if (match(line, /[ \t]/)) { key = substr(line, 1, RSTART - 1) val = trim(substr(line, RSTART + 1)) } if (val ~ /^".*"$/) val = substr(val, 2, length(val) - 2) printf "%s\037%d\037%s\037%s\n", current_path(), num[depth], key, val } { line = $0 if (line ~ /^[ \t]*[#!]/) next out = ""; quoted = 0 for (i = 1; i <= length(line); i++) { c = substr(line, i, 1) if (c == "\"") quoted = !quoted if (c == "#" && !quoted) break out = out c } gsub(/\{/, "\n{\n", out) gsub(/\}/, "\n}\n", out) n = split(out, part, "\n") for (k = 1; k <= n; k++) { t = trim(part[k]) if (t == "") continue if (t == "{") { depth++ sec[depth] = trim(pending); pending = "" count[current_path()]++ num[depth] = count[current_path()] } else if (t == "}") { if (pending != "") { emit(pending); pending = "" } if (depth > 0) depth-- } else { if (pending != "") emit(pending) pending = t } } } END { if (pending != "") emit(pending) } ' "$1" } # -------------------------------------------------------------- Daten sammeln collect_own_config() { local main_conf="${OPT_CONF:-${OPT_ROOT}/etc/multipath.conf}" local confd="${OPT_ROOT}/etc/multipath/conf.d" local file path idx key val wwid local -A block_wwid=() block_alias=() if [ -s "${main_conf}" ]; then CONF_FILES+=("${main_conf}"); fi if [ -z "${OPT_CONF}" ] && [ -d "${confd}" ]; then for file in "${confd}"/*.conf; do case "${file##*/}" in pve-*) continue ;; # von Proxmox VE erzeugt, nicht Teil der eigenen Konfiguration *) CONF_FILES+=("${file}") ;; esac done fi for file in "${CONF_FILES[@]}"; do while IFS="${SEP}" read -r path idx key val; do case "${path}" in defaults) case "${key}" in find_multipaths) DEF_FIND_MULTIPATHS="${val}" ;; user_friendly_names) DEF_USER_FRIENDLY="${val}" ;; *) ;; esac ;; blacklist) case "${key}" in wwid) BL_WWID+=("${val}") ;; devnode) BL_DEVNODE+=("${val}") ;; *) ;; esac ;; blacklist/device) BL_HAS_DEVICE=1 ;; blacklist_exceptions) if [ "${key}" = "wwid" ]; then EX_WWID+=("${val}"); fi ;; multipaths/multipath) case "${key}" in wwid) block_wwid["${file}:${idx}"]="${val}" ;; alias) block_alias["${file}:${idx}"]="${val}" ;; *) ;; esac ;; devices/device) DEV_BLOCKS+=("${file##*/}:${idx}"$'\t'"${key}"$'\t'"${val}") ;; *) ;; esac done < <(parse_multipath_conf "${file}") done for key in "${!block_wwid[@]}"; do wwid="${block_wwid[${key}]}" MP_ALIAS["${wwid}"]="${block_alias[${key}]:-}" done if [ "${#DEV_BLOCKS[@]}" -gt 0 ]; then DEV_COUNT="$(printf '%s\n' "${DEV_BLOCKS[@]}" | cut -f1 | sort -u | wc -l)" fi } # Einträge, die Proxmox VE bereits verwaltet (/etc/pve/multipath.cfg) collect_pve_entries() { local cfg="${OPT_ROOT}/etc/pve/multipath.cfg" local line current="" alias expected if [ "${CONF_ONLY}" -eq 1 ] || [ ! -r "${cfg}" ]; then return 0; fi while IFS= read -r line; do case "${line}" in wwid:*) current="${line#wwid:}" current="${current//[[:space:]]/}" PVE_ENTRY["${current}"]="|" ;; *[[:space:]]alias[[:space:]]*) if [ -n "${current}" ]; then alias="$(awk '{ print $2 }' <<<"${line}")" PVE_ENTRY["${current}"]="${alias}|${PVE_ENTRY[${current}]#*|}" fi ;; *[[:space:]]paths-expected[[:space:]]*) if [ -n "${current}" ]; then expected="$(awk '{ print $2 }' <<<"${line}")" PVE_ENTRY["${current}"]="${PVE_ENTRY[${current}]%|*}|${expected}" fi ;; *) ;; esac done < "${cfg}" } # Laufende Multipath-Geräte aus "multipath -ll" collect_live_maps() { local line current="" name active total have multipath || return 0 while IFS= read -r line; do if [[ "${line}" =~ ^([^[:space:]]+)[[:space:]]\(([0-9a-fA-F]{16,})\)[[:space:]]dm-[0-9]+ ]]; then current="${BASH_REMATCH[2]}" LIVE_MAP["${current}"]="${BASH_REMATCH[1]}|0|0" elif [[ "${line}" =~ ^([0-9a-fA-F]{16,})[[:space:]]dm-[0-9]+ ]]; then current="${BASH_REMATCH[1]}" LIVE_MAP["${current}"]="${BASH_REMATCH[1]}|0|0" elif [ -n "${current}" ] && [[ "${line}" =~ [0-9]+:[0-9]+:[0-9]+:[0-9]+[[:space:]]+[[:alnum:]]+[[:space:]]+[0-9]+:[0-9]+[[:space:]]+([a-z]+) ]]; then IFS='|' read -r name active total <<<"${LIVE_MAP[${current}]}" total=$((total + 1)) if [ "${BASH_REMATCH[1]}" = "active" ]; then active=$((active + 1)); fi LIVE_MAP["${current}"]="${name}|${active}|${total}" fi done < <(multipath -ll 2>/dev/null || true) } collect_pve_environment() { if have pveversion; then PVE_VERSION="$(pveversion 2>/dev/null | head -n 1 || true)" fi if have pvesh; then if pvesh get /cluster/san/status --output-format json >/dev/null 2>&1; then MANAGED="ja" else MANAGED="nein" fi fi } # Clusterweiter Zustand aus der SAN-Schnittstelle von Proxmox VE (ab 9.3). # Je Zeile, getrennt durch SEP: # NODE, Knoten, Zustand, weitere Angaben # LUN, WWID, Name, explicit, native, multipath-storage, used-by-storage, # Knoten, paths-active, paths-expected, paths-total, Zustand collect_san_status() { local line kind wwid name explicit native mpstorage usedby rest if [ "${MANAGED}" != "ja" ] || ! have perl; then return 0; fi while IFS= read -r line; do kind="${line%%"${SEP}"*}" case "${kind}" in NODE) SAN_NODES+=("${line#*"${SEP}"}") ;; LUN) SAN_LUNS+=("${line#*"${SEP}"}") IFS="${SEP}" read -r _ wwid name explicit native mpstorage usedby rest <<<"${line}" if [ "${explicit}" = "1" ]; then SAN_MANAGED["${wwid}"]="eintrag" elif [ "${native}" = "1" ]; then SAN_MANAGED["${wwid}"]="nativ" elif [ -n "${mpstorage}" ]; then SAN_MANAGED["${wwid}"]="storage:${mpstorage}" fi ;; *) ;; esac done < <( { pvesh get /cluster/san/status --output-format json 2>/dev/null || true; } | perl -MJSON::PP -e ' local $/; my $d = eval { JSON::PP->new->decode(scalar ) }; exit 0 unless ref $d eq "HASH"; my $sep = "\x1f"; my %skip = map { $_ => 1 } qw(state time iscsi-initiator-name nvme-host-nqn); for my $n (sort keys %{ $d->{nodes} // {} }) { my $s = $d->{nodes}{$n}; my @extra = map { "$_: $s->{$_}" } grep { !ref $s->{$_} && !$skip{$_} } sort keys %$s; print join($sep, "NODE", $n, $s->{state} // "", join("; ", @extra)), "\n"; } for my $l (@{ $d->{luns} // [] }) { for my $n (sort keys %{ $l->{nodes} // {} }) { my $s = $l->{nodes}{$n}; print join($sep, "LUN", $l->{wwid} // "", $l->{name} // $s->{name} // "", $l->{explicit} // 0, $l->{native} // 0, $l->{"multipath-storage"} // "", $l->{"used-by-storage"} // "", $n, $s->{"paths-active"} // "", $s->{"paths-expected"} // "", $s->{"paths-total"} // "", $s->{state} // ""), "\n"; } }' 2>/dev/null || true) } # Zustand laut SAN-Schnittstelle: alle Knoten des Clusters, iSCSI/FC und NVMe. check_san_status() { local row node state extra wwid name explicit native mpstorage usedby active expected total label [ "${#SAN_NODES[@]}" -gt 0 ] || [ "${#SAN_LUNS[@]}" -gt 0 ] || return 0 for row in "${SAN_NODES[@]}"; do IFS="${SEP}" read -r node state extra <<<"${row}" if [ "${state}" = "ok" ]; then add_finding OK san-knoten "Knoten ${node}: Multipath-Einrichtung laut Proxmox VE in Ordnung." elif [[ "${state}" == *error* ]]; then add_finding KOLLISION san-knoten "Knoten ${node} meldet „${state}“${extra:+ (${extra})}. Proxmox VE konnte seine Multipath-Konfiguration dort nicht anwenden; häufigste Ursache ist eine eigene Blacklist." else add_finding WARNUNG san-knoten "Knoten ${node} meldet den Zustand „${state}“${extra:+ (${extra})}." fi done for row in "${SAN_LUNS[@]}"; do IFS="${SEP}" read -r wwid name explicit native mpstorage usedby node active expected total state <<<"${row}" label="${name:-${wwid}}" if [ -n "${usedby}" ]; then label="${label}, Storage ${usedby}"; fi if [ "${state}" = "optimal" ]; then add_finding OK san-lun "${label} auf ${node}: ${active} von ${expected} Pfaden." else add_finding WARNUNG san-lun "${label} auf ${node}: Zustand „${state}“, ${active:-?} von ${expected:-?} erwarteten Pfaden aktiv (${wwid})." fi done } # ------------------------------------------------------------------ Prüfungen check_environment() { local version="${PVE_VERSION:-Version unbekannt}" if [ "${OFFLINE}" -eq 1 ]; then add_finding HINWEIS umgebung "Offline-Prüfung: Es wurden nur Dateien gelesen. Laufende Pfade, Sitzungen und die Proxmox-Version sind nicht geprüft." return 0 fi if [ "${EUID}" -ne 0 ]; then add_finding HINWEIS rechte "Das Skript läuft ohne root-Rechte. multipath, pvesh und Teile von /etc/iscsi sind dann nicht lesbar; die Prüfung ist unvollständig." fi case "${MANAGED}" in ja) add_finding OK umgebung "Verwaltetes Multipath ist auf diesem Knoten verfügbar (${version})." ;; nein) add_finding HINWEIS umgebung "Die SAN-Schnittstelle von Proxmox VE antwortet nicht (${version}). Verwaltetes Multipath gibt es ab Proxmox VE 9.3; die Befunde gelten als Vorbereitung." ;; *) add_finding HINWEIS umgebung "Kein Proxmox VE gefunden (pvesh fehlt). Geprüft wird nur die Multipath-Konfiguration." ;; esac } check_own_config_present() { if [ "${#CONF_FILES[@]}" -eq 0 ]; then add_finding OK eigene-konfig "Keine eigene multipath.conf mit Inhalt gefunden. Der Verwaltung durch Proxmox VE steht von dieser Seite nichts im Weg." else add_finding HINWEIS eigene-konfig "Eigene Multipath-Konfiguration gefunden: ${CONF_FILES[*]}. Sie gilt nur auf diesem Knoten; prüfen Sie jeden Knoten des Clusters einzeln." fi } check_blacklist_wwid() { local pattern catchall="" for pattern in "${BL_WWID[@]}"; do if [ "${pattern}" = "*" ] || re_match "${pattern}" "${PROBE_WWID}"; then catchall="${pattern}" fi done if [ -n "${catchall}" ]; then add_finding KOLLISION blacklist-wwid "blacklist { wwid \"${catchall}\" } schließt jede LUN aus, die nicht in blacklist_exceptions steht. Proxmox VE kann für solche LUNs kein Multipath einrichten; im Labtest stand die betroffene LUN als „missing“ in der SAN-Ansicht. Diese Blacklist muss weg, bevor die Multipath-Option eingeschaltet wird." if [ "${#EX_WWID[@]}" -gt 0 ]; then add_finding HINWEIS blacklist-ausnahmen "${#EX_WWID[@]} WWID(s) stehen heute als Ausnahme in der Datei: ${EX_WWID[*]}. Diese LUNs gehören als Einträge in die Proxmox-Verwaltung (Modus plan)." fi elif [ "${#BL_WWID[@]}" -gt 0 ]; then add_finding HINWEIS blacklist-wwid "Die Blacklist nennt einzelne WWIDs (${BL_WWID[*]}). Prüfen Sie, dass keine LUN darunter ist, die Proxmox VE verwalten soll." fi } check_blacklist_devnode() { local pattern probe hits for pattern in "${BL_DEVNODE[@]}"; do hits="" for probe in sdb sdaa nvme0n1; do if re_match "${pattern}" "${probe}"; then hits="${hits} ${probe}"; fi done if [ -n "${hits}" ]; then add_finding WARNUNG blacklist-devnode "blacklist { devnode \"${pattern}\" } trifft Gerätenamen wie${hits}. Damit sind SAN-Pfade von Multipath ausgeschlossen, sofern keine Ausnahme greift." fi done if [ "${BL_HAS_DEVICE}" -eq 1 ]; then add_finding HINWEIS blacklist-device "Die Blacklist enthält device-Blöcke (Hersteller/Produkt). Prüfen Sie, dass Ihr Speichersystem nicht darunter fällt." fi } check_defaults() { if [ -n "${DEF_FIND_MULTIPATHS}" ] && [ "${DEF_FIND_MULTIPATHS}" != "strict" ]; then add_finding HINWEIS find-multipaths "find_multipaths steht auf „${DEF_FIND_MULTIPATHS}“. Das Proxmox-Wiki empfiehlt den Standard „strict“: Multipath richtet dann nur LUNs ein, die ausdrücklich eingetragen sind." fi case "${DEF_USER_FRIENDLY}" in yes|1|on) # Nach der Umstellung vergibt Proxmox VE die Aliase; dann ist der Hinweis überholt. if [ "${#PVE_ENTRY[@]}" -gt 0 ] || [ "${#SAN_MANAGED[@]}" -gt 0 ]; then return 0; fi add_finding HINWEIS namen "user_friendly_names ist an. Namen wie mpatha vergibt jeder Knoten selbst; sie können sich zwischen Knoten unterscheiden. Die Proxmox-Verwaltung arbeitet mit der WWID und einem clusterweiten Alias." ;; *) ;; esac } check_lun_and_vendor_settings() { if [ "${#MP_ALIAS[@]}" -gt 0 ]; then add_finding HINWEIS luns "${#MP_ALIAS[@]} LUN(s) mit eigenen Einstellungen (multipaths) gefunden. Sie werden als Einträge übernommen (Modus plan)." fi if [ "${DEV_COUNT}" -gt 0 ]; then add_finding HINWEIS hersteller "${DEV_COUNT} Herstellerblock/-blöcke (devices) gefunden. Diese Einstellungen gehören in die Multipath-Überschreibungen unter Rechenzentrum → SAN, nicht mehr in eine Datei je Knoten." fi } check_live_paths() { local wwid name active total expected if [ "${#SAN_LUNS[@]}" -gt 0 ]; then return 0; fi # der SAN-Status ist die bessere Quelle if [ "${#LIVE_MAP[@]}" -eq 0 ]; then if have multipath; then add_finding HINWEIS pfade "multipath -ll zeigt keine Geräte. Entweder ist kein SAN angebunden oder Multipath ist nicht eingerichtet." fi return 0 fi for wwid in "${!LIVE_MAP[@]}"; do IFS='|' read -r name active total <<<"${LIVE_MAP[${wwid}]}" expected="" if [ -n "${PVE_ENTRY[${wwid}]:-}" ]; then expected="${PVE_ENTRY[${wwid}]#*|}"; fi if [ "${total}" -lt 2 ]; then add_finding WARNUNG pfade "${name} (${wwid}) hat nur ${total} Pfad. Ohne zweiten Pfad gibt es keine Ausfallsicherheit." elif [ "${active}" -lt "${total}" ]; then add_finding WARNUNG pfade "${name} (${wwid}): nur ${active} von ${total} Pfaden aktiv." elif is_uint "${expected}" && [ "${active}" -lt "${expected}" ]; then add_finding WARNUNG pfade "${name} (${wwid}): ${active} Pfade aktiv, erwartet sind ${expected}." else add_finding OK pfade "${name} (${wwid}): ${active} von ${total} Pfaden aktiv${expected:+, erwartet ${expected}}." fi done } # iSCSI: Wartezeit, bis ein ausgefallener Pfad gemeldet wird check_iscsi_timeout() { local conf="${OPT_ROOT}/etc/iscsi/iscsid.conf" local from_conf="" from_nodes="" dir local -a node_dirs=() if [ "${CONF_ONLY}" -eq 1 ]; then return 0; fi # open-iscsi legt die Einträge je nach Distribution an einem der beiden Orte ab. for dir in "${OPT_ROOT}/etc/iscsi/nodes" "${OPT_ROOT}/var/lib/iscsi/nodes"; do if [ -d "${dir}" ]; then node_dirs+=("${dir}"); fi done if [ -r "${conf}" ]; then from_conf="$(awk -F= '/^[ \t]*node\.session\.timeo\.replacement_timeout/ { gsub(/[ \t]/, "", $2); v = $2 } END { print v }' "${conf}" 2>/dev/null || true)" fi if [ "${#node_dirs[@]}" -gt 0 ]; then from_nodes="$( { grep -rhs '^node\.session\.timeo\.replacement_timeout' "${node_dirs[@]}" 2>/dev/null || true; } | awk -F= '{ gsub(/[ \t]/, "", $2); print $2 }' | sort -n | tail -n 1)" fi if is_uint "${from_nodes}" && [ "${from_nodes}" -ge "${RT_THRESHOLD}" ]; then add_finding WARNUNG iscsi-wartezeit "Ein bestehender iSCSI-Eintrag wartet ${from_nodes} Sekunden (replacement_timeout), bevor ein ausgefallener Pfad gemeldet wird. So lange steht das I/O. Das Proxmox-Wiki empfiehlt 15. Der Wert muss in iscsid.conf und in den bestehenden Einträgen geändert werden (iscsiadm -m node -o update)." elif is_uint "${from_conf}" && [ "${from_conf}" -ge "${RT_THRESHOLD}" ]; then add_finding WARNUNG iscsi-wartezeit "iscsid.conf setzt replacement_timeout auf ${from_conf} Sekunden. So lange steht das I/O bei einem Pfadausfall. Das Proxmox-Wiki empfiehlt 15." elif is_uint "${from_nodes}"; then add_finding OK iscsi-wartezeit "replacement_timeout der bestehenden iSCSI-Einträge: ${from_nodes} Sekunden." elif is_uint "${from_conf}"; then add_finding OK iscsi-wartezeit "replacement_timeout in iscsid.conf: ${from_conf} Sekunden." fi } check_pve_storages() { local cfg="${OPT_ROOT}/etc/pve/storage.cfg" local name managed if [ "${CONF_ONLY}" -eq 1 ] || [ ! -r "${cfg}" ]; then return 0; fi while IFS='|' read -r name managed; do if [ "${managed}" = "1" ]; then add_finding OK storage "iSCSI-Storage „${name}“: Multipath wird von Proxmox VE verwaltet." else add_finding HINWEIS storage "iSCSI-Storage „${name}“: Die Multipath-Option ist aus. Solange das so bleibt, gilt Ihre eigene Konfiguration." fi done < <(awk ' /^[a-z]+:/ { if (type == "iscsi") print name "|" managed type = $1; sub(/:$/, "", type); name = $2; managed = 0 next } /^[ \t]+managed-multipath[ \t]+1/ { managed = 1 } END { if (type == "iscsi") print name "|" managed } ' "${cfg}") } check_nvme_paths() { local nqn count if [ "${#SAN_LUNS[@]}" -gt 0 ]; then return 0; fi # NVMe-Pfade stehen bereits im SAN-Status have nvme || return 0 while IFS='|' read -r nqn count; do if [ "${count}" -lt 2 ]; then add_finding WARNUNG nvme "NVMe-Subsystem ${nqn} hat nur ${count} aktiven Pfad. Tragen Sie alle Portale ein; die Discovery liefert nicht immer jedes." else add_finding OK nvme "NVMe-Subsystem ${nqn}: ${count} Pfade aktiv." fi done < <( { nvme list-subsys 2>/dev/null || true; } | awk ' /NQN=/ { if (nqn != "") print nqn "|" n; nqn = $0; sub(/.*NQN=/, "", nqn); n = 0 } /^[ \t]*\+-/ && / live/ { n++ } END { if (nqn != "") print nqn "|" n } ') } # ------------------------------------------------------------------- Ausgabe render_json() { local i offline="false" if [ "${OFFLINE}" -eq 1 ]; then offline="true"; fi printf '{"werkzeug":"%s","version":"%s","datenstand":"%s","modus":"%s","offline":%s,"ergebnis":%d,"befunde":[' \ "${PROG}" "${VERSION}" "${DATA_DATE}" "${MODE}" "${offline}" "${WORST}" for i in "${!F_LEVEL[@]}"; do if [ "${i}" -gt 0 ]; then printf ','; fi printf '{"stufe":"%s","kennung":"%s","text":"%s"}' \ "${F_LEVEL[${i}]}" "${F_ID[${i}]}" "$(json_escape "${F_TEXT[${i}]}")" done printf ']}\n' } render_text() { local c_ok="" c_hint="" c_warn="" c_conf="" c_bold="" c_off="" color i if [ "${USE_COLOR}" -eq 1 ]; then c_ok=$'\033[32m'; c_hint=$'\033[36m'; c_warn=$'\033[33m'; c_conf=$'\033[31;1m' c_bold=$'\033[1m'; c_off=$'\033[0m' fi printf '%s%s %s%s · Datenstand %s · liest nur, ändert nichts\n\n' \ "${c_bold}" "${PROG}" "${VERSION}" "${c_off}" "${DATA_DATE}" for i in "${!F_LEVEL[@]}"; do case "${F_LEVEL[${i}]}" in OK) color="${c_ok}" ;; HINWEIS) color="${c_hint}" ;; WARNUNG) color="${c_warn}" ;; *) color="${c_conf}" ;; esac if [ "${WIDTH}" -eq 0 ]; then printf '%s[%-9s]%s %s\n' "${color}" "${F_LEVEL[${i}]}" "${c_off}" "${F_TEXT[${i}]}" else printf '%s[%-9s]%s %s\n' "${color}" "${F_LEVEL[${i}]}" "${c_off}" "${F_TEXT[${i}]}" | fold -s -w "${WIDTH}" | sed '2,$s/^/ /' fi done printf '\n' case "${WORST}" in "${EXIT_CONFLICT}") printf '%sErgebnis: Kollision.%s So lässt sich das verwaltete Multipath nicht einschalten.\n' "${c_conf}" "${c_off}" ;; "${EXIT_WARN}") printf '%sErgebnis: Warnungen.%s Vor einer Umstellung klären.\n' "${c_warn}" "${c_off}" ;; *) printf '%sErgebnis: nichts Kritisches gefunden.%s\n' "${c_ok}" "${c_off}" ;; esac if [ "${MODE}" = "plan" ]; then render_plan "${c_bold}" "${c_off}"; fi printf '\nHintergrund und Labtest: %s\n' "${BLOG_URL}" } # Umstellplan: gibt Befehle aus, führt nichts aus. render_plan() { local c_bold="$1" c_off="$2" local wwid name total expected last="" entry block key val host local -A luns=() for wwid in "${EX_WWID[@]}"; do if is_wwid "${wwid}"; then luns["${wwid}"]="${MP_ALIAS[${wwid}]:-}"; fi done for wwid in "${!MP_ALIAS[@]}"; do luns["${wwid}"]="${MP_ALIAS[${wwid}]}" done for wwid in "${!LIVE_MAP[@]}"; do name="${LIVE_MAP[${wwid}]%%|*}" if [ -z "${luns[${wwid}]:-}" ]; then # Vom System vergebene Namen (mpatha, WWID) sind kein Alias. if [ "${name}" != "${wwid}" ] && [[ ! "${name}" =~ ^mpath[a-z]+$ ]]; then luns["${wwid}"]="${name}" else luns["${wwid}"]="" fi fi done host="$(hostname 2>/dev/null || echo knoten)" printf '\n%sUmstellplan%s (nur Ausgabe, nichts wird ausgeführt)\n' "${c_bold}" "${c_off}" cat < # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # -----------------------------------------------------------------------------