Backup automatico script del 2026-01-25 07:00

This commit is contained in:
2026-01-25 07:00:03 +01:00
parent 9dbe0cfa93
commit f0c5672607
16 changed files with 241 additions and 61 deletions

View File

@@ -5,6 +5,7 @@ import datetime
import requests
import shlex
import json
import time
from functools import wraps
from typing import Optional
from zoneinfo import ZoneInfo
@@ -58,9 +59,8 @@ INFRA_DEVICES = [
{"name": "📶 WiFi Taverna", "ip": "192.168.128.103"},
{"name": "📶 WiFi Dado", "ip": "192.168.128.104"},
{"name": "🔌 Sw Sala", "ip": "192.168.128.105"},
{"name": "🔌 Sw Main", "ip": "192.168.128.106"},
{"name": "🔌 Sw Lav", "ip": "192.168.128.107"},
{"name": "🔌 Sw Tav", "ip": "192.168.128.108"}
{"name": "🔌 Sw Tav", "ip": "192.168.128.106"},
{"name": "🔌 Sw Lav", "ip": "192.168.128.107"}
]
logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s", level=logging.INFO)
@@ -84,9 +84,17 @@ def get_ping_icon(ip):
except Exception: return "🔴"
def get_device_stats(device):
ip, user, dtype = device['ip'], device['type'], device['user']
ip, user, dtype = device['ip'], device['user'], device['type']
uptime_raw = run_cmd("uptime -p 2>/dev/null || uptime", ip, user)
if not uptime_raw or "Err" in uptime_raw: return "🔴 **OFFLINE**"
if not uptime_raw or "Err" in uptime_raw:
# Retry once to reduce transient SSH hiccups.
time.sleep(0.5)
uptime_raw = run_cmd("uptime -p 2>/dev/null || uptime", ip, user)
if not uptime_raw or "Err" in uptime_raw:
# If ping is OK but SSH failed, mark as online with warning.
if get_ping_icon(ip) == "":
return "🟡 **ONLINE (SSH non raggiungibile)**"
return "🔴 **OFFLINE**"
uptime = uptime_raw.replace("up ", "").split(", load")[0].split(", ")[0]
temp = "N/A"
if dtype in ["pi", "local"]: