Skip to content

Commit

Permalink
Merge pull request #15 from gikang82/v2_support
Browse files Browse the repository at this point in the history
bug: update wrong status param.
  • Loading branch information
gikang82 authored Dec 8, 2023
2 parents a6f315b + 2466222 commit 7d4c7d9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/plugin/error.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from spaceone.core.error import *


class ERROR_INVALID_WEBHOOK_TYPE(ERROR_BASE):
class ERROR_INVALID_WEBHOOK_TYPE(ERROR_INVALID_PARAMETER_TYPE):
_message = 'Wrong Webhook Type(webhook_type= {webhook_type})'


class ERROR_CONVERT_TITLE(ERROR_BASE):
_message = 'Failed to convert alert title'


class ERROR_REQUIRED_FIELDS(ERROR_BASE):
_message = 'Required field is missing(field= {field})'

Expand All @@ -18,3 +19,4 @@ class ERROR_PARSE_EVENT(ERROR_BASE):

class ERROR_CONVERT_DATA_TYPE(ERROR_BASE):
_message = 'Failed to convert data type'

1 change: 1 addition & 0 deletions src/plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
app = WebhookPluginServer()



@app.route('Webhook.init')
def webhook_init(params: dict) -> dict:
""" init plugin by options
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/manager/event_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def get_parse_manager_by_webhook_type(cls, webhook_type):
for subclass in cls.__subclasses__():
if subclass.webhook_type == webhook_type:
return subclass()
raise ERROR_INVALID_WEBHOOK_TYPE(webhook_type=webhook_type)
raise ERROR_INVALID_WEBHOOK_TYPE(webhook_type=webhook_type)
10 changes: 3 additions & 7 deletions src/plugin/manager/event_manager/standard_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from plugin.manager.event_manager import ParseManager
from plugin.error import *


_LOGGER = logging.getLogger("spaceone")


class StandardManager(ParseManager):

webhook_type = "STANDARD"

def parse(self, raw_data: dict) -> dict:
Expand All @@ -29,14 +27,13 @@ def parse(self, raw_data: dict) -> dict:
_LOGGER.debug(f"[StandardManager] data => {raw_data}")
event_dict = {
"event_key": self.generate_event_key(raw_data),
"event_type": self.get_event_type(raw_data.get("state", "")),
"severity": self.get_severity(raw_data.get("state", "")),
"event_type": self.get_event_type(raw_data.get("status", "")),
"severity": self.get_severity(raw_data.get("status", "")),
"title": self.remove_alert_code_from_title(raw_data.get("title")),
"rule": raw_data.get("groupKey", ""),
"image_url": self._get_value_from_alerts(raw_data, "panelURL"),
"resource": {},
"description": raw_data.get("message", ""),
#"occurred_at": utils.datetime_to_iso8601(parser.parse(self._get_value_from_alerts(raw_data, "startsAt"))),
"occurred_at": self._convert_to_iso8601(self._get_value_from_alerts(raw_data, "startsAt")),
"additional_info": self.get_additional_info(raw_data)
}
Expand Down Expand Up @@ -124,8 +121,7 @@ def _get_value_from_alerts(self, raw_data: dict, key: str) -> Union[dict, dateti

@staticmethod
def _get_alerts_cnt(raw_data: dict) -> int:
alerts = raw_data.get("alerts", "")
return len(alerts)
return len(raw_data.get("alerts", ""))

@staticmethod
def _convert_to_iso8601(raw_time: str) -> Union[str, None]:
Expand Down

0 comments on commit 7d4c7d9

Please sign in to comment.