Skip to content

Commit

Permalink
Merge pull request #137 from whdalsrnt/master
Browse files Browse the repository at this point in the history
fix: fix notification bug
  • Loading branch information
whdalsrnt authored Aug 29, 2024
2 parents 8f62076 + dc9eacb commit 4cb0e82
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/spaceone/monitoring/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ def _create_message(

callbacks = []

access_key = self._create_access_key(alert_vo.alert_id)

if has_callback:
access_key = self._generate_access_key()
callback_url = self._make_callback_url(
alert_vo.alert_id, domain_id, access_key
)
Expand Down Expand Up @@ -540,6 +541,27 @@ def _create_message(
"notification_level": notification_level,
}

def _create_access_key(self, alert_id: str) -> str:
def _rollback(alert_id: str, access_key: str):
_LOGGER.info(
f"[_make_callback_url._rollback] "
f"Delete cache : {alert_id} "
f"({access_key})"
)
cache.delete(
f"monitoring:alert:notification-callback:{alert_id}:{access_key}"
)

access_key = self._generate_access_key()

cache.set(
f"monitoring:alert:notification-callback:{alert_id}:{access_key}",
True,
expire=3600,
)
self.transaction.add_rollback(_rollback, alert_id, access_key)
return access_key

@cache.cacheable(key="monitoring:project-name:{domain_id}:{project_id}", expire=300)
def _get_project_name(self, project_id: str, domain_id: str) -> str:
try:
Expand Down Expand Up @@ -600,24 +622,8 @@ def _get_user_name(self, user_id: str, domain_id: str) -> str:
def _generate_access_key():
return utils.random_string(16)

def _make_callback_url(self, alert_id, domain_id, access_key):
def _rollback(alert_id, access_key):
_LOGGER.info(
f"[_make_callback_url._rollback] "
f"Delete cache : {alert_id} "
f"({access_key})"
)
cache.delete(
f"monitoring:alert:notification-callback:{alert_id}:{access_key}"
)

cache.set(
f"monitoring:alert:notification-callback:{alert_id}:{access_key}",
True,
expire=3600,
)
self.transaction.add_rollback(_rollback, alert_id, access_key)

@staticmethod
def _make_callback_url(alert_id, domain_id, access_key):
webhook_domain = config.get_global("WEBHOOK_DOMAIN")
return f"{webhook_domain}/monitoring/v1/domain/{domain_id}/alert/{alert_id}/{access_key}/ACKNOWLEDGED"

Expand Down

0 comments on commit 4cb0e82

Please sign in to comment.