Skip to content

Commit

Permalink
Merge pull request #31 from lhhyung/master
Browse files Browse the repository at this point in the history
Update regex patterns
  • Loading branch information
lhhyung authored Dec 12, 2024
2 parents 0065fe5 + 3ee8c33 commit 1ca53d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/pip_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spaceone-api
spaceone-monitoring
regex

21 changes: 11 additions & 10 deletions src/plugin/manager/event_manager/standard_manager.py
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -85,15 +86,15 @@ 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:
filtered_message = self.__remove_keys(
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:
Expand All @@ -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 = {}
Expand Down Expand Up @@ -138,10 +139,10 @@ 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+),? ?(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)

Expand Down

0 comments on commit 1ca53d9

Please sign in to comment.