#!/usr/bin/env bash # node-info.sh — Node-Identität als Metrik: LAN-IP, NetBird-IP/FQDN, PVE-URL. # # Ausgabe im Prometheus-Format: # node_info{lan_ip="192.168.188.20",netbird_ip="100.83.12.34", # netbird_fqdn="pve7.netbird.selfhosted", # pve_url="https://pve7.netbird.selfhosted:8006", # pve_cluster="1",pve_node="pve7"} 1 # # Wird vom Installer auf JEDER Linux-Node eingebunden (Rolle unabhängig). # Fehlende Werte werden weggelassen — kein Platzhalter-Müll. set -eu lan_ip=""; nb_ip=""; nb_fqdn=""; pve_url=""; pve_node=""; pve_cluster="" # LAN-IP: erste globale IPv4, ohne Netzwerk-Overlays/Bridges lan_ip="$(ip -4 -o addr show scope global 2>/dev/null \ | awk '$2 !~ /^(wt0|docker|br-|veth|virbr|lo|tun|tap)/ {print $4}' \ | cut -d/ -f1 | head -1 || true)" # NetBird: Interface-IP (funktioniert ohne CLI) … nb_ip="$(ip -4 -o addr show wt0 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -1 || true)" # … und FQDN aus der CLI (optional; liefert ohne Daemon-Zugriff nichts) if command -v netbird >/dev/null 2>&1; then nb_fqdn="$(netbird status 2>/dev/null | sed -n 's/^ *FQDN: *//p' | head -1 || true)" fi # PVE-Erkennung: Knotenname lokal, Cluster-Status aus /etc/pve if command -v pvesh >/dev/null 2>&1; then pve_node="$(hostname -s 2>/dev/null || true)" # /etc/pve/corosync.conf existiert nur in einem Cluster [ -r /etc/pve/corosync.conf ] && pve_cluster="1" # Link bevorzugt über den NetBird-Namen (erreichbar aus dem Mesh), sonst LAN host_ref="${nb_fqdn%%.netbird.selfhosted}" [ -n "$nb_fqdn" ] && pve_url="https://${nb_fqdn}:8006" [ -z "$pve_url" ] && [ -n "$lan_ip" ] && pve_url="https://${lan_ip}:8006" fi esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; } labels="" add() { [ -n "$2" ] || return 0; labels="${labels:+$labels,}$1=\"$(esc "$2")\""; } add lan_ip "$lan_ip" add netbird_ip "$nb_ip" add netbird_fqdn "$nb_fqdn" add pve_url "$pve_url" add pve_node "$pve_node" add pve_cluster "$pve_cluster" [ -n "$labels" ] || exit 0 printf 'node_info{%s} 1\n' "$labels"