| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from __future__ import (absolute_import, division, print_function) |
| 14 |
|
| 15 |
__metaclass__ = type |
| 16 |
|
| 17 |
DOCUMENTATION = """ |
| 18 |
--- |
| 19 |
module: dellemc_configure_idrac_eventing |
| 20 |
short_description: Configures the iDRAC eventing related attributes |
| 21 |
version_added: "1.0.0" |
| 22 |
deprecated: |
| 23 |
removed_at_date: "2024-12-31" |
| 24 |
why: Replaced with M(dellemc.openmanage.idrac_attributes). |
| 25 |
alternative: Use M(dellemc.openmanage.idrac_attributes) instead. |
| 26 |
removed_from_collection: dellemc.openmanage |
| 27 |
description: |
| 28 |
- This module allows to configure the iDRAC eventing related attributes. |
| 29 |
extends_documentation_fragment: |
| 30 |
- dellemc.openmanage.idrac_auth_options |
| 31 |
options: |
| 32 |
share_name: |
| 33 |
type: str |
| 34 |
description: |
| 35 |
- (deprecated)Network share or a local path. |
| 36 |
- This option is deprecated and will be removed in the later version. |
| 37 |
share_user: |
| 38 |
type: str |
| 39 |
description: |
| 40 |
- (deprecated)Network share user in the format 'user@domain' or 'domain\\user' if user is |
| 41 |
part of a domain else 'user'. This option is mandatory for CIFS Network Share. |
| 42 |
- This option is deprecated and will be removed in the later version. |
| 43 |
share_password: |
| 44 |
type: str |
| 45 |
description: |
| 46 |
- (deprecated)Network share user password. This option is mandatory for CIFS Network Share. |
| 47 |
- This option is deprecated and will be removed in the later version. |
| 48 |
aliases: ['share_pwd'] |
| 49 |
share_mnt: |
| 50 |
type: str |
| 51 |
description: |
| 52 |
- (deprecated)Local mount path of the network share with read-write permission for ansible user. |
| 53 |
This option is mandatory for Network Share. |
| 54 |
- This option is deprecated and will be removed in the later version. |
| 55 |
destination_number: |
| 56 |
type: int |
| 57 |
description: Destination number for SNMP Trap. |
| 58 |
destination: |
| 59 |
type: str |
| 60 |
description: Destination for SNMP Trap. |
| 61 |
snmp_v3_username: |
| 62 |
type: str |
| 63 |
description: SNMP v3 username for SNMP Trap. |
| 64 |
snmp_trap_state: |
| 65 |
type: str |
| 66 |
description: Whether to Enable or Disable SNMP alert. |
| 67 |
choices: [Enabled, Disabled] |
| 68 |
email_alert_state: |
| 69 |
type: str |
| 70 |
description: Whether to Enable or Disable Email alert. |
| 71 |
choices: [Enabled, Disabled] |
| 72 |
alert_number: |
| 73 |
type: int |
| 74 |
description: Alert number for Email configuration. |
| 75 |
address: |
| 76 |
type: str |
| 77 |
description: Email address for SNMP Trap. |
| 78 |
custom_message: |
| 79 |
type: str |
| 80 |
description: Custom message for SNMP Trap reference. |
| 81 |
enable_alerts: |
| 82 |
type: str |
| 83 |
description: Whether to Enable or Disable iDRAC alerts. |
| 84 |
choices: [Enabled, Disabled] |
| 85 |
authentication: |
| 86 |
type: str |
| 87 |
description: Simple Mail Transfer Protocol Authentication. |
| 88 |
choices: [Enabled, Disabled] |
| 89 |
smtp_ip_address: |
| 90 |
type: str |
| 91 |
description: Enter the IPv4 or IPv6 address of the SMTP server or the FQDN or DNS name. |
| 92 |
smtp_port: |
| 93 |
type: str |
| 94 |
description: SMTP Port number for access. |
| 95 |
username: |
| 96 |
type: str |
| 97 |
description: Username for SMTP authentication. |
| 98 |
password: |
| 99 |
type: str |
| 100 |
description: Password for SMTP authentication. |
| 101 |
requirements: |
| 102 |
- "omsdk >= 1.2.503" |
| 103 |
- "python >= 3.9.6" |
| 104 |
author: "Felix Stephen (@felixs88)" |
| 105 |
notes: |
| 106 |
- This module requires 'Administrator' privilege for I(idrac_user). |
| 107 |
- Run this module from a system that has direct access to Dell iDRAC. |
| 108 |
- This module supports both IPv4 and IPv6 address for I(idrac_ip). |
| 109 |
- This module supports C(check_mode). |
| 110 |
""" |
| 111 |
|
| 112 |
EXAMPLES = """ |
| 113 |
--- |
| 114 |
- name: Configure the iDRAC eventing attributes |
| 115 |
dellemc.openmanage.dellemc_configure_idrac_eventing: |
| 116 |
idrac_ip: "192.168.0.1" |
| 117 |
idrac_user: "user_name" |
| 118 |
idrac_password: "user_password" |
| 119 |
ca_path: "/path/to/ca_cert.pem" |
| 120 |
destination_number: "2" |
| 121 |
destination: "1.1.1.1" |
| 122 |
snmp_v3_username: "None" |
| 123 |
snmp_trap_state: "Enabled" |
| 124 |
email_alert_state: "Disabled" |
| 125 |
alert_number: "1" |
| 126 |
address: "[email protected]" |
| 127 |
custom_message: "Custom Message" |
| 128 |
enable_alerts: "Disabled" |
| 129 |
authentication: "Enabled" |
| 130 |
smtp_ip_address: "192.168.0.1" |
| 131 |
smtp_port: "25" |
| 132 |
username: "username" |
| 133 |
password: "password" |
| 134 |
""" |
| 135 |
|
| 136 |
RETURN = r''' |
| 137 |
--- |
| 138 |
msg: |
| 139 |
description: Successfully configured the iDRAC eventing settings. |
| 140 |
returned: always |
| 141 |
type: str |
| 142 |
sample: Successfully configured the iDRAC eventing settings. |
| 143 |
eventing_status: |
| 144 |
description: Configures the iDRAC eventing attributes. |
| 145 |
returned: success |
| 146 |
type: dict |
| 147 |
sample: { |
| 148 |
"CompletionTime": "2020-04-02T02:43:28", |
| 149 |
"Description": "Job Instance", |
| 150 |
"EndTime": null, |
| 151 |
"Id": "JID_12345123456", |
| 152 |
"JobState": "Completed", |
| 153 |
"JobType": "ImportConfiguration", |
| 154 |
"Message": "Successfully imported and applied Server Configuration Profile.", |
| 155 |
"MessageArgs": [], |
| 156 |
"MessageId": "SYS053", |
| 157 |
"Name": "Import Configuration", |
| 158 |
"PercentComplete": 100, |
| 159 |
"StartTime": "TIME_NOW", |
| 160 |
"Status": "Success", |
| 161 |
"TargetSettingsURI": null, |
| 162 |
"retval": true |
| 163 |
} |
| 164 |
error_info: |
| 165 |
description: Details of the HTTP Error. |
| 166 |
returned: on HTTP error |
| 167 |
type: dict |
| 168 |
sample: { |
| 169 |
"error": { |
| 170 |
"code": "Base.1.0.GeneralError", |
| 171 |
"message": "A general error has occurred. See ExtendedInfo for more information.", |
| 172 |
"@Message.ExtendedInfo": [ |
| 173 |
{ |
| 174 |
"MessageId": "GEN1234", |
| 175 |
"RelatedProperties": [], |
| 176 |
"Message": "Unable to process the request because an error occurred.", |
| 177 |
"MessageArgs": [], |
| 178 |
"Severity": "Critical", |
| 179 |
"Resolution": "Retry the operation. If the issue persists, contact your system administrator." |
| 180 |
} |
| 181 |
] |
| 182 |
} |
| 183 |
} |
| 184 |
''' |
| 185 |
|
| 186 |
import os |
| 187 |
import tempfile |
| 188 |
import json |
| 189 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idrac import iDRACConnection, idrac_auth_params |
| 190 |
from ansible.module_utils.basic import AnsibleModule |
| 191 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 192 |
from ansible.module_utils.urls import ConnectionError, SSLValidationError |
| 193 |
try: |
| 194 |
from omdrivers.enums.iDRAC.iDRAC import (State_SNMPAlertTypes, Enable_EmailAlertTypes, |
| 195 |
AlertEnable_IPMILanTypes, |
| 196 |
SMTPAuthentication_RemoteHostsTypes) |
| 197 |
from omsdk.sdkfile import file_share_manager |
| 198 |
except ImportError: |
| 199 |
pass |
| 200 |
|
| 201 |
|
| 202 |
def run_idrac_eventing_config(idrac, module): |
| 203 |
""" |
| 204 |
Get Lifecycle Controller status |
| 205 |
|
| 206 |
Keyword arguments: |
| 207 |
idrac -- iDRAC handle |
| 208 |
module -- Ansible module |
| 209 |
""" |
| 210 |
idrac.use_redfish = True |
| 211 |
share_path = tempfile.gettempdir() + os.sep |
| 212 |
upd_share = file_share_manager.create_share_obj(share_path=share_path, isFolder=True) |
| 213 |
if not upd_share.IsValid: |
| 214 |
module.fail_json(msg="Unable to access the share. Ensure that the share name, " |
| 215 |
"share mount, and share credentials provided are correct.") |
| 216 |
set_liason = idrac.config_mgr.set_liason_share(upd_share) |
| 217 |
if set_liason['Status'] == "Failed": |
| 218 |
try: |
| 219 |
message = set_liason['Data']['Message'] |
| 220 |
except (IndexError, KeyError): |
| 221 |
message = set_liason['Message'] |
| 222 |
module.fail_json(msg=message) |
| 223 |
|
| 224 |
if module.params["destination_number"] is not None: |
| 225 |
if module.params["destination"] is not None: |
| 226 |
idrac.config_mgr.configure_snmp_trap_destination( |
| 227 |
destination=module.params["destination"], |
| 228 |
destination_number=module.params["destination_number"] |
| 229 |
) |
| 230 |
if module.params["snmp_v3_username"] is not None: |
| 231 |
idrac.config_mgr.configure_snmp_trap_destination( |
| 232 |
snmp_v3_username=module.params["snmp_v3_username"], |
| 233 |
destination_number=module.params["destination_number"] |
| 234 |
) |
| 235 |
if module.params["snmp_trap_state"] is not None: |
| 236 |
idrac.config_mgr.configure_snmp_trap_destination( |
| 237 |
state=State_SNMPAlertTypes[module.params["snmp_trap_state"]], |
| 238 |
destination_number=module.params["destination_number"] |
| 239 |
) |
| 240 |
|
| 241 |
if module.params["alert_number"] is not None: |
| 242 |
if module.params["email_alert_state"] is not None: |
| 243 |
idrac.config_mgr.configure_email_alerts( |
| 244 |
state=Enable_EmailAlertTypes[module.params["email_alert_state"]], |
| 245 |
alert_number=module.params["alert_number"] |
| 246 |
) |
| 247 |
if module.params["address"] is not None: |
| 248 |
idrac.config_mgr.configure_email_alerts( |
| 249 |
address=module.params["address"], |
| 250 |
alert_number=module.params["alert_number"] |
| 251 |
) |
| 252 |
if module.params["custom_message"] is not None: |
| 253 |
idrac.config_mgr.configure_email_alerts( |
| 254 |
custom_message=module.params["custom_message"], |
| 255 |
alert_number=module.params["alert_number"] |
| 256 |
) |
| 257 |
|
| 258 |
if module.params["enable_alerts"] is not None: |
| 259 |
idrac.config_mgr.configure_idrac_alerts( |
| 260 |
enable_alerts=AlertEnable_IPMILanTypes[module.params["enable_alerts"]], |
| 261 |
) |
| 262 |
|
| 263 |
if module.params['authentication'] is not None: |
| 264 |
idrac.config_mgr.configure_smtp_server_settings( |
| 265 |
authentication=SMTPAuthentication_RemoteHostsTypes[module.params['authentication']]) |
| 266 |
if module.params['smtp_ip_address'] is not None: |
| 267 |
idrac.config_mgr.configure_smtp_server_settings( |
| 268 |
smtp_ip_address=module.params['smtp_ip_address']) |
| 269 |
if module.params['smtp_port'] is not None: |
| 270 |
idrac.config_mgr.configure_smtp_server_settings( |
| 271 |
smtp_port=module.params['smtp_port']) |
| 272 |
if module.params['username'] is not None: |
| 273 |
idrac.config_mgr.configure_smtp_server_settings( |
| 274 |
username=module.params['username']) |
| 275 |
if module.params['password'] is not None: |
| 276 |
idrac.config_mgr.configure_smtp_server_settings( |
| 277 |
password=module.params['password']) |
| 278 |
|
| 279 |
if module.check_mode: |
| 280 |
status = idrac.config_mgr.is_change_applicable() |
| 281 |
if status.get("changes_applicable"): |
| 282 |
module.exit_json(msg="Changes found to commit!", changed=True) |
| 283 |
else: |
| 284 |
module.exit_json(msg="No changes found to commit!") |
| 285 |
else: |
| 286 |
status = idrac.config_mgr.apply_changes(reboot=False) |
| 287 |
|
| 288 |
return status |
| 289 |
|
| 290 |
|
| 291 |
def main(): |
| 292 |
specs = dict( |
| 293 |
share_name=dict(required=False, type='str'), |
| 294 |
share_password=dict(required=False, type='str', aliases=['share_pwd'], no_log=True), |
| 295 |
share_user=dict(required=False, type='str'), |
| 296 |
share_mnt=dict(required=False, type='str'), |
| 297 |
|
| 298 |
destination_number=dict(required=False, type="int"), |
| 299 |
destination=dict(required=False, type="str"), |
| 300 |
snmp_v3_username=dict(required=False, type="str"), |
| 301 |
snmp_trap_state=dict(required=False, choices=["Enabled", "Disabled"], default=None), |
| 302 |
|
| 303 |
alert_number=dict(required=False, type="int"), |
| 304 |
address=dict(required=False, default=None, type="str"), |
| 305 |
custom_message=dict(required=False, default=None, type="str"), |
| 306 |
email_alert_state=dict(required=False, choices=["Enabled", "Disabled"], default=None), |
| 307 |
|
| 308 |
enable_alerts=dict(required=False, choices=["Enabled", "Disabled"], default=None), |
| 309 |
|
| 310 |
authentication=dict(required=False, choices=['Enabled', 'Disabled'], default=None), |
| 311 |
smtp_ip_address=dict(required=False, default=None, type='str'), |
| 312 |
smtp_port=dict(required=False, type='str'), |
| 313 |
username=dict(required=False, type="str"), |
| 314 |
password=dict(required=False, type="str", no_log=True), |
| 315 |
) |
| 316 |
specs.update(idrac_auth_params) |
| 317 |
module = AnsibleModule( |
| 318 |
argument_spec=specs, |
| 319 |
supports_check_mode=True) |
| 320 |
|
| 321 |
try: |
| 322 |
with iDRACConnection(module.params) as idrac: |
| 323 |
status = run_idrac_eventing_config(idrac, module) |
| 324 |
msg, changed = "Successfully configured the iDRAC eventing settings.", True |
| 325 |
if status.get('Status') == "Success": |
| 326 |
if (status.get('Message') == "No changes found to commit!") or \ |
| 327 |
("No changes were applied" in status.get('Message')): |
| 328 |
msg = status.get('Message') |
| 329 |
changed = False |
| 330 |
elif status.get('Status') == "Failed": |
| 331 |
module.fail_json(msg="Failed to configure the iDRAC eventing settings") |
| 332 |
module.exit_json(msg=msg, eventing_status=status, changed=changed) |
| 333 |
except HTTPError as err: |
| 334 |
module.fail_json(msg=str(err), error_info=json.load(err)) |
| 335 |
except URLError as err: |
| 336 |
module.exit_json(msg=str(err), unreachable=True) |
| 337 |
except (RuntimeError, ImportError, SSLValidationError, IOError, ValueError, TypeError, ConnectionError) as e: |
| 338 |
module.fail_json(msg=str(e)) |
| 339 |
|
| 340 |
|
| 341 |
if __name__ == '__main__': |
| 342 |
main() |