mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-28 06:00:40 +00:00
Update notification service
This commit is contained in:
@@ -71,9 +71,10 @@ _PROXMOX_NODE_CACHE_TTL = 300 # seconds (5 minutes)
|
|||||||
|
|
||||||
def get_proxmox_node_name() -> str:
|
def get_proxmox_node_name() -> str:
|
||||||
"""
|
"""
|
||||||
Retrieve the real Proxmox node name.
|
Retrieve the real Proxmox node name for the LOCAL node.
|
||||||
|
|
||||||
- First tries reading from: `pvesh get /nodes`
|
- First tries reading from: `pvesh get /nodes`
|
||||||
|
- In a cluster, matches the local hostname against the node list
|
||||||
- Uses an in-memory cache to avoid repeated API calls
|
- Uses an in-memory cache to avoid repeated API calls
|
||||||
- Falls back to the short hostname if the API call fails
|
- Falls back to the short hostname if the API call fails
|
||||||
"""
|
"""
|
||||||
@@ -85,6 +86,9 @@ def get_proxmox_node_name() -> str:
|
|||||||
if cached_name and (now - float(cached_ts)) < _PROXMOX_NODE_CACHE_TTL:
|
if cached_name and (now - float(cached_ts)) < _PROXMOX_NODE_CACHE_TTL:
|
||||||
return str(cached_name)
|
return str(cached_name)
|
||||||
|
|
||||||
|
# Get local hostname for matching
|
||||||
|
local_hostname = socket.gethostname().split(".", 1)[0].lower()
|
||||||
|
|
||||||
# Try Proxmox API
|
# Try Proxmox API
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
@@ -98,19 +102,36 @@ def get_proxmox_node_name() -> str:
|
|||||||
if result.returncode == 0 and result.stdout:
|
if result.returncode == 0 and result.stdout:
|
||||||
nodes = json.loads(result.stdout)
|
nodes = json.loads(result.stdout)
|
||||||
if isinstance(nodes, list) and nodes:
|
if isinstance(nodes, list) and nodes:
|
||||||
node_name = nodes[0].get("node")
|
# In a cluster, find the node that matches local hostname
|
||||||
if node_name:
|
# Node names in Proxmox typically match the hostname
|
||||||
_PROXMOX_NODE_CACHE["name"] = node_name
|
for node_info in nodes:
|
||||||
_PROXMOX_NODE_CACHE["timestamp"] = now
|
node_name = node_info.get("node", "")
|
||||||
return node_name
|
if node_name.lower() == local_hostname:
|
||||||
|
_PROXMOX_NODE_CACHE["name"] = node_name
|
||||||
|
_PROXMOX_NODE_CACHE["timestamp"] = now
|
||||||
|
return node_name
|
||||||
|
|
||||||
|
# If no exact match, try partial match (hostname might be truncated)
|
||||||
|
for node_info in nodes:
|
||||||
|
node_name = node_info.get("node", "")
|
||||||
|
if local_hostname.startswith(node_name.lower()) or node_name.lower().startswith(local_hostname):
|
||||||
|
_PROXMOX_NODE_CACHE["name"] = node_name
|
||||||
|
_PROXMOX_NODE_CACHE["timestamp"] = now
|
||||||
|
return node_name
|
||||||
|
|
||||||
|
# Last resort: if single node cluster, use that node
|
||||||
|
if len(nodes) == 1:
|
||||||
|
node_name = nodes[0].get("node")
|
||||||
|
if node_name:
|
||||||
|
_PROXMOX_NODE_CACHE["name"] = node_name
|
||||||
|
_PROXMOX_NODE_CACHE["timestamp"] = now
|
||||||
|
return node_name
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning("Failed to get Proxmox node name from API: %s", exc)
|
logger.warning("Failed to get Proxmox node name from API: %s", exc)
|
||||||
|
|
||||||
# Fallback: short hostname (without domain)
|
# Fallback: short hostname (without domain)
|
||||||
hostname = socket.gethostname()
|
return local_hostname
|
||||||
short_hostname = hostname.split(".", 1)[0]
|
|
||||||
return short_hostname
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1406,7 +1406,8 @@ EMOJI USAGE — place ONE emoji at the START of EVERY non-empty line (title and
|
|||||||
❌ failed / FAILED / error
|
❌ failed / FAILED / error
|
||||||
💥 crash / collision / I/O error
|
💥 crash / collision / I/O error
|
||||||
🆘 new critical health issue
|
🆘 new critical health issue
|
||||||
📦 backup started / updates available
|
📦 updates available
|
||||||
|
💾 backup started
|
||||||
🆕 new PVE version available
|
🆕 new PVE version available
|
||||||
🔺 escalated / severity increased
|
🔺 escalated / severity increased
|
||||||
📋 health digest / persistent issues
|
📋 health digest / persistent issues
|
||||||
@@ -1436,6 +1437,7 @@ EMOJI USAGE — place ONE emoji at the START of EVERY non-empty line (title and
|
|||||||
✔️ status ok / success / completed
|
✔️ status ok / success / completed
|
||||||
❌ status error / failed
|
❌ status error / failed
|
||||||
💽 size / tamaño / Größe
|
💽 size / tamaño / Größe
|
||||||
|
💾 total backup size (summary line only)
|
||||||
⏱️ duration / tiempo / Dauer
|
⏱️ duration / tiempo / Dauer
|
||||||
🗄️ storage / almacenamiento / PBS
|
🗄️ storage / almacenamiento / PBS
|
||||||
🗃️ archive path / ruta de archivo
|
🗃️ archive path / ruta de archivo
|
||||||
@@ -1459,6 +1461,8 @@ EMOJI USAGE — place ONE emoji at the START of EVERY non-empty line (title and
|
|||||||
🚦 severity / severidad
|
🚦 severity / severidad
|
||||||
🖥️ node / nodo
|
🖥️ node / nodo
|
||||||
🎯 target / destino
|
🎯 target / destino
|
||||||
|
🔹 current version (pve_update)
|
||||||
|
🟢 new version (pve_update)
|
||||||
|
|
||||||
BLANK LINES FOR READABILITY — insert ONE blank line between logical sections within the body.
|
BLANK LINES FOR READABILITY — insert ONE blank line between logical sections within the body.
|
||||||
Blank lines go BETWEEN groups, not before the first line or after the last line.
|
Blank lines go BETWEEN groups, not before the first line or after the last line.
|
||||||
@@ -1527,7 +1531,7 @@ EMOJI USAGE — place ONE emoji at the START of EVERY non-empty line (title and
|
|||||||
⏱️ Duration: 00:01:10
|
⏱️ Duration: 00:01:10
|
||||||
🗄️ Storage: ct/101/2026-03-17T22:04:29Z
|
🗄️ Storage: ct/101/2026-03-17T22:04:29Z
|
||||||
|
|
||||||
📊 Total: 2 backups | 📦 16.4 GiB | ⏱️ 00:05:31
|
📊 Total: 2 backups | 💾 16.4 GiB | ⏱️ 00:05:31
|
||||||
|
|
||||||
EXAMPLE — backup partially failed (some ok, some failed):
|
EXAMPLE — backup partially failed (some ok, some failed):
|
||||||
[TITLE]
|
[TITLE]
|
||||||
@@ -1546,7 +1550,7 @@ EMOJI USAGE — place ONE emoji at the START of EVERY non-empty line (title and
|
|||||||
💽 Size: 0 B
|
💽 Size: 0 B
|
||||||
⏱️ Duration: 00:00:37
|
⏱️ Duration: 00:00:37
|
||||||
|
|
||||||
📊 Total: 2 backups | ❌ 1 failed | 📦 12.3 GiB | ⏱️ 00:04:58
|
📊 Total: 2 backups | ❌ 1 failed | 💾 12.3 GiB | ⏱️ 00:04:58
|
||||||
|
|
||||||
EXAMPLE — disk I/O health warning:
|
EXAMPLE — disk I/O health warning:
|
||||||
[TITLE]
|
[TITLE]
|
||||||
|
|||||||
Reference in New Issue
Block a user