Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Alert_rule] added all functionality in alert_rule #154

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Changes from 2 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
19 changes: 16 additions & 3 deletions plugins/modules/alert_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- Event group categories to be alerted.
type: list
elements: str
choices: ['SYS_DISK_EVENTS', 'NODE_STATUS_EVENTS', 'REBOOT_EVENTS',
choices: ['all', 'SYS_DISK_EVENTS', 'NODE_STATUS_EVENTS', 'REBOOT_EVENTS',
'SW_EVENTS', 'QUOTA_EVENTS', 'SNAP_EVENTS', 'WINNET_EVENTS', 'FILESYS_EVENTS',
'HW_EVENTS', 'CPOOL_EVENTS']
channels:
Expand Down Expand Up @@ -252,7 +252,7 @@ def get_alert_rule_parameters(self):
condition=dict(type='str', choices=['NEW', 'NEW EVENTS', 'ONGOING',
'SEVERITY INCREASE', 'SEVERITY DECREASE', 'RESOLVED']),
categories=dict(type='list', elements='str',
choices=['SYS_DISK_EVENTS', 'NODE_STATUS_EVENTS',
choices=['all', 'SYS_DISK_EVENTS', 'NODE_STATUS_EVENTS',
'REBOOT_EVENTS', 'SW_EVENTS', 'QUOTA_EVENTS',
'SNAP_EVENTS', 'WINNET_EVENTS', 'FILESYS_EVENTS',
'HW_EVENTS', 'CPOOL_EVENTS']),
Expand Down Expand Up @@ -286,7 +286,12 @@ def get_alert_rule(self, module_params):
break

if alert_rule.get("categories"):
categories = sorted([category_dict[key] for key in alert_rule["categories"]], reverse=True)
categories = alert_rule["categories"]
if "all" in categories:
categories = ["all"]
else:
categories = sorted([category_dict[key] for key in alert_rule["categories"]], reverse=True)

alert_rule.update({"categories": categories})
return alert_rule

Expand All @@ -308,12 +313,19 @@ def get_module_params(self, module_params):
data_dict.update({"exclude_eventgroup_ids": []})
return data_dict

def process_categories(self, module_params, alert_data):
categories = module_params.get('categories', [])
if "all" in categories:
alert_data["categories"] = ["all"]
return alert_data

def create_alert_condition(self, module_params):
changed = False
alert_data = self.get_module_params(module_params)

if not self.module.check_mode:
try:
alert_data = self.process_categories(module_params, alert_data)
self.event_api.create_event_alert_condition(alert_data)
alert_data = self.get_alert_rule(module_params)
changed = True
Expand Down Expand Up @@ -362,6 +374,7 @@ def modify_alert_condition(self, alert_rule_details, module_params):
try:
updated_payload.pop("name")
rule_id = updated_payload.pop("id")
alert_data = self.process_categories(module_params, alert_data)
self.event_api.update_event_alert_condition(updated_payload, rule_id)
alert_data = self.get_alert_rule(module_params)
changed = True
Expand Down