Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 10.0.1
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 DOCUMENTATION = r'''
13 ---
14 module: ome_alert_policies_message_id_info
15 short_description: Get message ID information of alert policies.
16 version_added: "8.2.0"
17 description:
18 - "This module retrieves the message ID information of alert policies for OpenManage Enterprise
19 and OpenManage Enterprise Modular."
20 extends_documentation_fragment:
21 - dellemc.openmanage.ome_auth_options
22 requirements:
23 - "python >= 3.9.6"
24 author: "Shivam Sharma (@ShivamSh3)"
25 notes:
26 - Run this module from a system that has direct access to Dell OpenManage Enterprise
27 or OpenManage Enterprise Modular.
28 - This module supports C(check_mode).
29 - This module supports IPv4 and IPv6 addresses.
30 '''
31
32 EXAMPLES = r'''
33 ---
34 - name: Get message ID details of all alert policies
35 dellemc.openmanage.ome_alert_policies_message_id_info:
36 hostname: "192.168.0.1"
37 username: "username"
38 password: "password"
39 ca_path: "/path/to/ca_cert.pem"
40 '''
41
42 RETURN = r'''
43 ---
44 msg:
45 description: "Status of the alert policies message ids fetch operation."
46 returned: always
47 type: str
48 sample: "Successfully retrieved alert policies message ids information."
49 message_ids:
50 type: dict
51 description: Details of the message ids.
52 returned: success
53 sample: [
54 {
55 "Category": "System Health",
56 "DetailedDescription": "The current sensor identified in the message has failed. This condition
57 can cause system performance issues and degradation in the monitoring capability of the system.",
58 "Message": "The ${0} sensor has failed, and the last recorded value by the sensor was ${1} A.",
59 "MessageId": "AMP400",
60 "Prefix": "AMP",
61 "RecommendedAction": "Check the Embedded System Management (ESM) Log for any sensor related faults.
62 If there is a failed sensor, replace the system board. For more information, contact your service provider.",
63 "SequenceNo": 400,
64 "Severity": "Critical",
65 "SubCategory": "Amperage"
66 },
67 {
68 "Category": "System Health",
69 "DetailedDescription": "The current sensor identified in the message has failed. This condition can cause
70 system performance issues and degradation in the monitoring capability of the system.",
71 "Message": "Unable to read the ${0} sensor value.",
72 "MessageId": "AMP401",
73 "Prefix": "AMP",
74 "RecommendedAction": "Check the Embedded System Management (ESM) Log for any sensor related faults. If
75 there is a failed sensor, replace the system board. For more information, contact your service provider.",
76 "SequenceNo": 401,
77 "Severity": "Warning",
78 "SubCategory": "Amperage"
79 }
80 ]
81 error_info:
82 type: dict
83 description: Details of the HTTP Error.
84 returned: on HTTP error
85 sample: {
86 "error": {
87 "code": "Base.1.0.GeneralError",
88 "message": "A general error has occurred. See ExtendedInfo for more information.",
89 "@Message.ExtendedInfo": [
90 {
91 "MessageId": "GEN1234",
92 "RelatedProperties": [],
93 "Message": "Unable to process the request because an error occurred.",
94 "MessageArgs": [],
95 "Severity": "Critical",
96 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
97 }
98 ]
99 }
100 }
101 '''
102
103 import json
104 from ssl import SSLError
105 from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule
106 from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import remove_key, get_all_data_with_pagination
107 from urllib.error import HTTPError, URLError
108 from ansible.module_utils.urls import ConnectionError, SSLValidationError
109
110 ALERT_MESSAGE_URI = "AlertService/AlertMessageDefinitions"
111 SUCCESSFUL_MSG = "Successfully retrieved alert policies message ids information."
112 EMPTY_MSG = "No alert policies message id information were found."
113
114
115 def main():
116 specs = {}
117 module = OmeAnsibleModule(
118 argument_spec=specs,
119 supports_check_mode=True
120 )
121 try:
122 with RestOME(module.params, req_session=True) as rest_obj:
123 message_id_info = get_all_data_with_pagination(rest_obj, ALERT_MESSAGE_URI)
124 if not message_id_info.get("report_list", []):
125 module.exit_json(msg=EMPTY_MSG, message_ids=[])
126 message_ids = remove_key(message_id_info['report_list'])
127 module.exit_json(msg=SUCCESSFUL_MSG, message_ids=message_ids)
128 except HTTPError as err:
129 module.exit_json(msg=str(err), error_info=json.load(err), failed=True)
130 except URLError as err:
131 module.exit_json(msg=str(err), unreachable=True)
132 except (SSLValidationError, ConnectionError, TypeError, ValueError, OSError, SSLError) as err:
133 module.exit_json(msg=str(err), failed=True)
134
135
136 if __name__ == '__main__':
137 main()