Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions keep/api/bl/maintenance_windows_bl.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,19 @@ def check_if_alert_in_maintenance_windows(self, alert: AlertDto) -> bool:
@staticmethod
def evaluate_cel(maintenance_window: MaintenanceWindowRule, alert: AlertDto | Alert, environment: celpy.Environment, logger, logger_extra_info: dict) -> bool:

cel = preprocess_cel_expression(maintenance_window.cel_query)
ast = environment.compile(cel)
prgm = environment.program(ast)

if isinstance(alert, AlertDto):
payload = alert.dict()
else:
payload = alert.event
# todo: fix this in the future
payload["source"] = payload["source"][0]
try:
cel = preprocess_cel_expression(maintenance_window.cel_query)
ast = environment.compile(cel)
prgm = environment.program(ast)

activation = celpy.json_to_cel(json.loads(json.dumps(payload, default=str)))
if isinstance(alert, AlertDto):
payload = alert.dict()
else:
payload = alert.event
# todo: fix this in the future
payload["source"] = payload["source"][0]

try:
activation = celpy.json_to_cel(json.loads(json.dumps(payload, default=str)))
cel_result = prgm.evaluate(activation)
return True if cel_result else False
except celpy.evaluation.CELEvalError as e:
Expand All @@ -144,9 +143,14 @@ def evaluate_cel(maintenance_window: MaintenanceWindowRule, alert: AlertDto | Al
extra={**logger_extra_info, "maintenance_rule_id": maintenance_window.id},
)
return False
# Log unexpected CEL errors but don't fail the entire event processing
logger.error(
f"Unexpected CEL evaluation error: {str(e)}",
f"Failed to evaluate maintenance window CEL rule: {str(e)}",
extra={**logger_extra_info, "maintenance_rule_id": maintenance_window.id},
)
return False
except Exception as e:
logger.error(
f"Failed to evaluate maintenance window CEL rule: {str(e)}",
extra={**logger_extra_info, "maintenance_rule_id": maintenance_window.id},
)
return False
Expand Down
Loading