[STAGE5] Migrate InfraBot via scoped infra.read gateway
This commit is contained in:
1 parent
29fe3881a8
commit
57172fd91f
5 files changed
+54
-1
No files matched your search
@@ -42,6 +42,8 @@ direct 127.0.0.1:9120 → blocked
|
||||
- feature flag `HUB_GATEWAY_CAM=1` включён; камера не перенастраивалась;
|
||||
- `SecretaryBot` intent/ask через gateway (`core.intent`, `core.ask`); `!алиас` оставлен direct (owner-write);
|
||||
- feature flag `HUB_GATEWAY_SECRETARY=1` включён;
|
||||
- `InfraBot` переведён на scoped `infra.read` (status/alerts/disk/content/services/gaps/inbox/sources/history/users);
|
||||
- feature flag `HUB_GATEWAY_INFRA=1` включён;
|
||||
- hub-bots active, 9 ботов на связи.
|
||||
|
||||
## Порядок миграции
|
||||
|
||||
@@ -125,6 +125,10 @@ tools:
|
||||
mode: read
|
||||
local: core_ask
|
||||
approval: false
|
||||
- name: infra.read
|
||||
mode: read
|
||||
local: infra_read
|
||||
approval: false
|
||||
- name: audit.write
|
||||
gateway: http://127.0.0.1:9160/api/sprint/status
|
||||
mode: write
|
||||
|
||||
@@ -27,7 +27,7 @@ GET /v1/models
|
||||
| S5-04 | Memory | done: SQLite namespaced memory + TTL/search, tests 3/3 |
|
||||
| S5-05 | Night Shift | done: timers 00:00/07:30, llm-night-start/stop |
|
||||
| S5-06 | Tool Gateway / agent approvals | done: agent-gw enforced + approval queue; legacy migration = G5 |
|
||||
| S5-07 | Gate G5 | in_progress: Photo+Book+Home+Digest+Search+Cam; Secretary intent/ask; MEDIA/INFRA direct |
|
||||
| S5-07 | Gate G5 | in_progress: Photo+Book+Home+Digest+Search+Cam+Infra; Secretary intent/ask; MEDIA direct |
|
||||
|
||||
## Tool Gateway runtime
|
||||
|
||||
|
||||
@@ -122,6 +122,27 @@ def local_call(handler, q="", params=None):
|
||||
if handler == "core_ask":
|
||||
data, err = _hub_module("core_api")._get("/ask", {"q": q}, timeout=180)
|
||||
return {"ok": not bool(err), "data": data, "error": err}
|
||||
if handler == "infra_read":
|
||||
bot = _hub_module("bots").InfraBot(None, None)
|
||||
prom = _hub_module("sources").Prom()
|
||||
arg = (params.get("arg") or [""])[0]
|
||||
allowed = {
|
||||
"status": lambda: bot._status(prom),
|
||||
"alerts": lambda: bot._alerts(prom),
|
||||
"disk": lambda: bot._disk(prom),
|
||||
"backups": lambda: bot._backups(),
|
||||
"content": lambda: bot._content(),
|
||||
"services": lambda: bot._services(),
|
||||
"gaps": lambda: bot._gaps(),
|
||||
"inbox": lambda: bot._inbox(),
|
||||
"sources": lambda: bot._services_cmd(arg),
|
||||
"history": lambda: bot._history_cmd(arg),
|
||||
"users": lambda: bot._users_cmd(),
|
||||
}
|
||||
fn = allowed.get(q)
|
||||
if not fn:
|
||||
return {"ok": False, "data": None, "error": "unknown infra command"}
|
||||
return {"ok": True, "data": fn(), "error": None}
|
||||
if handler == "core_aliases":
|
||||
data, err = _hub_module("core_api")._get("/aliases", {
|
||||
"latin": (params.get("latin") or [""])[0],
|
||||
|
||||
@@ -961,6 +961,10 @@ class InfraBot(Bot):
|
||||
title = "Инфраструктура"
|
||||
room_env = "INFRA_ROOM"
|
||||
|
||||
def _gw(self, q, arg=""):
|
||||
from .gateway import call
|
||||
return call("infra.read", {"q": q, "arg": arg}).get("data") or ""
|
||||
|
||||
def register(self):
|
||||
prom = Prom()
|
||||
self.cmd("status", "какие службы живы, а какие нет")(lambda a: self._status(prom))
|
||||
@@ -976,6 +980,8 @@ class InfraBot(Bot):
|
||||
self.cmd("users", "кто в каких сервисах есть: аудит доступов")(lambda a: self._users_cmd())
|
||||
|
||||
def _services_cmd(self, arg):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("sources", arg)
|
||||
"""Источники событий: кто сколько присылает и когда последний раз."""
|
||||
data, err = core_api.services()
|
||||
if err:
|
||||
@@ -993,6 +999,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _history_cmd(self, arg):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("history", arg)
|
||||
"""История по одному сервису."""
|
||||
name = (arg or "").strip()
|
||||
if not name:
|
||||
@@ -1011,6 +1019,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _users_cmd(self):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("users")
|
||||
"""Аудит пользователей: кто где заведён."""
|
||||
data, err = core_api.get_data("identity", 1)
|
||||
if err:
|
||||
@@ -1024,6 +1034,8 @@ class InfraBot(Bot):
|
||||
+ "\n\n_✓ — аккаунт есть, тире — нет. Обновляется по понедельникам._")
|
||||
|
||||
def _status(self, prom):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("status")
|
||||
targets, err = prom.targets()
|
||||
if err:
|
||||
return util.human_error(err, "Prometheus")
|
||||
@@ -1037,6 +1049,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _alerts(self, prom):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("alerts")
|
||||
alerts, err = prom.alerts()
|
||||
if err:
|
||||
return f"Не смог получить тревоги: {err}"
|
||||
@@ -1048,6 +1062,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _disk(self, prom):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("disk")
|
||||
q = '(node_filesystem_avail_bytes{mountpoint="/"} * 100 / node_filesystem_size_bytes{mountpoint="/"})'
|
||||
v, err = prom.query(q + " < 15")
|
||||
if err:
|
||||
@@ -1064,6 +1080,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _backups(self):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("backups")
|
||||
out, err = local.pct_exec(10, ["sh", "-c", "ls -t /mnt/backups/dump/*.tar.zst 2>/dev/null | head -3"])
|
||||
if err or not out:
|
||||
try:
|
||||
@@ -1081,6 +1099,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _content(self):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("content")
|
||||
c = catalog.content_state()
|
||||
jf = c.get("jellyfin") or {}
|
||||
nav = c.get("navidrome") or {}
|
||||
@@ -1096,6 +1116,8 @@ class InfraBot(Bot):
|
||||
f"• Дом: {ha.get('total', 0)} сущностей")
|
||||
|
||||
def _services(self):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("services")
|
||||
lines = ["**Все службы**", ""]
|
||||
for name, addr, domain, holds, fill in catalog.SERVICES:
|
||||
link = f"https://{domain}" if domain and domain != "—" else addr
|
||||
@@ -1103,6 +1125,8 @@ class InfraBot(Bot):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _inbox(self):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("inbox")
|
||||
from . import inbox as inbox_mod
|
||||
s = inbox_mod.stats()
|
||||
rows = inbox_mod.pending(10)
|
||||
@@ -1199,6 +1223,8 @@ class InfraBot(Bot):
|
||||
return gaps
|
||||
|
||||
def _gaps(self):
|
||||
if os.environ.get("HUB_GATEWAY_INFRA") == "1":
|
||||
return self._gw("gaps")
|
||||
"""Честный список того, что мешает системе работать целиком."""
|
||||
import time as _t
|
||||
if _GAPS_FULL["value"] is not None and (_t.time() - _GAPS_FULL["at"]) < _GAPS_TTL:
|
||||
|
||||
Reference in new issue
Block a user