Add Loki and Sentinel utility classes for web API endpoints

- Implemented LokiUtils class with GET and POST endpoints for managing scripts, jobs, and payloads.
- Added SentinelUtils class with GET and POST endpoints for managing events, rules, devices, and notifications.
- Both classes include error handling and JSON response formatting.
This commit is contained in:
infinition
2026-03-14 22:33:10 +01:00
parent eb20b168a6
commit aac77a3e76
525 changed files with 29400 additions and 13136 deletions

View File

@@ -974,6 +974,32 @@ class ActionScheduler:
"""
self_port = 0 if target_port is None else int(target_port)
# Circuit breaker check (ORCH-01)
if self.db.is_circuit_open(action_name, mac):
logger.debug(f"Circuit breaker open for {action_name}/{mac}, skipping")
return False
# Global concurrency limit check (ORCH-02)
running_count = self.db.count_running_actions()
max_concurrent = int(getattr(self.shared_data, 'semaphore_slots', 5))
if running_count >= max_concurrent:
logger.debug(f"Concurrency limit reached ({running_count}/{max_concurrent}), skipping {action_name}")
return False
# Per-action concurrency limit (ORCH-02)
requires_raw = action_def.get("b_requires", "")
if requires_raw:
try:
req_obj = json.loads(requires_raw) if isinstance(requires_raw, str) else requires_raw
if isinstance(req_obj, dict) and "max_concurrent" in req_obj:
max_per_action = int(req_obj["max_concurrent"])
running_for_action = self.db.count_running_actions(action_name=action_name)
if running_for_action >= max_per_action:
logger.debug(f"Per-action concurrency limit for {action_name} ({running_for_action}/{max_per_action})")
return False
except (json.JSONDecodeError, TypeError, ValueError):
pass
# 0) Duplicate protection (active)
existing = self.db.query(
"""