Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 9.12.1
7 # Copyright (C) 2018-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
13 from __future__ import (absolute_import, division, print_function)
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 ---
18 module: idrac_syslog
19 short_description: Enable or disable the syslog on iDRAC
20 version_added: "2.1.0"
21 deprecated:
22 removed_at_date: "2027-05-27"
23 why: Replaced with M(dellemc.openmanage.idrac_attributes).
24 alternative: Use M(dellemc.openmanage.idrac_attributes) instead.
25 removed_from_collection: dellemc.openmanage
26 description:
27 - This module allows to enable or disable the iDRAC syslog.
28 extends_documentation_fragment:
29 - dellemc.openmanage.idrac_auth_options
30 - dellemc.openmanage.network_share_options
31 options:
32 syslog:
33 description: Enables or disables an iDRAC syslog.
34 choices: [Enabled, Disabled]
35 type: str
36 default: Enabled
37 requirements:
38 - "omsdk >= 1.2.488"
39 - "python >= 3.9.6"
40 author:
41 - "Felix Stephen (@felixs88)"
42 - "Anooja Vardhineni (@anooja-vardhineni)"
43 - "Abhishek Sinha (@ABHISHEK-SINHA10)"
44 notes:
45 - This module requires 'Administrator' privilege for I(idrac_user).
46 - Run this module from a system that has direct access to Dell iDRAC.
47 - This module supports both IPv4 and IPv6 address for I(idrac_ip).
48 - This module supports C(check_mode).
49 """
50
51 EXAMPLES = """
52 ---
53 - name: Enable iDRAC syslog
54 dellemc.openmanage.idrac_syslog:
55 idrac_ip: "192.168.0.1"
56 idrac_user: "user_name"
57 idrac_password: "user_password"
58 ca_path: "/path/to/ca_cert.pem"
59 share_name: "192.168.0.2:/share"
60 share_password: "share_user_pwd"
61 share_user: "share_user_name"
62 share_mnt: "/mnt/share"
63 syslog: "Enabled"
64
65 - name: Disable iDRAC syslog
66 dellemc.openmanage.idrac_syslog:
67 idrac_ip: "192.168.0.1"
68 idrac_user: "user_name"
69 idrac_password: "user_password"
70 ca_path: "/path/to/ca_cert.pem"
71 share_name: "192.168.0.2:/share"
72 share_password: "share_user_pwd"
73 share_user: "share_user_name"
74 share_mnt: "/mnt/share"
75 syslog: "Disabled"
76 """
77
78 RETURN = r'''
79 ---
80 msg:
81 description: Overall status of the syslog export operation.
82 returned: always
83 type: str
84 sample: "Successfully fetch the syslogs."
85 syslog_status:
86 description: Job details of the syslog operation.
87 returned: success
88 type: dict
89 sample: {
90 "@odata.context": "/redfish/v1/$metadata#DellJob.DellJob",
91 "@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/JID_852940632485",
92 "@odata.type": "#DellJob.v1_0_2.DellJob",
93 "CompletionTime": "2020-03-27T02:27:45",
94 "Description": "Job Instance",
95 "EndTime": null,
96 "Id": "JID_852940632485",
97 "JobState": "Completed",
98 "JobType": "ImportConfiguration",
99 "Message": "Successfully imported and applied Server Configuration Profile.",
100 "MessageArgs": [],
101 "[email protected]": 0,
102 "MessageId": "SYS053",
103 "Name": "Import Configuration",
104 "PercentComplete": 100,
105 "StartTime": "TIME_NOW",
106 "Status": "Success",
107 "TargetSettingsURI": null,
108 "retval": true
109 }
110 error_info:
111 description: Details of the HTTP Error.
112 returned: on HTTP error
113 type: dict
114 sample: {
115 "error": {
116 "code": "Base.1.0.GeneralError",
117 "message": "A general error has occurred. See ExtendedInfo for more information.",
118 "@Message.ExtendedInfo": [
119 {
120 "MessageId": "GEN1234",
121 "RelatedProperties": [],
122 "Message": "Unable to process the request because an error occurred.",
123 "MessageArgs": [],
124 "Severity": "Critical",
125 "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
126 }
127 ]
128 }
129 }
130 '''
131
132
133 import json
134 from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params
135 from ansible.module_utils.basic import AnsibleModule
136 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
137 from ansible.module_utils.urls import ConnectionError, SSLValidationError
138
139 try:
140 from omsdk.sdkfile import file_share_manager
141 from omsdk.sdkcreds import UserCredentials
142 except ImportError:
143 pass
144
145
146 def run_setup_idrac_syslog(idrac, module):
147 idrac.use_redfish = True
148 upd_share = file_share_manager.create_share_obj(share_path=module.params['share_name'],
149 mount_point=module.params['share_mnt'],
150 isFolder=True,
151 creds=UserCredentials(
152 module.params['share_user'],
153 module.params['share_password']))
154 if not upd_share.IsValid:
155 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
156 "share mount, and share credentials provided are correct.")
157 idrac.config_mgr.set_liason_share(upd_share)
158 if module.check_mode:
159 if module.params['syslog'] == 'Enabled':
160 idrac.config_mgr.enable_syslog(apply_changes=False)
161 elif module.params['syslog'] == 'Disabled':
162 idrac.config_mgr.disable_syslog(apply_changes=False)
163 msg = idrac.config_mgr.is_change_applicable()
164 else:
165 if module.params['syslog'] == 'Enabled':
166 msg = idrac.config_mgr.enable_syslog()
167 elif module.params['syslog'] == 'Disabled':
168 msg = idrac.config_mgr.disable_syslog()
169 return msg
170
171
172 def main():
173 specs = {
174 "share_name": {"required": True, "type": 'str'},
175 "share_user": {"required": False, "type": 'str'},
176 "share_password": {"required": False, "type": 'str', "aliases": ['share_pwd'], "no_log": True},
177 "share_mnt": {"required": False, "type": 'str'},
178 "syslog": {"required": False, "choices": ['Enabled', 'Disabled'], "default": 'Enabled'}
179 }
180 specs.update(idrac_auth_params)
181 module = AnsibleModule(
182 argument_spec=specs,
183 supports_check_mode=True)
184
185 try:
186 with iDRACConnection(module.params) as idrac:
187 msg = run_setup_idrac_syslog(idrac, module)
188 changed = False
189 if msg.get('Status') == "Success":
190 changed = True
191 if msg.get('Message') == "No changes found to commit!":
192 changed = False
193 except HTTPError as err:
194 module.fail_json(msg=str(err), error_info=json.load(err))
195 except URLError as err:
196 module.exit_json(msg=str(err), unreachable=True)
197 except AttributeError as err:
198 if "NoneType" in str(err):
199 module.fail_json(msg="Unable to access the share. Ensure that the share name, "
200 "share mount, and share credentials provided are correct.")
201 except (RuntimeError, SSLValidationError, ConnectionError, KeyError,
202 ImportError, ValueError, TypeError) as e:
203 module.fail_json(msg=str(e))
204 module.exit_json(msg="Successfully fetch the syslogs.",
205 syslog_status=msg, changed=changed)
206
207
208 if __name__ == '__main__':
209 main()