Compare commits
8
Commits
50f3620090
..
v2.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3020e076d4 | ||
|
|
f2345b979b | ||
|
|
f3b979fad9 | ||
|
|
92d163b98c | ||
|
|
78a45ce897 | ||
|
|
dcd33b4e7d | ||
|
|
c59f390a32 | ||
|
|
de6c6fe320 |
+93
-3
@@ -22,6 +22,7 @@ import signal
|
|||||||
import requests
|
import requests
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
|
import shutil
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
|
||||||
AGENT_VERSION = "2.0"
|
AGENT_VERSION = "2.0"
|
||||||
@@ -460,7 +461,7 @@ def hardware_reset(auto=False):
|
|||||||
|
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# 7. TELEMETRIA
|
# 7. TELEMETRIA E LETTURA VERSIONI
|
||||||
# ==========================================
|
# ==========================================
|
||||||
def get_cpu_temperature():
|
def get_cpu_temperature():
|
||||||
temp = 0.0
|
temp = 0.0
|
||||||
@@ -479,6 +480,90 @@ def get_cpu_temperature():
|
|||||||
logger.debug(f"Temperature read error: {e}")
|
logger.debug(f"Temperature read error: {e}")
|
||||||
return round(temp, 1)
|
return round(temp, 1)
|
||||||
|
|
||||||
|
def get_binary_versions():
|
||||||
|
"""Interroga direttamente tutti i binari della suite MMDVM supportando nomi multipli."""
|
||||||
|
versions = {}
|
||||||
|
|
||||||
|
def find_cmd(names):
|
||||||
|
# Accetta una lista di nomi e li prova in ordine
|
||||||
|
for name in names:
|
||||||
|
cmd_path = shutil.which(name)
|
||||||
|
if cmd_path:
|
||||||
|
return cmd_path
|
||||||
|
for base in ['/usr/local/bin', '/usr/bin', '/opt/MMDVMHost', '/opt/DMRGateway']:
|
||||||
|
full = os.path.join(base, name)
|
||||||
|
if os.path.isfile(full):
|
||||||
|
return full
|
||||||
|
return names[0] # Se fallisce, tenta col primo nome di default
|
||||||
|
|
||||||
|
# Mappa: "Nome Bello da mostrare" -> ["Lista", "di", "eseguibili", "da", "cercare"]
|
||||||
|
binaries = {
|
||||||
|
"MMDVMHost": ["MMDVMHost", "MMDVM-Host"],
|
||||||
|
"DMRGateway": ["DMRGateway"],
|
||||||
|
"YSFGateway": ["YSFGateway"],
|
||||||
|
"NXDNGateway": ["NXDNGateway"],
|
||||||
|
"P25Gateway": ["P25Gateway"],
|
||||||
|
"DStarGateway": ["dstargateway", "dstar-gateway"]
|
||||||
|
}
|
||||||
|
|
||||||
|
for chiave, lista_eseguibili in binaries.items():
|
||||||
|
cmd_reale = [find_cmd(lista_eseguibili), "-v"]
|
||||||
|
r = run_cmd(cmd_reale, timeout=3)
|
||||||
|
|
||||||
|
if r.returncode == 0 and r.stdout:
|
||||||
|
testo = r.stdout.strip().split('\n')[0]
|
||||||
|
|
||||||
|
import re
|
||||||
|
testo_pulito = re.sub(r'^[A-Za-z0-9_\-]+\s+version\s+', '', testo, flags=re.IGNORECASE)
|
||||||
|
|
||||||
|
# Pulizia extra per DStarGateway (rimuove il blocco Copyright lunghissimo)
|
||||||
|
if "Copyright" in testo_pulito:
|
||||||
|
testo_pulito = testo_pulito.split("Copyright")[0].replace("DStarGateway", "").strip()
|
||||||
|
if testo_pulito.startswith("v"):
|
||||||
|
testo_pulito = testo_pulito[1:] # Toglie la 'v' iniziale
|
||||||
|
|
||||||
|
if chiave not in versions or versions[chiave] == "":
|
||||||
|
versions[chiave] = testo_pulito.strip()
|
||||||
|
|
||||||
|
return versions
|
||||||
|
|
||||||
|
binaries = {
|
||||||
|
"MMDVMHost": ["MMDVMHost", "-v"],
|
||||||
|
"MMDVMHost (alt)": ["MMDVM-Host", "-v"],
|
||||||
|
"DMRGateway": ["DMRGateway", "-v"],
|
||||||
|
"YSFGateway": ["YSFGateway", "-v"],
|
||||||
|
"NXDNGateway": ["NXDNGateway", "-v"],
|
||||||
|
"P25Gateway": ["P25Gateway", "-v"],
|
||||||
|
"DStarGateway": ["dstargateway", "-v"],
|
||||||
|
"DStarGateway (alt)": ["dstar-gateway", "-v"]
|
||||||
|
}
|
||||||
|
|
||||||
|
for nome, comando in binaries.items():
|
||||||
|
cmd_reale = [find_cmd(comando[0]), comando[1]]
|
||||||
|
r = run_cmd(cmd_reale, timeout=3)
|
||||||
|
|
||||||
|
if r.returncode == 0 and r.stdout:
|
||||||
|
# Prende solo la prima riga dell'output
|
||||||
|
testo = r.stdout.strip().split('\n')[0]
|
||||||
|
|
||||||
|
# Pulisce la stringa
|
||||||
|
import re
|
||||||
|
testo_pulito = re.sub(r'^[A-Za-z0-9_\-]+\s+version\s+', '', testo, flags=re.IGNORECASE)
|
||||||
|
|
||||||
|
# --- PULIZIA EXTRA PER DSTARGATEWAY ---
|
||||||
|
if "Copyright" in testo_pulito:
|
||||||
|
testo_pulito = testo_pulito.split("Copyright")[0].replace("DStarGateway", "").strip()
|
||||||
|
if testo_pulito.startswith("v"):
|
||||||
|
testo_pulito = testo_pulito[1:] # Toglie la 'v' iniziale per uniformità
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
|
# Normalizza il nome
|
||||||
|
chiave = "DStarGateway" if "DStar" in nome else nome
|
||||||
|
|
||||||
|
if chiave not in versions or versions[chiave] == "":
|
||||||
|
versions[chiave] = testo_pulito.strip()
|
||||||
|
|
||||||
|
return versions
|
||||||
|
|
||||||
def get_system_status():
|
def get_system_status():
|
||||||
status = {
|
status = {
|
||||||
@@ -492,6 +577,7 @@ def get_system_status():
|
|||||||
for k, v in cfg['profiles'].items()},
|
for k, v in cfg['profiles'].items()},
|
||||||
"update_interval": get_update_interval(), # il server ne ricava le soglie "agent muto"
|
"update_interval": get_update_interval(), # il server ne ricava le soglie "agent muto"
|
||||||
"agent_version": AGENT_VERSION,
|
"agent_version": AGENT_VERSION,
|
||||||
|
"versions": get_binary_versions() # Estrazione versioni dai file binari
|
||||||
}
|
}
|
||||||
names = read_lines(PROCESS_LIST_PATH)
|
names = read_lines(PROCESS_LIST_PATH)
|
||||||
if names:
|
if names:
|
||||||
@@ -500,17 +586,21 @@ def get_system_status():
|
|||||||
for name in names:
|
for name in names:
|
||||||
n = name.strip().lower()
|
n = name.strip().lower()
|
||||||
if n:
|
if n:
|
||||||
status["processes"][n] = "online" if n in running else "offline"
|
# MAGIA QUI: Controlla se il nome corrisponde, ignorando i trattini (mmdvmhost == mmdvm-host)
|
||||||
|
is_online = any(r == n or r.replace('-', '') == n.replace('-', '') for r in running)
|
||||||
|
status["processes"][n] = "online" if is_online else "offline"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Process check error: {e}")
|
logger.error(f"Process check error: {e}")
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
def publish_telemetry():
|
def publish_telemetry():
|
||||||
status = get_system_status()
|
status = get_system_status()
|
||||||
stems = [Path(f).stem for f in read_lines(FILE_LIST_PATH)]
|
stems = [Path(f).stem for f in read_lines(FILE_LIST_PATH)]
|
||||||
status["config_files"] = stems
|
status["config_files"] = stems
|
||||||
status["files"] = stems
|
status["files"] = stems
|
||||||
|
|
||||||
|
# nomi completi con estensione (es. dstargateway.cfg): la dashboard li usa solo per l'etichetta
|
||||||
|
status["file_names"] = [Path(f).name for f in read_lines(FILE_LIST_PATH)]
|
||||||
if connected():
|
if connected():
|
||||||
mqtt_client.publish(TOPIC_SERVICES, json.dumps(status), qos=1)
|
mqtt_client.publish(TOPIC_SERVICES, json.dumps(status), qos=1)
|
||||||
return status
|
return status
|
||||||
|
|||||||
Reference in New Issue
Block a user