fix reload&refrehs

This commit is contained in:
larssand
2026-07-06 09:25:40 +02:00
parent fde165d79b
commit 1238fd0e4d
3 changed files with 31 additions and 9 deletions

View File

@@ -517,7 +517,7 @@ def write_status(status: dict[str, object], output: str) -> None:
tmp_path.replace(output_path)
def write_refreshing_status(output: str, *, cache_path: str | None = None) -> None:
def write_refreshing_status(output: str, *, cache_path: str | None = None, call_timeout_seconds: int = 0, poll_timeout_seconds: int = 0) -> None:
output_path = Path(output)
now = int(time.time())
try:
@@ -561,6 +561,8 @@ def write_refreshing_status(output: str, *, cache_path: str | None = None) -> No
"previous_poll_completed_at": previous_completed_at,
"fetch_mode": previous_fetch_mode,
"coverage_status": previous_coverage_status or "refreshing",
"call_timeout_seconds": call_timeout_seconds or previous_mcp.get("call_timeout_seconds", 0),
"poll_timeout_seconds": poll_timeout_seconds or previous_mcp.get("poll_timeout_seconds", 0),
}
current["status_cache"] = {"served_from_cache": used_cache, "reason": "refreshing"}
write_status(current, output)
@@ -590,13 +592,29 @@ def monitor_loop(
runtime = ConfigStore(config_path).read() if config_path and Path(config_path).exists() else {}
effective_llm = bool(runtime.get("llm_enabled")) if runtime else llm
effective_model = str(runtime.get("llm_model") or llm_model or "")
mcp_call_timeout = max(1, int(runtime.get("graylog_mcp_call_timeout_seconds", 8) or 8))
mcp_poll_timeout = max(60, int(runtime.get("graylog_mcp_poll_timeout_seconds", 120) or 120))
if runtime.get("log_source") == "graylog_mcp":
write_refreshing_status(output, cache_path=status_cache_path)
status = build_status(
log_path, policy_path=policy_path, anomaly_limit=anomaly_limit,
baseline_path=baseline_path, config_path=config_path, history_path=history_path,
status_cache_path=status_cache_path,
)
write_refreshing_status(output, cache_path=status_cache_path, call_timeout_seconds=mcp_call_timeout, poll_timeout_seconds=mcp_poll_timeout)
try:
status = build_status(
log_path, policy_path=policy_path, anomaly_limit=anomaly_limit,
baseline_path=baseline_path, config_path=config_path, history_path=history_path,
status_cache_path=status_cache_path,
)
except Exception as exc:
error_status = {"status": "error", "error": f"monitor_error: {exc}", "call_timeout_seconds": mcp_call_timeout, "poll_timeout_seconds": mcp_poll_timeout}
status = cached_status_with_error(status_cache_path, error_status) if status_cache_path else None
if not status:
status = {
"status_schema": 2,
"generated_at": int(time.time()),
"stale": True,
"stale_reason": "monitor_error",
"capabilities": {"graylog_mcp": error_status},
"summary": {"total": 0},
"status_cache": {"served_from_cache": False, "reason": "monitor_error"},
}
mcp = status.get("capabilities", {}).get("graylog_mcp", {}) if isinstance(status.get("capabilities"), dict) else {}
if status_cache_path and isinstance(mcp, dict) and mcp.get("status") == "error":
cached = cached_status_with_error(status_cache_path, mcp)