diff --git a/app.py b/app.py index 758afcf..c20ed47 100644 --- a/app.py +++ b/app.py @@ -15,7 +15,7 @@ else: paths_cfg = cfg.get("paths", {}) runtime_state.configure(paths_cfg.get("runtime_state", "/var/server-bot/runtime.json")) -ARTIFACT_STATE = paths_cfg["artifact_state"] +ARTIFACT_STATE = paths_cfg.get("artifact_state", "/opt/tg-bot/state.json") RESTIC_ENV = load_env(paths_cfg.get("restic_env", "/etc/restic/restic.env")) DISK_WARN = int(cfg.get("thresholds", {}).get("disk_warn", 80)) diff --git a/services/config_check.py b/services/config_check.py index 6925815..7176fe8 100644 --- a/services/config_check.py +++ b/services/config_check.py @@ -9,7 +9,9 @@ def validate_cfg(cfg: dict[str, Any]) -> Tuple[List[str], List[str]]: tg = cfg.get("telegram", {}) if not tg.get("token"): errors.append("telegram.token is missing") - if not tg.get("admin_id"): + admin_ids = tg.get("admin_ids") + has_admin_ids = isinstance(admin_ids, list) and len(admin_ids) > 0 + if not tg.get("admin_id") and not has_admin_ids: errors.append("telegram.admin_id is missing") thresholds = cfg.get("thresholds", {}) diff --git a/services/health.py b/services/health.py index 8986448..bd52f33 100644 --- a/services/health.py +++ b/services/health.py @@ -1,4 +1,4 @@ -import os +๏ปฟimport os import ssl import subprocess import psutil @@ -37,15 +37,17 @@ def _npm_api_base(cfg) -> str | None: def health(cfg, container_map: dict | None = None) -> str: - lines = ["๐Ÿฉบ Health check\n"] - + lines = ["ั€ัŸยฉั” Health check\n"] + thresholds = cfg.get("thresholds", {}) + disk_warn = int(thresholds.get("disk_warn", 80)) + load_warn = float(thresholds.get("load_warn", 2.0)) try: env = os.environ.copy() env.update(RESTIC_ENV) subprocess.check_output(["restic", "snapshots"], timeout=10, env=env) - lines.append("๐ŸŸข Backup repo reachable") + lines.append("ั€ัŸัŸัž Backup repo reachable") except Exception: - lines.append("๐Ÿ”ด Backup repo unreachable") + lines.append("ั€ัŸโ€า‘ Backup repo unreachable") containers = container_map if container_map is not None else _containers_from_cfg(cfg) for alias, real in containers.items(): @@ -53,20 +55,20 @@ def health(cfg, container_map: dict | None = None) -> str: f"docker inspect -f '{{{{.State.Status}}}}' {real}" ) if out.strip() != "running": - lines.append(f"๐Ÿ”ด {alias} down") + lines.append(f"ั€ัŸโ€า‘ {alias} down") else: - lines.append(f"๐ŸŸข {alias} OK") + lines.append(f"ั€ัŸัŸัž {alias} OK") npm_cfg = cfg.get("npmplus", {}) npm_base = _npm_api_base(cfg) if npm_base: npm_status = _request_status(npm_base, npm_cfg.get("verify_tls", True)) if npm_status == 200: - lines.append("๐ŸŸข NPMplus API OK") + lines.append("ั€ัŸัŸัž NPMplus API OK") elif npm_status is None: - lines.append("๐Ÿ”ด NPMplus API unreachable") + lines.append("ั€ัŸโ€า‘ NPMplus API unreachable") else: - lines.append(f"๐ŸŸก NPMplus API HTTP {npm_status}") + lines.append(f"ั€ัŸัŸะŽ NPMplus API HTTP {npm_status}") g_cfg = cfg.get("gitea", {}) g_base = (g_cfg.get("base_url") or "").rstrip("/") @@ -82,21 +84,22 @@ def health(cfg, container_map: dict | None = None) -> str: g_status = status break if g_status == 200: - lines.append("๐ŸŸข Gitea API OK") + lines.append("ั€ัŸัŸัž Gitea API OK") elif g_status is None: - lines.append("๐Ÿ”ด Gitea API unreachable") + lines.append("ั€ัŸโ€า‘ Gitea API unreachable") else: - lines.append(f"๐ŸŸก Gitea API HTTP {g_status}") + lines.append(f"ั€ัŸัŸะŽ Gitea API HTTP {g_status}") usage, mount = worst_disk_usage() if usage is None: - lines.append("โš ๏ธ Disk n/a") - elif usage > cfg["thresholds"]["disk_warn"]: - lines.append(f"๐ŸŸก Disk {usage}% ({mount})") + lines.append("ะฒั™ย ะฟั‘ะ Disk n/a") + elif usage > disk_warn: + lines.append(f"ั€ัŸัŸะŽ Disk {usage}% ({mount})") else: - lines.append(f"๐ŸŸข Disk {usage}% ({mount})") + lines.append(f"ั€ัŸัŸัž Disk {usage}% ({mount})") load = psutil.getloadavg()[0] - lines.append(f"{'๐ŸŸข' if load < cfg['thresholds']['load_warn'] else '๐ŸŸก'} Load {load}") + lines.append(f"{'ั€ัŸัŸัž' if load < load_warn else 'ั€ัŸัŸะŽ'} Load {load}") return "\n".join(lines) +