From 1d86283e34fab242c617b4d3eadd9fc4bd474531 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 12 Dec 2024 11:38:30 +0900 Subject: [PATCH 1/3] refactor: Update regex patterns Signed-off-by: lhhyung --- .../manager/event_manager/standard_manager.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/plugin/manager/event_manager/standard_manager.py b/src/plugin/manager/event_manager/standard_manager.py index fc318d8..465efb0 100644 --- a/src/plugin/manager/event_manager/standard_manager.py +++ b/src/plugin/manager/event_manager/standard_manager.py @@ -1,16 +1,17 @@ -import logging import hashlib -import re -from typing import Union, List +import logging from datetime import datetime +from typing import Union, List +import regex from spaceone.core import utils -from plugin.manager.event_manager import ParseManager + from plugin.error import ( ERROR_REQUIRED_FIELDS, ERROR_CONVERT_TITLE, ERROR_CONVERT_DATA_TYPE, ) +from plugin.manager.event_manager import ParseManager _LOGGER = logging.getLogger("spaceone") @@ -85,7 +86,7 @@ def get_severity(self, event_status: str) -> str: def _get_message(self, raw_data: dict) -> str: message = utils.get_dict_value(raw_data, "message") - no_value_data = re.search(r"\[no value\]", message) + no_value_data = regex.search(r"\[no value\]", message) if no_value_data: return "DatasourceNoData" else: @@ -93,7 +94,7 @@ def _get_message(self, raw_data: dict) -> str: message, ["Annotations", "Source", "Silence"] ) alerts = utils.get_dict_value(raw_data, "alerts") - filtered_message = re.sub(r"\n{3,}", "\n\n", filtered_message) + filtered_message = regex.sub(r"\n{3,}", "\n\n", filtered_message) filtered_message += "ValueString: \n" for alert in alerts: @@ -110,7 +111,7 @@ def _get_message(self, raw_data: dict) -> str: @staticmethod def __remove_keys(text: str, keys: List[str]) -> str: pattern = r"|".join(rf"{key}:\s+.*" for key in keys) - return re.sub(pattern, "", text, flags=re.MULTILINE) + return regex.sub(pattern, "", text, flags=regex.MULTILINE) def get_additional_info(self, raw_data: dict) -> dict: additional_info = {} @@ -138,10 +139,8 @@ def remove_alert_code_from_title(self, title: str) -> str: :return: """ try: - title = re.sub("\[[FIRING|RESOLVED]+\:+[0-9]+\] ", "", title) - title = re.sub( - "[\[+[a-zA-Z]+\:+[0-9]+\,+.+[a-zA-Z]+\:+[0-9]+\] ", "", title - ) + title = regex.sub(r"\[(FIRING|RESOLVED):\d+\]\s", "", title) + title = regex.sub(r"\[([a-zA-Z]+:\d+,\s*[a-zA-Z]+:\d+)\]\s", "", title) except Exception: ERROR_CONVERT_TITLE(title) From c77e834b3aa9d567fe952264b77732a9a6f7509c Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 12 Dec 2024 14:28:27 +0900 Subject: [PATCH 2/3] refactor: Update regex patterns Signed-off-by: lhhyung --- src/plugin/manager/event_manager/standard_manager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugin/manager/event_manager/standard_manager.py b/src/plugin/manager/event_manager/standard_manager.py index 465efb0..d4505a5 100644 --- a/src/plugin/manager/event_manager/standard_manager.py +++ b/src/plugin/manager/event_manager/standard_manager.py @@ -139,7 +139,9 @@ def remove_alert_code_from_title(self, title: str) -> str: :return: """ try: - title = regex.sub(r"\[(FIRING|RESOLVED):\d+\]\s", "", title) + title = regex.sub( + r"\[(FIRING|RESOLVED):(\d+),? ?(FIRING|RESOLVED)?:?(\d+)?\]", "", title + ) title = regex.sub(r"\[([a-zA-Z]+:\d+,\s*[a-zA-Z]+:\d+)\]\s", "", title) except Exception: ERROR_CONVERT_TITLE(title) From 3ee8c331f2eb5847e43230015e0fd2afad406484 Mon Sep 17 00:00:00 2001 From: lhhyung Date: Thu, 12 Dec 2024 14:34:06 +0900 Subject: [PATCH 3/3] build: Add require package Signed-off-by: lhhyung --- pkg/pip_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/pip_requirements.txt b/pkg/pip_requirements.txt index b3ae5fd..af7dffa 100644 --- a/pkg/pip_requirements.txt +++ b/pkg/pip_requirements.txt @@ -1,3 +1,4 @@ spaceone-api spaceone-monitoring +regex