From 9f220d527ba3b55a9bdebf53985a7dcdeac0cde5 Mon Sep 17 00:00:00 2001 From: rdas <5216575+rdas1212@users.noreply.github.com> Date: Mon, 18 Oct 2021 14:07:12 +0530 Subject: [PATCH] Fix issue where alert object triggers/notifications attribute was overwritten by the client for the respective attribute --- argusclient/client.py | 8 ++++---- argusclient/model.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/argusclient/client.py b/argusclient/client.py index d385dae..4bf68d2 100644 --- a/argusclient/client.py +++ b/argusclient/client.py @@ -551,8 +551,8 @@ def __init__(self, argus, get_all_req_opts=None): super(AlertsServiceClient, self).__init__(Alert, argus, id_path="alerts/%s", get_all_req_opts=get_all_req_opts) def _fill(self, alert): - alert._triggers = AlertTriggersServiceClient(self.argus, alert) - alert._notifications = AlertNotificationsServiceClient(self.argus, alert) + alert._triggers_client = AlertTriggersServiceClient(self.argus, alert) + alert._notifications_client = AlertNotificationsServiceClient(self.argus, alert) return alert def add(self, alert): @@ -566,9 +566,9 @@ def add(self, alert): alertobj = self._fill(self.argus._request("post", "alerts", dataObj=alert)) self._coll[alertobj.id] = alertobj if alert.trigger: - alertobj.trigger = alertobj.triggers.add(alert.trigger) + alertobj.trigger = alertobj.triggers_client.add(alert.trigger) if alert.notification: - alertobj.notification = alertobj.notifications.add(alert.notification) + alertobj.notification = alertobj.notifications_client.add(alert.notification) if alert.trigger and alert.notification: self.argus.alerts.add_notification_trigger(alertobj.id, alertobj.notification.id, alertobj.trigger.id) alertobj.notification.triggersIds = [alertobj.trigger.id] diff --git a/argusclient/model.py b/argusclient/model.py index f26f2c9..d94b171 100644 --- a/argusclient/model.py +++ b/argusclient/model.py @@ -329,6 +329,8 @@ class Alert(BaseEncodable): def __init__(self, name, expression, cronEntry, **kwargs): self._triggers = None self._notifications = None + self._triggers_client = None + self._notifications_client = None super(Alert, self).__init__(name=name, expression=expression, cronEntry=cronEntry, **kwargs) @property @@ -357,6 +359,10 @@ def triggers(self, value): # TODO Check for item type also self._triggers = value + @property + def triggers_client(self): + return self._triggers_client + @property def notification(self): """ A convenience property to be used when :attr:`notifications` contains a single :class:`argusclient.model.Notification`. """ @@ -383,6 +389,10 @@ def notifications(self, value): # TODO Check for item type also self._notifications = value + @property + def notifications_client(self): + return self._notifications_client + class Trigger(BaseEncodable): """