[STAGE5] Migrate DigestBot to gateway read tools
This commit is contained in:
1 parent
7e30c8df13
commit
235e7b829c
5 files changed
+69
-7
No files matched your search
+23
-6
@@ -1426,7 +1426,11 @@ class DigestBot(Bot):
|
||||
|
||||
def build(self):
|
||||
parts = [f"**Сводка · {datetime.date.today().strftime('%d.%m.%Y')}**", ""]
|
||||
c = catalog.content_state()
|
||||
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
|
||||
from .gateway import call
|
||||
c = call("catalog.content").get("data") or {}
|
||||
else:
|
||||
c = catalog.content_state()
|
||||
|
||||
jf = c.get("jellyfin") or {}
|
||||
parts.append(f"**Медиа**: {jf.get('Movie', 0)} фильмов, {jf.get('Series', 0)} сериалов, "
|
||||
@@ -1444,17 +1448,26 @@ class DigestBot(Bot):
|
||||
ha = c.get("home") or {}
|
||||
parts.append(f"**Дом**: {ha.get('total', 0)} сущностей")
|
||||
|
||||
prom = Prom()
|
||||
targets, err = prom.targets()
|
||||
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
|
||||
from .gateway import call
|
||||
targets = call("prometheus.targets").get("data") or []
|
||||
alerts = call("prometheus.alerts").get("data") or []
|
||||
else:
|
||||
prom = Prom()
|
||||
targets, err = prom.targets()
|
||||
alerts, _ = prom.alerts()
|
||||
if targets:
|
||||
down = sum(1 for t in targets if t.get("health") != "up")
|
||||
parts.append(f"**Службы**: {len(targets) - down} в норме, {down} проблемных")
|
||||
alerts, _ = prom.alerts()
|
||||
parts.append(f"**Тревоги**: {len(alerts)} активных")
|
||||
|
||||
# заявки в Seerr и состояние индекса
|
||||
try:
|
||||
counts, _ = Seerr().counts()
|
||||
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
|
||||
from .gateway import call
|
||||
counts = call("seerr.counts").get("data")
|
||||
else:
|
||||
counts, _ = Seerr().counts()
|
||||
if counts:
|
||||
parts.append(f"**Заявки**: {counts.get('pending', 0)} в ожидании, "
|
||||
f"{counts.get('approved', 0)} одобрено, "
|
||||
@@ -1462,7 +1475,11 @@ class DigestBot(Bot):
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
s = index.stats()
|
||||
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
|
||||
from .gateway import call
|
||||
s = call("digest.index").get("data") or {}
|
||||
else:
|
||||
s = index.stats()
|
||||
parts.append(f"**Индекс**: {s['total']} записей "
|
||||
f"(обновлён {(s['built_at'] or '—')[11:16]})")
|
||||
except Exception:
|
||||
|
||||
Reference in new issue
Block a user