fix clear investi

This commit is contained in:
larssand
2026-07-06 16:49:30 +02:00
parent 49ac7e2958
commit 649c29a8c2
8 changed files with 88 additions and 7 deletions

View File

@@ -26,6 +26,7 @@ DEFAULT_CONFIG: dict[str, object] = {
"graylog_field_mapping": "",
"llm_enabled": False,
"llm_model": "",
"llm_timeout": 180,
"profile_advisor_enabled": False,
"profile_advisor_model": "qwen3:8b",
"profile_advisor_timeout": 240,
@@ -73,7 +74,7 @@ class ConfigStore:
current[key] = value
elif key == "graylog_fetch_mode" and value in {"auto", "raw", "aggregate"}:
current[key] = value
elif key in {"graylog_range_seconds", "graylog_max_events_per_stream", "graylog_raw_sample_events", "graylog_mcp_call_timeout_seconds", "graylog_mcp_poll_timeout_seconds", "baseline_retention_days", "baseline_value_retention_days", "baseline_max_values_per_field", "baseline_training_days", "profile_advisor_timeout", "threat_intel_daily_limit", "threat_intel_ttl_seconds", "threat_intel_error_ttl_seconds", "abuseipdb_max_age_days"}:
elif key in {"graylog_range_seconds", "graylog_max_events_per_stream", "graylog_raw_sample_events", "graylog_mcp_call_timeout_seconds", "graylog_mcp_poll_timeout_seconds", "baseline_retention_days", "baseline_value_retention_days", "baseline_max_values_per_field", "baseline_training_days", "llm_timeout", "profile_advisor_timeout", "threat_intel_daily_limit", "threat_intel_ttl_seconds", "threat_intel_error_ttl_seconds", "abuseipdb_max_age_days"}:
try:
minimum = 60 if key in {"graylog_range_seconds", "graylog_mcp_poll_timeout_seconds"} else 1
current[key] = max(minimum, int(value))

File diff suppressed because one or more lines are too long

View File

@@ -112,6 +112,21 @@ class IncidentStore:
self._write(states)
return {"id": incident_id, **entry}
def clear(self, *, status: str | None = None) -> dict[str, object]:
states = self.entries()
if status is None:
removed = len(states)
states = {}
else:
status = status.lower()
if status not in {"open", "acknowledged", "resolved"}:
raise ValueError("invalid incident status")
before = len(states)
states = {key: value for key, value in states.items() if str(value.get("status", "open")) != status}
removed = before - len(states)
self._write(states)
return {"removed": removed, "remaining": len(states), "status": status or "all"}
def _write(self, states: dict[str, dict[str, object]]) -> None:
self.path.parent.mkdir(parents=True, exist_ok=True)
self.path.write_text(json.dumps(states, indent=2, sort_keys=True), encoding="utf-8")

View File

@@ -742,6 +742,7 @@ 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 "")
effective_llm_timeout = int(runtime.get("llm_timeout") or llm_timeout or 180)
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", 240) or 240))
if runtime.get("log_source") == "graylog_mcp":
@@ -779,15 +780,13 @@ def monitor_loop(
StatusSnapshotStore(status_cache_path).save("last_good", status)
write_status(status, output)
now = int(time.time())
if runtime.get("profile_advisor_enabled"):
add_profile_advisor(status, runtime)
write_status(status, output)
if now - last_llm_at >= llm_interval:
add_llm_assessment(status, previous=last_llm_text, model=effective_model or None, timeout=llm_timeout)
add_llm_assessment(status, previous=last_llm_text, model=effective_model or None, timeout=effective_llm_timeout)
assessment = status.get("llm_assessment", {})
if isinstance(assessment, dict):
last_llm_text = str(assessment.get("text", "") or last_llm_text or "")
last_llm_at = now
write_status(status, output)
else:
status["llm_assessment"] = {
"enabled": True,
@@ -795,6 +794,9 @@ def monitor_loop(
"generated_at": last_llm_at,
"text": last_llm_text or "",
}
if runtime.get("profile_advisor_enabled"):
add_profile_advisor(status, runtime)
write_status(status, output)
else:
status["llm_assessment"] = {"enabled": False, "status": "disabled", "text": ""}
if runtime.get("profile_advisor_enabled"):