From 8c6acc4cbbd3a1e2465ab8e14013f0b942a64351 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Thu, 2 Jan 2025 19:10:36 +0530 Subject: [PATCH] fix(reactions): Ignore rules without reactions --- .../alertmanager_webhook_log/alertmanager_webhook_log.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/press/press/doctype/alertmanager_webhook_log/alertmanager_webhook_log.py b/press/press/doctype/alertmanager_webhook_log/alertmanager_webhook_log.py index cc9ead9acd..50007a363a 100644 --- a/press/press/doctype/alertmanager_webhook_log/alertmanager_webhook_log.py +++ b/press/press/doctype/alertmanager_webhook_log/alertmanager_webhook_log.py @@ -131,11 +131,15 @@ def react_for_instance(self, instance) -> dict: rule: "PrometheusAlertRule" = frappe.get_doc("Prometheus Alert Rule", self.alert) labels = self.get_labels_for_instance(instance) job = rule.react(instance_type, instance, labels) - return {"press_job_type": job.job_type, "press_job": job.name} + if job: + return {"press_job_type": job.job_type, "press_job": job.name} + return {} def react(self): for instance in self.get_instances_from_alerts_payload(self.payload): - self.append("reaction_jobs", self.react_for_instance(instance)) + reaction_job = self.react_for_instance(instance) + if reaction_job: + self.append("reaction_jobs", reaction_job) self.save() def get_instances_from_alerts_payload(self, payload: str) -> set[str]: