From 446fa1485a189dfa2d105059caa160bdcdac21b7 Mon Sep 17 00:00:00 2001 From: sbgap Date: Mon, 3 Mar 2025 10:41:09 +0100 Subject: [PATCH] refac: remove leading and trailing whitespaces from tags - remove leading and trailing whitespaces from tags in alerts - remove leading and trailing whitespaces from tags in blackouts - remove leading and trailing whitespaces from tags in advanced tags (notification/escalation rules) --- alerta/models/alert.py | 2 +- alerta/models/blackout.py | 4 ++-- alerta/models/notification_rule.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/alerta/models/alert.py b/alerta/models/alert.py index 4a190bc91..f927e7c69 100644 --- a/alerta/models/alert.py +++ b/alerta/models/alert.py @@ -62,7 +62,7 @@ def __init__(self, resource: str, event: str, **kwargs) -> None: self.group = kwargs.get('group', None) or 'Misc' self.value = kwargs.get('value', None) self.text = kwargs.get('text', None) or '' - self.tags = kwargs.get('tags', None) or list() + self.tags = [tag.strip() for tag in kwargs.get('tags', None) or list()] self.attributes = kwargs.get('attributes', None) or dict() self.origin = kwargs.get('origin', None) or f'{os.path.basename(sys.argv[0])}/{platform.uname()[1]}' self.event_type = kwargs.get('event_type', kwargs.get('type', None)) or 'exceptionAlert' diff --git a/alerta/models/blackout.py b/alerta/models/blackout.py index a4d02bde7..4cfea5683 100644 --- a/alerta/models/blackout.py +++ b/alerta/models/blackout.py @@ -48,7 +48,7 @@ def __init__(self, environment: str, **kwargs) -> None: self.resource = kwargs.get('resource', None) self.event = kwargs.get('event', None) self.group = kwargs.get('group', None) - self.tags = kwargs.get('tags', None) or list() + self.tags = list({tag.strip() for tag in kwargs.get('tags', None) or list()}) self.origin = kwargs.get('origin', None) self.customer = kwargs.get('customer', None) self.start_time = start_time @@ -124,7 +124,7 @@ def serialize(self) -> Dict[str, Any]: 'resource': self.resource, 'event': self.event, 'group': self.group, - 'tags': self.tags, + 'tags': list(self.tags), 'origin': self.origin, 'customer': self.customer, 'startTime': self.start_time, diff --git a/alerta/models/notification_rule.py b/alerta/models/notification_rule.py index d9e3fbfb2..5439d5076 100644 --- a/alerta/models/notification_rule.py +++ b/alerta/models/notification_rule.py @@ -17,8 +17,8 @@ class AdvancedTags: def __init__(self, all: 'list[str]', any: 'list[str]') -> None: - self.all = all or [] - self.any = any or [] + self.all = list({a.strip() for a in all}) + self.any = list({a.strip() for a in any}) @property def serialize(self):