Files
checkbot/app/chatops.py
T
patrickandClaude Sonnet 5.5 f34fc6d686 feat: Ausgangslog für Messenger-Nachrichten
- LoggingAdapter protokolliert send/edit (Matrix zusätzlich reply) inkl. Fehlversuche
- Tabelle outbound_log (Migration 10), Aufbewahrung retention.outbound_days (30 Tage)
- Seite /messages und CLI checkbot messages mit Filtern
- Text gekappt (4000) und Secrets maskiert

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 23:38:07 +01:00

54 lines
2.8 KiB
Python

import time
from typing import Callable
from .agent_runs import AgentRunRepository, AgentService, configured_secrets
from .alerts import AlertRepository
from .chat import BACKEND_MATRIX, BACKEND_TELEGRAM, build_matrix, build_telegram
from .checkmk import CheckmkClient
from .commands import (CallbackHandler, CommandDeps, CommandHandler, SettingsReader, command_audit)
from .constants import MATRIX_ALLOWLIST, TELEGRAM_ALLOWLIST
from .db import Database
from .downtime import DowntimeService, PendingStore
from .listeners import ListenerState, MatrixListener, TelegramListener
from .listeners.matrix import HTTP_TIMEOUT_SECONDS as MATRIX_HTTP_TIMEOUT_SECONDS
from .listeners.telegram import HTTP_TIMEOUT_SECONDS as TELEGRAM_HTTP_TIMEOUT_SECONDS
from .mutes import MuteService
from .outbound import OutboundRepository
from .poller import StateStore
ALLOWLIST_KEYS = {BACKEND_TELEGRAM: TELEGRAM_ALLOWLIST, BACKEND_MATRIX: MATRIX_ALLOWLIST}
class ChatOps:
def __init__(self, db: Database, store, state: StateStore, alerts: AlertRepository, mutes: MuteService,
agent_prompt: Callable[[], str | None] | None = None, outbound: OutboundRepository | None = None):
def allowlist(backend: str) -> str | None:
return store.get(ALLOWLIST_KEYS[backend]) if backend in ALLOWLIST_KEYS else None
outbound = outbound or OutboundRepository(db)
def secrets() -> list[str]:
return configured_secrets(store)
bot_names: dict[str, str] = {}
self.agent_runs = AgentRunRepository(db)
self.agent = AgentService(store, db, self.agent_runs, state.recent_changes,
lambda: configured_secrets(store), prompt_provider=agent_prompt)
self.downtime = DowntimeService(store, db, PendingStore(time.monotonic), allowlist,
reader_factory=lambda: CheckmkClient.from_settings(store))
deps = CommandDeps(SettingsReader(store), self.agent, mutes=mutes, lookup=alerts, downtime=self.downtime)
audit_log = command_audit(db)
self.handler = CommandHandler(deps, allowlist, audit_log, bot_name=bot_names.get)
self.callbacks = CallbackHandler(deps, allowlist, audit_log)
listener_state = ListenerState(db)
self.telegram = TelegramListener(
store, self.handler, self.callbacks, listener_state, bot_names,
build=lambda s: build_telegram(s, timeout=TELEGRAM_HTTP_TIMEOUT_SECONDS, sink=outbound,
secrets=secrets))
self.matrix = MatrixListener(
store, self.handler, listener_state,
build=lambda s: build_matrix(s, timeout=MATRIX_HTTP_TIMEOUT_SECONDS, sink=outbound, secrets=secrets))
def listener_runners(self):
return [self.telegram.run, self.matrix.run]