Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/ome_alert_policies_actions_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 9.3.0
7 # Copyright (C) 2023-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
8
9 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
10 #
11
12 from __future__ import (absolute_import, division, print_function)
13 __metaclass__ = type
14
15 DOCUMENTATION = r'''
16 ---
17 module: ome_alert_policies_actions_info
18 short_description: Get information on actions of alert policies.
19 version_added: "8.2.0"
20 description:
21 - This module retrieves the information on actions of alert policies for OpenManage Enterprise
22 and OpenManage Enterprise Modular.
23 extends_documentation_fragment:
24 - dellemc.openmanage.ome_auth_options
25 requirements:
26 - "python >= 3.9.6"
27 author:
28 - "Kritika Bhateja (@Kritika-Bhateja-03)"
29 notes:
30 - Run this module from a system that has direct access to Dell OpenManage Enterprise
31 or OpenManage Enterprise Modular.
32 - This module supports both IPv4 and IPv6 addresses.
33 - This module supports C(check_mode).
34 '''
35
36 EXAMPLES = r'''
37 ---
38 - name: Get action details of all alert policies.
39 dellemc.openmanage.ome_alert_policies_actions_info:
40 hostname: "192.168.0.1"
41 username: "username"
42 password: "password"
43 ca_path: "/path/to/ca_cert.pem"
44 '''
45
46 RETURN = r'''
47 ---
48 actions:
49 type: list
50 description: Returns the alert policies action information collected from the Device.
51 returned: success
52 sample: [
53 {
54 "Name": "Email",
55 "Description": "Email",
56 "Disabled": false,
57 "ParameterDetails": [
58 {
59 "Id": 1,
60 "Name": "subject",
61 "Value": "Device Name: $name, Device IP Address: $ip, Severity: $severity",
62 "Type": "string",
63 "TemplateParameterTypeDetails": [
64 {
65 "Name": "maxLength",
66 "Value": "255"
67 }
68 ]
69 },
70 {
71 "Id": 2,
72 "Name": "to",
73 "Value": "",
74 "Type": "string",
75 "TemplateParameterTypeDetails": [
76 {
77 "Name": "maxLength",
78 "Value": "255"
79 }
80 ]
81 },
82 {
83 "Id": 3,
84 "Name": "from",
85 "Value": "[email protected]",
86 "Type": "string",
87 "TemplateParameterTypeDetails": [
88 {
89 "Name": "maxLength",
90 "Value": "255"
91 }
92 ]
93 },
94 {
95 "Id": 4,
96 "Name": "message",
97 "Value": "Event occurred for Device Name: $name,
98 Device IP Address: $ip, Service Tag: $identifier, UTC Time: $time, Severity: $severity, Message ID: $messageId, $message",
99 "Type": "string",
100 "TemplateParameterTypeDetails": [
101 {
102 "Name": "maxLength",
103 "Value": "255"
104 }
105 ]
106 },
107 {
108 "Id": 60,
109 "Name": "Trap",
110 "Description": "Trap",
111 "Disabled": false,
112 "ParameterDetails": [
113 {
114 "Id": 1,
115 "Name": "localhost:162",
116 "Value": "true",
117 "Type": "boolean",
118 "TemplateParameterTypeDetails": []
119 }
120 ]
121 },
122 {
123 "Id": 90,
124 "Name": "Syslog",
125 "Description": "Syslog",
126 "Disabled": false,
127 "ParameterDetails": [
128 {
129 "Id": 1,
130 "Name": "localhost.scomdev.com:555",
131 "Value": "true",
132 "Type": "boolean",
133 "TemplateParameterTypeDetails": []
134 },
135 {
136 "Id": 2,
137 "Name": "localhost.scomdev.com:555",
138 "Value": "true",
139 "Type": "boolean",
140 "TemplateParameterTypeDetails": []
141 }
142 ]
143 },
144 {
145 "Id": 100,
146 "Name": "Ignore",
147 "Description": "Ignore",
148 "Disabled": false,
149 "ParameterDetails": []
150 },
151 {
152 "Id": 70,
153 "Name": "SMS",
154 "Description": "SMS",
155 "Disabled": false,
156 "ParameterDetails": [
157 {
158 "Id": 1,
159 "Name": "to",
160 "Value": "",
161 "Type": "string",
162 "TemplateParameterTypeDetails": [
163 {
164 "Name": "maxLength",
165 "Value": "255"
166 }
167 ]
168 }
169 ]
170 },
171 {
172 "Id": 110,
173 "Name": "PowerControl",
174 "Description": "Power Control Action Template",
175 "Disabled": false,
176 "ParameterDetails": [
177 {
178 "Id": 1,
179 "Name": "powercontrolaction",
180 "Value": "poweroff",
181 "Type": "singleSelect",
182 "TemplateParameterTypeDetails": [
183 {
184 "Name": "option",
185 "Value": "powercycle"
186 },
187 {
188 "Name": "option",
189 "Value": "poweroff"
190 },
191 {
192 "Name": "option",
193 "Value": "poweron"
194 },
195 {
196 "Name": "option",
197 "Value": "gracefulshutdown"
198 }
199 ]
200 }
201 ]
202 },
203 {
204 "Id": 111,
205 "Name": "RemoteCommand",
206 "Description": "RemoteCommand",
207 "Disabled": true,
208 "ParameterDetails": [
209 {
210 "Id": 1,
211 "Name": "remotecommandaction",
212 "Value": null,
213 "Type": "singleSelect",
214 "TemplateParameterTypeDetails": []
215 }
216 ]
217 },
218 {
219 "Id": 112,
220 "Name": "Mobile",
221 "Description": "Mobile",
222 "Disabled": false,
223 "ParameterDetails": []
224 }
225 ]
226 }
227 ]
228 error_info:
229 description: Details of the HTTP Error.
230 returned: on HTTP error
231 type: dict
232 sample: {
233 "error": {
234 "code": "Base.1.0.GeneralError",
235 "message": "A general error has occurred. See ExtendedInfo for more information.",
236 "@Message.ExtendedInfo": [
237 {
238 "MessageId": "GEN1234",
239 "RelatedProperties": [],
240 "Message": "Unable to process the request because an error occurred.",
241 "MessageArgs": [],
242 "Severity": "Critical",
243 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
244 }
245 ]
246 }
247 }
248 msg:
249 description: Status of the alert policies actions fetch operation.
250 returned: always
251 type: str
252 sample: Successfully retrieved alert policies actions information.
253 '''
254
255 import json
256 from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule
257 from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import remove_key
258 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
259 from ansible.module_utils.urls import ConnectionError, SSLValidationError
260 from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import get_all_data_with_pagination
261
262 ACTIONS_URI = "AlertService/AlertActionTemplates"
263 SUCCESSFUL_MSG = "Successfully retrieved alert policies actions information."
264 EMPTY_ALERT_POLICY_ACTION_MSG = "No alert policies action information were found."
265
266
267 def main():
268 """ function to retrieve the information on actions of alert policies """
269 specs = {}
270 module = OmeAnsibleModule(
271 argument_spec=specs,
272 supports_check_mode=True)
273 try:
274 with RestOME(module.params, req_session=True) as rest_obj:
275 actions_info = get_all_data_with_pagination(rest_obj, ACTIONS_URI)
276 if not actions_info.get("report_list", []):
277 module.exit_json(msg=EMPTY_ALERT_POLICY_ACTION_MSG, actions=[])
278 actions = remove_key(actions_info['report_list'])
279 module.exit_json(msg=SUCCESSFUL_MSG, actions=actions)
280 except HTTPError as err:
281 module.exit_json(msg=str(err), error_info=json.load(err), failed=True)
282 except URLError as err:
283 module.exit_json(msg=str(err), unreachable=True)
284 except (SSLValidationError, ConnectionError, TypeError, ValueError, OSError) as err:
285 module.exit_json(msg=str(err), failed=True)
286
287
288 if __name__ == '__main__':
289 main()