Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/spaceone/monitoring/manager/alert_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def _rollback(vo: Alert) -> None:
params["domain_id"], params["workspace_id"]
)
params["alert_number_str"] = str(params["alert_number"])
print(params)
alert_vo: Alert = self.alert_model.create(params)
self.transaction.add_rollback(_rollback, alert_vo)

Expand Down
9 changes: 6 additions & 3 deletions src/spaceone/monitoring/manager/event_rule_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def get_event_rule(
def list_event_rules(self, query: dict) -> dict:
return self.event_rule_model.query(**query)

def filter_event_rules(self, **conditions):
return self.event_rule_model.filter(**conditions)

def stat_event_rules(self, query: dict) -> dict:
return self.event_rule_model.stat(**query)

Expand Down Expand Up @@ -221,7 +224,7 @@ def _get_service_account(self, target_key, target_value, domain_id):
if total_count > 0:
service_account_info = results[0]

self._service_account_info[
f"{domain_id}:{target_key}:{target_value}"
] = service_account_info
self._service_account_info[f"{domain_id}:{target_key}:{target_value}"] = (
service_account_info
)
return service_account_info
2 changes: 2 additions & 0 deletions src/spaceone/monitoring/service/alert_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from datetime import datetime

from pandas.io.sas.sas_constants import page_size_length
from spaceone.core import utils, cache
from spaceone.core.service import *

Expand Down Expand Up @@ -468,6 +469,7 @@ def get(self, params):
]
)
@append_keyword_filter(["alert_id", "alert_number_str", "title"])
@set_query_page_limit(1000)
def list(self, params):
"""List alerts

Expand Down
44 changes: 42 additions & 2 deletions src/spaceone/monitoring/service/event_rule_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def create(self, params: dict) -> EventRule:
self._check_conditions(params["conditions"])
self._check_actions(params["actions"], domain_id, workspace_id, identity_mgr)

self._check_recursive_actions(
identity_mgr, params["actions"], domain_id, workspace_id, []
)

params["order"] = (
self._get_highest_order(resource_group, project_id, domain_id, workspace_id)
+ 1
Expand Down Expand Up @@ -142,14 +146,17 @@ def update(self, params: dict) -> EventRule:
if "conditions" in params:
self._check_conditions(params["conditions"])

if "actions" in params:
if actions := params.get("actions", {}):
identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
self._check_actions(
params["actions"],
actions,
domain_id,
workspace_id,
identity_mgr,
)
self._check_recursive_actions(
identity_mgr, actions, domain_id, workspace_id, []
)

return self.event_rule_mgr.update_event_rule_by_vo(params, event_rule_vo)

Expand Down Expand Up @@ -428,6 +435,39 @@ def _check_actions(
key="actions.no_notification", type="bool"
)

def _check_recursive_actions(
self,
identity_mgr: IdentityManager,
actions: dict,
domain_id: str,
workspace_id: str,
project_ids: list,
) -> list:
if change_project_id := actions.get("change_project"):
if change_project_id in project_ids:
_LOGGER.error(
f"[_check_recursive_actions] change_project_id {change_project_id}, project ids: {project_ids} "
)
raise ERROR_INVALID_PARAMETER(
key="actions.change_project",
reason=f"The {change_project_id} in the action should be different from the project_id in the event rule.",
)
else:
project_ids.append(change_project_id)
event_rule_vos = self.event_rule_mgr.filter_event_rules(
domain_id=domain_id,
workspace_id=workspace_id,
project_id=change_project_id,
)
for event_rule_vo in event_rule_vos:
self._check_recursive_actions(
identity_mgr,
event_rule_vo.actions,
domain_id,
workspace_id,
project_ids,
)

@staticmethod
def _check_order(order: int) -> None:
if order <= 0:
Expand Down
Loading