| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
from __future__ import (absolute_import, division, print_function) |
| 12 |
|
| 13 |
__metaclass__ = type |
| 14 |
|
| 15 |
import json |
| 16 |
import os |
| 17 |
import tempfile |
| 18 |
from datetime import datetime, timedelta |
| 19 |
from io import StringIO |
| 20 |
|
| 21 |
import pytest |
| 22 |
from ansible.module_utils._text import to_text |
| 23 |
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError |
| 24 |
from ansible.module_utils.urls import SSLValidationError |
| 25 |
from ansible_collections.dellemc.openmanage.plugins.modules import ome_alert_policies |
| 26 |
from ansible_collections.dellemc.openmanage.tests.unit.plugins.modules.common import FakeAnsibleModule |
| 27 |
|
| 28 |
MODULE_PATH = 'ansible_collections.dellemc.openmanage.plugins.modules.ome_alert_policies.' |
| 29 |
|
| 30 |
SUCCESS_MSG = "Successfully {0}d the alert policy." |
| 31 |
NO_CHANGES_MSG = "No changes found to be applied." |
| 32 |
CHANGES_MSG = "Changes found to be applied." |
| 33 |
INVALID_TIME = "The specified {0} date or {0} time `{1}` to schedule the policy is not valid. Enter a valid date and time." |
| 34 |
END_START_TIME = "The end time `{0}` to schedule the policy must be greater than the start time `{1}`." |
| 35 |
CATEGORY_FETCH_FAILED = "Unable to retrieve the category details from OpenManage Enterprise." |
| 36 |
INVALID_TARGETS = "Specify target devices to apply the alert policy." |
| 37 |
INVALID_CATEGORY_MESSAGE = "Specify categories or message to create the alert policy." |
| 38 |
INVALID_SCHEDULE = "Specify a date and time to schedule the alert policy." |
| 39 |
INVALID_ACTIONS = "Specify alert actions for the alert policy." |
| 40 |
INVALID_SEVERITY = "Specify the severity to create the alert policy." |
| 41 |
MULTIPLE_POLICIES = "Unable to update the alert policies because the number of alert policies entered are more than " \ |
| 42 |
"one. The update policy operation supports only one alert policy at a time." |
| 43 |
DISABLED_ACTION = "Action {0} is disabled. Enable it before applying to the alert policy." |
| 44 |
ACTION_INVALID_PARAM = "The Action {0} attribute contains invalid parameter name {1}. The valid values are {2}." |
| 45 |
ACTION_INVALID_VALUE = "The Action {0} attribute contains invalid value for {1} for parameter name {2}. The valid " \ |
| 46 |
"values are {3}." |
| 47 |
ACTION_DIS_EXIST = "Action {0} does not exist." |
| 48 |
SUBCAT_IN_CATEGORY = "The subcategory {0} does not exist in the category {1}." |
| 49 |
CATEGORY_IN_CATALOG = "The category {0} does not exist in the catalog {1}." |
| 50 |
OME_DATA_MSG = "The {0} with the following {1} do not exist: {2}." |
| 51 |
CATALOG_DIS_EXIST = "The catalog {0} does not exist." |
| 52 |
CSV_PATH = "The message file {0} does not exist." |
| 53 |
DEFAULT_POLICY_DELETE = "The following default policies cannot be deleted: {0}." |
| 54 |
POLICY_ENABLE_MISSING = "Unable to {0} the alert policies {1} because the policy names are invalid. Enter the valid " \ |
| 55 |
"alert policy names and retry the operation." |
| 56 |
NO_POLICY_EXIST = "The alert policy does not exist." |
| 57 |
SEPARATOR = ", " |
| 58 |
|
| 59 |
|
| 60 |
@pytest.fixture |
| 61 |
def ome_connection_mock_for_alert_policies(mocker, ome_response_mock): |
| 62 |
connection_class_mock = mocker.patch(MODULE_PATH + 'RestOME') |
| 63 |
ome_connection_mock_obj = connection_class_mock.return_value.__enter__.return_value |
| 64 |
ome_connection_mock_obj.invoke_request.return_value = ome_response_mock |
| 65 |
return ome_connection_mock_obj |
| 66 |
|
| 67 |
|
| 68 |
class TestOmeAlertPolicies(FakeAnsibleModule): |
| 69 |
module = ome_alert_policies |
| 70 |
|
| 71 |
@pytest.mark.parametrize("params", [ |
| 72 |
{"message": SUCCESS_MSG.format("enable"), "success": True, |
| 73 |
"json_data": {"value": [{'Name': "new alert policy", "Id": 12, "Enabled": False}]}, |
| 74 |
"mparams": {"name": "new alert policy", "enable": True}}, |
| 75 |
{"message": CHANGES_MSG, "success": True, "check_mode": True, |
| 76 |
"json_data": {"value": [{'Name': "new alert policy", "Id": 12, "Enabled": False}]}, |
| 77 |
"mparams": {"name": "new alert policy", "enable": True}}, |
| 78 |
{"message": MULTIPLE_POLICIES, "success": True, |
| 79 |
"json_data": {"value": [{'Name': "alert policy1", "Id": 12, "Enabled": True}, |
| 80 |
{'Name': "alert policy2", "Id": 13, "Enabled": True}]}, |
| 81 |
"mparams": {"name": ["alert policy1", "alert policy2"], "enable": False, "description": 'Update case failed'}}, |
| 82 |
{"message": POLICY_ENABLE_MISSING.format("disable", "alert policy3"), "success": True, |
| 83 |
"json_data": {"value": [{'Name': "alert policy1", "Id": 12, "Enabled": True}, |
| 84 |
{'Name': "alert policy2", "Id": 13, "Enabled": True}]}, |
| 85 |
"mparams": {"name": ["alert policy3", "alert policy2"], "enable": False}}, |
| 86 |
{"message": NO_CHANGES_MSG, "success": True, "check_mode": True, |
| 87 |
"json_data": {"value": [{'Name': "new alert policy", "Id": 12, "Enabled": False}]}, |
| 88 |
"mparams": {"name": "new alert policy", "enable": False}}, |
| 89 |
{"message": SUCCESS_MSG.format("delete"), "success": True, |
| 90 |
"json_data": {"report_list": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}], |
| 91 |
"value": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}]}, |
| 92 |
"mparams": {"name": "new alert policy", "state": "absent"}}, |
| 93 |
{"message": CHANGES_MSG, "success": True, "check_mode": True, |
| 94 |
"json_data": {"report_list": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}], |
| 95 |
"value": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}]}, |
| 96 |
"mparams": {"name": "new alert policy", "state": "absent"}}, |
| 97 |
{"message": DEFAULT_POLICY_DELETE.format("new alert policy"), "success": True, |
| 98 |
"json_data": {"report_list": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}], |
| 99 |
"value": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": True}]}, |
| 100 |
"mparams": {"name": "new alert policy", "state": "absent"}}, |
| 101 |
{"message": NO_POLICY_EXIST, "success": True, "check_mode": True, |
| 102 |
"json_data": {"report_list": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}], |
| 103 |
"value": [{'Name': "new alert policy 1", "Id": 12, "DefaultPolicy": False}]}, |
| 104 |
"mparams": {"name": "new alert policy", "state": "absent"}}, |
| 105 |
{"message": NO_POLICY_EXIST, "success": True, |
| 106 |
"json_data": {"report_list": [{'Name': "new alert policy", "Id": 12, "DefaultPolicy": False}], |
| 107 |
"value": [{'Name': "new alert policy 1", "Id": 12, "DefaultPolicy": False}]}, |
| 108 |
"mparams": {"name": "new alert policy", "state": "absent"}}, |
| 109 |
]) |
| 110 |
def test_ome_alert_policies_enable_delete(self, params, ome_connection_mock_for_alert_policies, |
| 111 |
ome_response_mock, ome_default_args, module_mock, mocker): |
| 112 |
ome_response_mock.success = params.get("success", True) |
| 113 |
ome_response_mock.json_data = params['json_data'] |
| 114 |
ome_connection_mock_for_alert_policies.get_all_items_with_pagination.return_value = params[ |
| 115 |
'json_data'] |
| 116 |
ome_default_args.update(params['mparams']) |
| 117 |
result = self._run_module( |
| 118 |
ome_default_args, check_mode=params.get('check_mode', False)) |
| 119 |
assert result['msg'] == params['message'] |
| 120 |
|
| 121 |
trap_ip1 = "traphost1:162" |
| 122 |
trap_ip2 = "traphost2:162" |
| 123 |
trap_ip3 = "traphost3:514" |
| 124 |
actions = [ |
| 125 |
{ |
| 126 |
"action_name": "Trap", |
| 127 |
"parameters": [ |
| 128 |
{ |
| 129 |
"name": trap_ip2, |
| 130 |
"value": "True" |
| 131 |
} |
| 132 |
] |
| 133 |
}, |
| 134 |
{ |
| 135 |
"action_name": "Mobile", |
| 136 |
"parameters": [] |
| 137 |
}, |
| 138 |
{ |
| 139 |
"action_name": "Email", |
| 140 |
"parameters": [ |
| 141 |
{ |
| 142 |
"name": "to", |
| 143 |
"value": "[email protected]" |
| 144 |
}, |
| 145 |
{ |
| 146 |
"name": "from", |
| 147 |
"value": "[email protected]" |
| 148 |
}, |
| 149 |
{ |
| 150 |
"name": "subject", |
| 151 |
"value": "test subject" |
| 152 |
}, |
| 153 |
{ |
| 154 |
"name": "message", |
| 155 |
"value": "test message" |
| 156 |
} |
| 157 |
] |
| 158 |
}, |
| 159 |
{ |
| 160 |
"action_name": "SMS", |
| 161 |
"parameters": [ |
| 162 |
{ |
| 163 |
"name": "to", |
| 164 |
"value": "1234567890" |
| 165 |
} |
| 166 |
] |
| 167 |
} |
| 168 |
] |
| 169 |
create_input = { |
| 170 |
"actions": actions, |
| 171 |
"date_and_time": { |
| 172 |
"date_from": (datetime.now() + timedelta(days=2)).strftime("%Y-%m-%d"), |
| 173 |
"date_to": (datetime.now() + timedelta(days=3)).strftime("%Y-%m-%d"), |
| 174 |
"days": [ |
| 175 |
"sunday", |
| 176 |
"monday" |
| 177 |
], |
| 178 |
"time_from": "11:00", |
| 179 |
"time_to": "12:00", |
| 180 |
"time_interval": True |
| 181 |
}, |
| 182 |
"description": "Description of Alert Policy One", |
| 183 |
"device_group": [ |
| 184 |
"AX", |
| 185 |
"Linux Servers" |
| 186 |
], |
| 187 |
"enable": True, |
| 188 |
"message_ids": [ |
| 189 |
"AMP400", |
| 190 |
"CTL201", |
| 191 |
"AMP401" |
| 192 |
], |
| 193 |
"name": [ |
| 194 |
"Alert Policy One" |
| 195 |
], |
| 196 |
"severity": [ |
| 197 |
"unknown" |
| 198 |
], |
| 199 |
"state": "present" |
| 200 |
} |
| 201 |
get_alert_policy = [{ |
| 202 |
"Id": 24792, |
| 203 |
"Name": "Alert Policy One", |
| 204 |
"Description": "CREATIOn of Alert Policy One", |
| 205 |
"Enabled": True, |
| 206 |
"DefaultPolicy": False, |
| 207 |
"Editable": True, |
| 208 |
"Visible": True, |
| 209 |
"PolicyData": { |
| 210 |
"Catalogs": [], |
| 211 |
"Severities": [ |
| 212 |
1 |
| 213 |
], |
| 214 |
"MessageIds": [ |
| 215 |
"'AMP401'", |
| 216 |
"'AMP400'", |
| 217 |
"'CTL201'" |
| 218 |
], |
| 219 |
"Devices": [], |
| 220 |
"DeviceTypes": [], |
| 221 |
"Groups": [ |
| 222 |
1011, |
| 223 |
1033 |
| 224 |
], |
| 225 |
"Schedule": { |
| 226 |
"StartTime": "2023-10-09 00:00:00.000", |
| 227 |
"EndTime": "2023-10-11 00:00:00.000", |
| 228 |
"CronString": "* * * ? * mon,sun *", |
| 229 |
"Interval": False |
| 230 |
}, |
| 231 |
"Actions": [ |
| 232 |
{ |
| 233 |
"Id": 499, |
| 234 |
"Name": "RemoteCommand", |
| 235 |
"ParameterDetails": [ |
| 236 |
{ |
| 237 |
"Id": 0, |
| 238 |
"Name": "remotecommandaction1", |
| 239 |
"Value": "test", |
| 240 |
"Type": "singleSelect", |
| 241 |
"TypeParams": [ |
| 242 |
{ |
| 243 |
"Name": "option", |
| 244 |
"Value": "test" |
| 245 |
} |
| 246 |
] |
| 247 |
} |
| 248 |
], |
| 249 |
"TemplateId": 111 |
| 250 |
} |
| 251 |
], |
| 252 |
"AllTargets": False, |
| 253 |
"UndiscoveredTargets": [] |
| 254 |
}, |
| 255 |
"State": True, |
| 256 |
"Owner": 10078 |
| 257 |
}] |
| 258 |
get_all_actions = { |
| 259 |
"Email": { |
| 260 |
"Disabled": False, |
| 261 |
"Id": 50, |
| 262 |
"Parameters": { |
| 263 |
"from": "[email protected]", |
| 264 |
"message": "Event occurred for Device Name", |
| 265 |
"subject": "Device Name: $name, Device IP Address: $ip, Severity: $severity", |
| 266 |
"to": "" |
| 267 |
}, |
| 268 |
"Type": { |
| 269 |
"from": [], |
| 270 |
"message": [], |
| 271 |
"subject": [], |
| 272 |
"to": [] |
| 273 |
} |
| 274 |
}, |
| 275 |
"Ignore": { |
| 276 |
"Disabled": False, |
| 277 |
"Id": 100, |
| 278 |
"Parameters": {}, |
| 279 |
"Type": {} |
| 280 |
}, |
| 281 |
"Mobile": { |
| 282 |
"Disabled": False, |
| 283 |
"Id": 112, |
| 284 |
"Parameters": {}, |
| 285 |
"Type": {} |
| 286 |
}, |
| 287 |
"PowerControl": { |
| 288 |
"Disabled": False, |
| 289 |
"Id": 110, |
| 290 |
"Parameters": { |
| 291 |
"powercontrolaction": "poweroff" |
| 292 |
}, |
| 293 |
"Type": { |
| 294 |
"powercontrolaction": [ |
| 295 |
"powercycle", |
| 296 |
"poweroff", |
| 297 |
"poweron", |
| 298 |
"gracefulshutdown" |
| 299 |
] |
| 300 |
} |
| 301 |
}, |
| 302 |
"RemoteCommand": { |
| 303 |
"Disabled": False, |
| 304 |
"Id": 111, |
| 305 |
"Parameters": { |
| 306 |
"remotecommandaction": "test" |
| 307 |
}, |
| 308 |
"Type": { |
| 309 |
"remotecommandaction": [ |
| 310 |
"test", |
| 311 |
"cmd2 : XX.XX.XX.XX" |
| 312 |
] |
| 313 |
} |
| 314 |
}, |
| 315 |
"SMS": { |
| 316 |
"Disabled": False, |
| 317 |
"Id": 70, |
| 318 |
"Parameters": { |
| 319 |
"to": "" |
| 320 |
}, |
| 321 |
"Type": { |
| 322 |
"to": [] |
| 323 |
} |
| 324 |
}, |
| 325 |
"Syslog": { |
| 326 |
"Disabled": False, |
| 327 |
"Id": 90, |
| 328 |
"Parameters": { |
| 329 |
trap_ip3: "true" |
| 330 |
}, |
| 331 |
"Type": { |
| 332 |
trap_ip3: [ |
| 333 |
"true", |
| 334 |
"false" |
| 335 |
] |
| 336 |
} |
| 337 |
}, |
| 338 |
"Trap": { |
| 339 |
"Disabled": False, |
| 340 |
"Id": 60, |
| 341 |
"Parameters": { |
| 342 |
trap_ip1: "true", |
| 343 |
trap_ip2: "true" |
| 344 |
}, |
| 345 |
"Type": { |
| 346 |
trap_ip1: [ |
| 347 |
"true", |
| 348 |
"false" |
| 349 |
], |
| 350 |
trap_ip2: [ |
| 351 |
"true", |
| 352 |
"false" |
| 353 |
] |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
get_category_data_tree = { |
| 358 |
'Application': { |
| 359 |
'Audit': { |
| 360 |
4: { |
| 361 |
'Devices': 90, |
| 362 |
'Generic': 10, |
| 363 |
'Power Configuration': 151, |
| 364 |
'Users': 35 |
| 365 |
} |
| 366 |
}, |
| 367 |
'Configuration': { |
| 368 |
5: { |
| 369 |
'Application': 85, |
| 370 |
'Device Warranty': 116, |
| 371 |
'Devices': 90, |
| 372 |
'Discovery': 36, |
| 373 |
'Generic': 10, |
| 374 |
'Users': 35 |
| 375 |
} |
| 376 |
}, |
| 377 |
'Miscellaneous': { |
| 378 |
7: { |
| 379 |
'Miscellaneous': 20 |
| 380 |
} |
| 381 |
}, |
| 382 |
'Storage': { |
| 383 |
2: { |
| 384 |
'Devices': 90 |
| 385 |
} |
| 386 |
}, |
| 387 |
'System Health': { |
| 388 |
1: { |
| 389 |
'Devices': 90, |
| 390 |
'Health Status of Managed device': 7400, |
| 391 |
'Job': 47, |
| 392 |
'Metrics': 118, |
| 393 |
'Power Configuration': 151 |
| 394 |
} |
| 395 |
}, |
| 396 |
'Updates': { |
| 397 |
3: { |
| 398 |
'Application': 85, |
| 399 |
'Firmware': 112 |
| 400 |
} |
| 401 |
} |
| 402 |
}, |
| 403 |
'Dell Storage': { |
| 404 |
'Storage': { |
| 405 |
2: { |
| 406 |
'Other': 7700 |
| 407 |
} |
| 408 |
}, |
| 409 |
'System Health': { |
| 410 |
1: { |
| 411 |
'Other': 7700, |
| 412 |
'Storage': 18 |
| 413 |
} |
| 414 |
} |
| 415 |
}, |
| 416 |
'Storage': {'Audit': { |
| 417 |
4: { |
| 418 |
'Interface': 101 |
| 419 |
} |
| 420 |
}}, |
| 421 |
'iDRAC': { |
| 422 |
'Audit': { |
| 423 |
4: { |
| 424 |
'Interface': 101 |
| 425 |
} |
| 426 |
} |
| 427 |
}, |
| 428 |
} |
| 429 |
|
| 430 |
@pytest.mark.parametrize("params", [ |
| 431 |
{"message": SUCCESS_MSG.format("create"), "success": True, |
| 432 |
"mparams": create_input, |
| 433 |
"get_alert_policies": [], |
| 434 |
"validate_ome_data": (["AMP400", "AMP401", "CTL201"],), |
| 435 |
"get_severity_payload": {"Severities": ["unknown"]}, |
| 436 |
"get_all_actions": get_all_actions, |
| 437 |
"json_data": {"value": [{'Name': "new alert policy 1", "Id": 12, "DefaultPolicy": False}]}}, |
| 438 |
{"message": CHANGES_MSG, "success": True, |
| 439 |
"check_mode": True, |
| 440 |
"mparams": create_input, |
| 441 |
"get_alert_policies": [], |
| 442 |
"validate_ome_data": (["AMP400", "AMP401", "CTL201"],), |
| 443 |
"get_severity_payload": {"Severities": ["unknown"]}, |
| 444 |
"get_all_actions": get_all_actions, |
| 445 |
"json_data": {"value": [{'Name': "new alert policy 1", "Id": 12, "DefaultPolicy": False}]}}, |
| 446 |
{"message": SUCCESS_MSG.format("update"), "success": True, |
| 447 |
"mparams": create_input, |
| 448 |
"get_alert_policies": get_alert_policy, |
| 449 |
"validate_ome_data": (["AMP400", "AMP401", "CTL201"],), |
| 450 |
"get_category_data_tree": get_category_data_tree, |
| 451 |
"get_all_actions": get_all_actions, |
| 452 |
"json_data": { |
| 453 |
"value": [ |
| 454 |
{ |
| 455 |
|
| 456 |
"Id": 1, |
| 457 |
"Name": "Unknown", |
| 458 |
"Description": "Unknown" |
| 459 |
}, |
| 460 |
{ |
| 461 |
"Id": 2, |
| 462 |
"Name": "Info", |
| 463 |
"Description": "Info" |
| 464 |
}, |
| 465 |
{ |
| 466 |
"Id": 4, |
| 467 |
"Name": "Normal", |
| 468 |
"Description": "Normal" |
| 469 |
}, |
| 470 |
{ |
| 471 |
"Id": 8, |
| 472 |
"Name": "Warning", |
| 473 |
"Description": "Warning" |
| 474 |
}, |
| 475 |
{ |
| 476 |
"Id": 16, |
| 477 |
"Name": "Critical", |
| 478 |
"Description": "Critical" |
| 479 |
} |
| 480 |
] |
| 481 |
}}, |
| 482 |
{"message": SUCCESS_MSG.format("update"), "success": True, |
| 483 |
"mparams": { |
| 484 |
"actions": [ |
| 485 |
{ |
| 486 |
"action_name": "Ignore", |
| 487 |
"parameters": [] |
| 488 |
} |
| 489 |
], |
| 490 |
"description": "Description of Alert Policy One", |
| 491 |
"specific_undiscovered_devices": [ |
| 492 |
"host1", |
| 493 |
"192.1.2.3-192.1.2.10" |
| 494 |
], |
| 495 |
"enable": True, |
| 496 |
"category": [ |
| 497 |
{ |
| 498 |
"catalog_category": [ |
| 499 |
{ |
| 500 |
"category_name": "Audit", |
| 501 |
"sub_category_names": [ |
| 502 |
"Users", |
| 503 |
"Generic" |
| 504 |
] |
| 505 |
} |
| 506 |
], |
| 507 |
"catalog_name": "Application" |
| 508 |
}, |
| 509 |
{ |
| 510 |
"catalog_category": [ |
| 511 |
{ |
| 512 |
"category_name": "Storage", |
| 513 |
"sub_category_names": [ |
| 514 |
"Other" |
| 515 |
] |
| 516 |
} |
| 517 |
], |
| 518 |
"catalog_name": "Dell Storage" |
| 519 |
}, |
| 520 |
{"catalog_name": "Storage"}, |
| 521 |
{ |
| 522 |
"catalog_category": [ |
| 523 |
{ |
| 524 |
"category_name": "Audit", |
| 525 |
"sub_category_names": [] |
| 526 |
} |
| 527 |
], |
| 528 |
"catalog_name": "iDRAC" |
| 529 |
} |
| 530 |
], |
| 531 |
"name": [ |
| 532 |
"Alert Policy One" |
| 533 |
], |
| 534 |
"new_name": "Alert Policy Renamed", |
| 535 |
"severity": [ |
| 536 |
"unknown" |
| 537 |
], |
| 538 |
"state": "present" |
| 539 |
}, |
| 540 |
"get_alert_policies": get_alert_policy, |
| 541 |
"validate_ome_data": (["AMP400", "AMP401", "CTL201"],), |
| 542 |
"get_category_data_tree": get_category_data_tree, |
| 543 |
"get_all_actions": get_all_actions, |
| 544 |
"json_data": {"value": []} |
| 545 |
}, |
| 546 |
{"message": OME_DATA_MSG.format("groups", "Name", "Linux Servers"), "success": True, |
| 547 |
"mparams": { |
| 548 |
"device_group": [ |
| 549 |
"AX", |
| 550 |
"Linux Servers" |
| 551 |
], |
| 552 |
"state": "present", |
| 553 |
"name": "Test alert policy" |
| 554 |
}, |
| 555 |
"get_alert_policies": get_alert_policy, |
| 556 |
"json_data": { |
| 557 |
"@odata.count": 102, |
| 558 |
"@odata.nextLink": "/AlertPolicies", |
| 559 |
"value": [{"Name": "AX", "Id": 121}, |
| 560 |
{"Name": "Group2", "Id": 122}]} |
| 561 |
}, |
| 562 |
{"message": OME_DATA_MSG.format("groups", "Name", "Linux Servers"), "success": True, |
| 563 |
"mparams": { |
| 564 |
"device_group": [ |
| 565 |
"AX", |
| 566 |
"Linux Servers" |
| 567 |
], |
| 568 |
"state": "present", |
| 569 |
"name": "Test alert policy", |
| 570 |
"description": "Coverage for filter block in validate_ome_data" |
| 571 |
}, |
| 572 |
"get_alert_policies": [{ |
| 573 |
"Id": 1234, |
| 574 |
"Name": "Alert Policy Two", |
| 575 |
"Description": "Alert Policy Two described", |
| 576 |
"Enabled": True, |
| 577 |
"DefaultPolicy": False, |
| 578 |
"Editable": True, |
| 579 |
"Visible": True, |
| 580 |
"PolicyData": { |
| 581 |
"Catalogs": [], |
| 582 |
"Severities": [ |
| 583 |
16 |
| 584 |
], |
| 585 |
"MessageIds": [ |
| 586 |
"'AMP403'", |
| 587 |
"'AMP400'", |
| 588 |
"'BIOS108'" |
| 589 |
], |
| 590 |
"Devices": [], |
| 591 |
"DeviceTypes": [], |
| 592 |
"Groups": [ |
| 593 |
111, |
| 594 |
133 |
| 595 |
], |
| 596 |
"Schedule": { |
| 597 |
"StartTime": "2023-11-09 00:00:00.000", |
| 598 |
"EndTime": "2023-11-11 00:00:00.000", |
| 599 |
"CronString": "* * * ? * mon,sun *", |
| 600 |
"Interval": False |
| 601 |
}, |
| 602 |
"Actions": [ |
| 603 |
{ |
| 604 |
"Id": 499, |
| 605 |
"Name": "RemoteCommand", |
| 606 |
"ParameterDetails": [ |
| 607 |
{ |
| 608 |
"Id": 0, |
| 609 |
"Name": "remotecommandaction1", |
| 610 |
"Value": "test", |
| 611 |
"Type": "singleSelect", |
| 612 |
"TypeParams": [ |
| 613 |
{ |
| 614 |
"Name": "option", |
| 615 |
"Value": "test" |
| 616 |
} |
| 617 |
] |
| 618 |
} |
| 619 |
], |
| 620 |
"TemplateId": 111 |
| 621 |
} |
| 622 |
], |
| 623 |
"AllTargets": False, |
| 624 |
"UndiscoveredTargets": [] |
| 625 |
}, |
| 626 |
"State": True, |
| 627 |
"Owner": 10078 |
| 628 |
}], |
| 629 |
"json_data": { |
| 630 |
"@odata.count": 300, |
| 631 |
"value": [{"Name": "AX", "Id": 121}, |
| 632 |
{"Name": "Group2", "Id": 122}]} |
| 633 |
}, |
| 634 |
{"message": INVALID_CATEGORY_MESSAGE, "success": True, |
| 635 |
"mparams": { |
| 636 |
"device_service_tag": [ |
| 637 |
"ABC1234", |
| 638 |
"SVCTAG1" |
| 639 |
], |
| 640 |
"state": "present", |
| 641 |
"name": "Test alert policy", |
| 642 |
"description": "Coverage for filter block in validate_ome_data" |
| 643 |
}, |
| 644 |
"get_alert_policies": [], |
| 645 |
"json_data": { |
| 646 |
"@odata.count": 300, |
| 647 |
"value": [{"DeviceServiceTag": "ABC1234", "Id": 121, "Type": 1000}, |
| 648 |
{"DeviceServiceTag": "SVCTAG1", "Id": 122, "Type": 1000}]} |
| 649 |
}, |
| 650 |
{"message": INVALID_CATEGORY_MESSAGE, "success": True, |
| 651 |
"mparams": { |
| 652 |
"all_devices": True, |
| 653 |
"state": "present", |
| 654 |
"name": "Test alert policy", |
| 655 |
"description": "all devices coverage" |
| 656 |
}, |
| 657 |
"get_alert_policies": [], |
| 658 |
"json_data": { |
| 659 |
"@odata.count": 300, |
| 660 |
"value": [{"DeviceServiceTag": "ABC1234", "Id": 121, "Type": 1000}, |
| 661 |
{"DeviceServiceTag": "SVCTAG1", "Id": 122, "Type": 1000}]} |
| 662 |
}, |
| 663 |
{"message": INVALID_CATEGORY_MESSAGE, "success": True, |
| 664 |
"mparams": { |
| 665 |
"any_undiscovered_devices": True, |
| 666 |
"state": "present", |
| 667 |
"name": "Test alert policy", |
| 668 |
"description": "all devices coverage" |
| 669 |
}, |
| 670 |
"get_alert_policies": [], |
| 671 |
"json_data": { |
| 672 |
"@odata.count": 300, |
| 673 |
"value": [{"DeviceServiceTag": "ABC1234", "Id": 121, "Type": 1000}, |
| 674 |
{"DeviceServiceTag": "SVCTAG1", "Id": 122, "Type": 1000}]} |
| 675 |
}, |
| 676 |
{"message": INVALID_CATEGORY_MESSAGE, "success": True, |
| 677 |
"mparams": { |
| 678 |
"specific_undiscovered_devices": [ |
| 679 |
"192.1.2.3-192.1.2.10", |
| 680 |
"hostforpolicy.domain.com" |
| 681 |
], |
| 682 |
"state": "present", |
| 683 |
"name": "Test alert policy", |
| 684 |
"description": "all devices coverage" |
| 685 |
}, |
| 686 |
"get_alert_policies": [], |
| 687 |
"json_data": { |
| 688 |
"@odata.count": 300, |
| 689 |
"value": [{"DeviceServiceTag": "ABC1234", "Id": 121, "Type": 1000}, |
| 690 |
{"DeviceServiceTag": "SVCTAG1", "Id": 122, "Type": 1000}]} |
| 691 |
}, |
| 692 |
{"message": INVALID_SCHEDULE, "success": True, |
| 693 |
"mparams": { |
| 694 |
"all_devices": True, |
| 695 |
"message_file": "{0}/{1}".format(tempfile.gettempdir(), "myfile.csv"), |
| 696 |
"state": "present", |
| 697 |
"name": "Test alert policy", |
| 698 |
"description": "all devices coverage" |
| 699 |
}, |
| 700 |
"get_alert_policies": [], |
| 701 |
"create_temp_file": "MessageIds\nMSGID1", |
| 702 |
"json_data": { |
| 703 |
"@odata.count": 300, |
| 704 |
"value": [{"MessageId": "MSGID1", "Id": 121, "Type": 1000}, |
| 705 |
{"MessageId": "MSGID2", "Id": 122, "Type": 1000}]} |
| 706 |
}, |
| 707 |
{"message": INVALID_SCHEDULE, "success": True, |
| 708 |
"mparams": { |
| 709 |
"all_devices": True, |
| 710 |
"category": [ |
| 711 |
{ |
| 712 |
"catalog_category": [ |
| 713 |
{ |
| 714 |
"category_name": "Audit", |
| 715 |
"sub_category_names": [ |
| 716 |
"Users", |
| 717 |
"Generic" |
| 718 |
] |
| 719 |
} |
| 720 |
], |
| 721 |
"catalog_name": "Application" |
| 722 |
}, |
| 723 |
{ |
| 724 |
"catalog_category": [ |
| 725 |
{ |
| 726 |
"category_name": "Storage", |
| 727 |
"sub_category_names": [ |
| 728 |
"Other" |
| 729 |
] |
| 730 |
} |
| 731 |
], |
| 732 |
"catalog_name": "Dell Storage" |
| 733 |
} |
| 734 |
], |
| 735 |
"state": "present", |
| 736 |
"name": "Test alert policy", |
| 737 |
"description": "get_category_data_tree coverage" |
| 738 |
}, |
| 739 |
"get_alert_policies": [], |
| 740 |
"get_target_payload": {"Groups": [123, 124]}, |
| 741 |
"json_data": { |
| 742 |
"value": [ |
| 743 |
{ |
| 744 |
"Name": "Application", |
| 745 |
"IsBuiltIn": True, |
| 746 |
"CategoriesDetails": [ |
| 747 |
{ |
| 748 |
"Id": 4, |
| 749 |
"Name": "Audit", |
| 750 |
"CatalogName": "Application", |
| 751 |
"SubCategoryDetails": [ |
| 752 |
{ |
| 753 |
"Id": 90, |
| 754 |
"Name": "Devices", |
| 755 |
"Description": "Devices description" |
| 756 |
}, |
| 757 |
{ |
| 758 |
"Id": 10, |
| 759 |
"Name": "Generic", |
| 760 |
"Description": "Generic description" |
| 761 |
}, |
| 762 |
{ |
| 763 |
"Id": 151, |
| 764 |
"Name": "Power Configuration", |
| 765 |
"Description": "Power Configuration description" |
| 766 |
}, |
| 767 |
{ |
| 768 |
"Id": 35, |
| 769 |
"Name": "Users", |
| 770 |
"Description": "Users description" |
| 771 |
} |
| 772 |
] |
| 773 |
}, |
| 774 |
{ |
| 775 |
"Id": 7, |
| 776 |
"Name": "Miscellaneous", |
| 777 |
"CatalogName": "Application", |
| 778 |
"SubCategoryDetails": [ |
| 779 |
{ |
| 780 |
"Id": 20, |
| 781 |
"Name": "Miscellaneous", |
| 782 |
"Description": "Miscellaneous description" |
| 783 |
} |
| 784 |
] |
| 785 |
}, |
| 786 |
{ |
| 787 |
"Id": 2, |
| 788 |
"Name": "Storage", |
| 789 |
"CatalogName": "Application", |
| 790 |
"SubCategoryDetails": [ |
| 791 |
{ |
| 792 |
"Id": 90, |
| 793 |
"Name": "Devices", |
| 794 |
"Description": "Devices description" |
| 795 |
} |
| 796 |
] |
| 797 |
}, |
| 798 |
{ |
| 799 |
"Id": 1, |
| 800 |
"Name": "System Health", |
| 801 |
"CatalogName": "Application", |
| 802 |
"SubCategoryDetails": [ |
| 803 |
{ |
| 804 |
"Id": 90, |
| 805 |
"Name": "Devices", |
| 806 |
"Description": "Devices description" |
| 807 |
}, |
| 808 |
{ |
| 809 |
"Id": 7400, |
| 810 |
"Name": "Health Status of Managed device", |
| 811 |
"Description": "Health Status of Managed device description" |
| 812 |
}, |
| 813 |
{ |
| 814 |
"Id": 47, |
| 815 |
"Name": "Job", |
| 816 |
"Description": "Job description" |
| 817 |
}, |
| 818 |
{ |
| 819 |
"Id": 118, |
| 820 |
"Name": "Metrics", |
| 821 |
"Description": "Metrics description" |
| 822 |
}, |
| 823 |
{ |
| 824 |
"Id": 151, |
| 825 |
"Name": "Power Configuration", |
| 826 |
"Description": "Power Configuration description" |
| 827 |
} |
| 828 |
] |
| 829 |
}, |
| 830 |
{ |
| 831 |
"Id": 3, |
| 832 |
"Name": "Updates", |
| 833 |
"CatalogName": "Application", |
| 834 |
"SubCategoryDetails": [ |
| 835 |
{ |
| 836 |
"Id": 85, |
| 837 |
"Name": "Application", |
| 838 |
"Description": "Application description" |
| 839 |
}, |
| 840 |
{ |
| 841 |
"Id": 112, |
| 842 |
"Name": "Firmware", |
| 843 |
"Description": "Firmware description" |
| 844 |
} |
| 845 |
] |
| 846 |
} |
| 847 |
] |
| 848 |
}, |
| 849 |
{ |
| 850 |
"Name": "Dell Storage", |
| 851 |
"IsBuiltIn": True, |
| 852 |
"CategoriesDetails": [ |
| 853 |
{ |
| 854 |
"Id": 2, |
| 855 |
"Name": "Storage", |
| 856 |
"CatalogName": "Dell Storage", |
| 857 |
"SubCategoryDetails": [ |
| 858 |
{ |
| 859 |
"Id": 7700, |
| 860 |
"Name": "Other", |
| 861 |
"Description": "Other description" |
| 862 |
} |
| 863 |
] |
| 864 |
}, |
| 865 |
{ |
| 866 |
"Id": 1, |
| 867 |
"Name": "System Health", |
| 868 |
"CatalogName": "Dell Storage", |
| 869 |
"SubCategoryDetails": [ |
| 870 |
{ |
| 871 |
"Id": 7700, |
| 872 |
"Name": "Other", |
| 873 |
"Description": "Other description" |
| 874 |
}, |
| 875 |
{ |
| 876 |
"Id": 18, |
| 877 |
"Name": "Storage", |
| 878 |
"Description": "Storage description" |
| 879 |
} |
| 880 |
] |
| 881 |
} |
| 882 |
] |
| 883 |
} |
| 884 |
] |
| 885 |
} |
| 886 |
}, |
| 887 |
{"message": INVALID_SEVERITY, "success": True, |
| 888 |
"mparams": { |
| 889 |
"actions": actions, |
| 890 |
"all_devices": True, |
| 891 |
"message_ids": ["MSG01", "MSG02"], |
| 892 |
"state": "present", |
| 893 |
"name": "Test alert policy", |
| 894 |
"description": "get_all_actions coverage" |
| 895 |
}, |
| 896 |
"get_alert_policies": [], |
| 897 |
"get_target_payload": {"Groups": [123, 124]}, |
| 898 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 899 |
"get_schedule_payload": {"StartTime": "", "EndTime": ""}, |
| 900 |
"get_severity_payload": {}, |
| 901 |
"json_data": { |
| 902 |
"value": [ |
| 903 |
{ |
| 904 |
"Name": "Email", |
| 905 |
"Description": "Email", |
| 906 |
"Disabled": False, |
| 907 |
"ParameterDetails": [ |
| 908 |
{ |
| 909 |
"Id": 1, |
| 910 |
"Name": "subject", |
| 911 |
"Value": "Device Name: $name, Device IP Address: $ip, Severity: $severity", |
| 912 |
"Type": "string", |
| 913 |
"TemplateParameterTypeDetails": [ |
| 914 |
{ |
| 915 |
"Name": "maxLength", |
| 916 |
"Value": "255" |
| 917 |
} |
| 918 |
] |
| 919 |
}, |
| 920 |
{ |
| 921 |
"Id": 2, |
| 922 |
"Name": "to", |
| 923 |
"Value": "", |
| 924 |
"Type": "string", |
| 925 |
"TemplateParameterTypeDetails": [ |
| 926 |
{ |
| 927 |
"Name": "maxLength", |
| 928 |
"Value": "255" |
| 929 |
} |
| 930 |
] |
| 931 |
}, |
| 932 |
{ |
| 933 |
"Id": 3, |
| 934 |
"Name": "from", |
| 935 |
"Value": "[email protected]", |
| 936 |
"Type": "string", |
| 937 |
"TemplateParameterTypeDetails": [ |
| 938 |
{ |
| 939 |
"Name": "maxLength", |
| 940 |
"Value": "255" |
| 941 |
} |
| 942 |
] |
| 943 |
}, |
| 944 |
{ |
| 945 |
"Id": 4, |
| 946 |
"Name": "message", |
| 947 |
"Value": "Event occurred for Device Name", |
| 948 |
"Type": "string", |
| 949 |
"TemplateParameterTypeDetails": [ |
| 950 |
{ |
| 951 |
"Name": "maxLength", |
| 952 |
"Value": "255" |
| 953 |
} |
| 954 |
] |
| 955 |
} |
| 956 |
] |
| 957 |
}, |
| 958 |
{ |
| 959 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 960 |
"@odata.id": "/api/AlertService/AlertActionTemplates(60)", |
| 961 |
"Id": 60, |
| 962 |
"Name": "Trap", |
| 963 |
"Description": "Trap", |
| 964 |
"Disabled": False, |
| 965 |
"ParameterDetails": [ |
| 966 |
{ |
| 967 |
"Id": 1, |
| 968 |
"Name": trap_ip1, |
| 969 |
"Value": "true", |
| 970 |
"Type": "boolean", |
| 971 |
"TemplateParameterTypeDetails": [] |
| 972 |
}, |
| 973 |
{ |
| 974 |
"Id": 2, |
| 975 |
"Name": trap_ip2, |
| 976 |
"Value": "true", |
| 977 |
"Type": "boolean", |
| 978 |
"TemplateParameterTypeDetails": [] |
| 979 |
} |
| 980 |
] |
| 981 |
}, |
| 982 |
{ |
| 983 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 984 |
"@odata.id": "/api/AlertService/AlertActionTemplates(90)", |
| 985 |
"Id": 90, |
| 986 |
"Name": "Syslog", |
| 987 |
"Description": "Syslog", |
| 988 |
"Disabled": False, |
| 989 |
"ParameterDetails": [ |
| 990 |
{ |
| 991 |
"Id": 1, |
| 992 |
"Name": trap_ip3, |
| 993 |
"Value": "true", |
| 994 |
"Type": "boolean", |
| 995 |
"TemplateParameterTypeDetails": [] |
| 996 |
} |
| 997 |
] |
| 998 |
}, |
| 999 |
{ |
| 1000 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 1001 |
"@odata.id": "/api/AlertService/AlertActionTemplates(100)", |
| 1002 |
"Id": 100, |
| 1003 |
"Name": "Ignore", |
| 1004 |
"Description": "Ignore", |
| 1005 |
"Disabled": False, |
| 1006 |
"ParameterDetails": [] |
| 1007 |
}, |
| 1008 |
{ |
| 1009 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 1010 |
"@odata.id": "/api/AlertService/AlertActionTemplates(70)", |
| 1011 |
"Id": 70, |
| 1012 |
"Name": "SMS", |
| 1013 |
"Description": "SMS", |
| 1014 |
"Disabled": False, |
| 1015 |
"ParameterDetails": [ |
| 1016 |
{ |
| 1017 |
"Id": 1, |
| 1018 |
"Name": "to", |
| 1019 |
"Value": "", |
| 1020 |
"Type": "string", |
| 1021 |
"TemplateParameterTypeDetails": [ |
| 1022 |
{ |
| 1023 |
"Name": "maxLength", |
| 1024 |
"Value": "255" |
| 1025 |
} |
| 1026 |
] |
| 1027 |
} |
| 1028 |
] |
| 1029 |
}, |
| 1030 |
{ |
| 1031 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 1032 |
"@odata.id": "/api/AlertService/AlertActionTemplates(110)", |
| 1033 |
"Id": 110, |
| 1034 |
"Name": "PowerControl", |
| 1035 |
"Description": "Power Control Action Template", |
| 1036 |
"Disabled": False, |
| 1037 |
"ParameterDetails": [ |
| 1038 |
{ |
| 1039 |
"Id": 1, |
| 1040 |
"Name": "powercontrolaction", |
| 1041 |
"Value": "poweroff", |
| 1042 |
"Type": "singleSelect", |
| 1043 |
"TemplateParameterTypeDetails": [ |
| 1044 |
{ |
| 1045 |
"Name": "option", |
| 1046 |
"Value": "powercycle" |
| 1047 |
}, |
| 1048 |
{ |
| 1049 |
"Name": "option", |
| 1050 |
"Value": "poweroff" |
| 1051 |
}, |
| 1052 |
{ |
| 1053 |
"Name": "option", |
| 1054 |
"Value": "poweron" |
| 1055 |
}, |
| 1056 |
{ |
| 1057 |
"Name": "option", |
| 1058 |
"Value": "gracefulshutdown" |
| 1059 |
} |
| 1060 |
] |
| 1061 |
} |
| 1062 |
] |
| 1063 |
}, |
| 1064 |
{ |
| 1065 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 1066 |
"@odata.id": "/api/AlertService/AlertActionTemplates(111)", |
| 1067 |
"Id": 111, |
| 1068 |
"Name": "RemoteCommand", |
| 1069 |
"Description": "RemoteCommand", |
| 1070 |
"Disabled": False, |
| 1071 |
"ParameterDetails": [ |
| 1072 |
{ |
| 1073 |
"Id": 1, |
| 1074 |
"Name": "remotecommandaction", |
| 1075 |
"Value": "test", |
| 1076 |
"Type": "singleSelect", |
| 1077 |
"TemplateParameterTypeDetails": [ |
| 1078 |
{ |
| 1079 |
"Name": "option", |
| 1080 |
"Value": "test" |
| 1081 |
} |
| 1082 |
] |
| 1083 |
} |
| 1084 |
] |
| 1085 |
}, |
| 1086 |
{ |
| 1087 |
"@odata.type": "#AlertService.AlertActionTemplate", |
| 1088 |
"@odata.id": "/api/AlertService/AlertActionTemplates(112)", |
| 1089 |
"Id": 112, |
| 1090 |
"Name": "Mobile", |
| 1091 |
"Description": "Mobile", |
| 1092 |
"Disabled": False, |
| 1093 |
"ParameterDetails": [] |
| 1094 |
} |
| 1095 |
] |
| 1096 |
} |
| 1097 |
}, |
| 1098 |
{"message": DISABLED_ACTION.format("SMS"), "success": True, |
| 1099 |
"mparams": { |
| 1100 |
"actions": [{ |
| 1101 |
"action_name": "SMS", |
| 1102 |
"parameters": [ |
| 1103 |
{ |
| 1104 |
"name": "to", |
| 1105 |
"value": "1234567890" |
| 1106 |
} |
| 1107 |
] |
| 1108 |
}], |
| 1109 |
"all_devices": True, |
| 1110 |
"message_ids": ["MSG01", "MSG02"], |
| 1111 |
"state": "present", |
| 1112 |
"name": "Test alert policy", |
| 1113 |
"description": "get_all_actions coverage" |
| 1114 |
}, |
| 1115 |
"get_alert_policies": [], |
| 1116 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1117 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1118 |
"get_schedule_payload": {"StartTime": "", "EndTime": ""}, |
| 1119 |
"get_severity_payload": {}, |
| 1120 |
"json_data": { |
| 1121 |
"value": [ |
| 1122 |
{ |
| 1123 |
"Id": 70, |
| 1124 |
"Name": "SMS", |
| 1125 |
"Description": "SMS", |
| 1126 |
"Disabled": True, |
| 1127 |
"ParameterDetails": [ |
| 1128 |
{ |
| 1129 |
"Id": 1, |
| 1130 |
"Name": "to", |
| 1131 |
"Value": "", |
| 1132 |
"Type": "string", |
| 1133 |
"TemplateParameterTypeDetails": [ |
| 1134 |
{ |
| 1135 |
"Name": "maxLength", |
| 1136 |
"Value": "255" |
| 1137 |
} |
| 1138 |
] |
| 1139 |
} |
| 1140 |
] |
| 1141 |
}, |
| 1142 |
{ |
| 1143 |
"Id": 112, |
| 1144 |
"Name": "Mobile", |
| 1145 |
"Description": "Mobile", |
| 1146 |
"Disabled": False, |
| 1147 |
"ParameterDetails": [] |
| 1148 |
} |
| 1149 |
] |
| 1150 |
} |
| 1151 |
}, |
| 1152 |
{"message": ACTION_INVALID_PARAM.format("Trap", "traphost2:162", "traphost1:162"), "success": True, |
| 1153 |
"mparams": { |
| 1154 |
"actions": [{ |
| 1155 |
"action_name": "Trap", |
| 1156 |
"parameters": [ |
| 1157 |
{ |
| 1158 |
"name": trap_ip2, |
| 1159 |
"value": "True" |
| 1160 |
} |
| 1161 |
] |
| 1162 |
}], |
| 1163 |
"all_devices": True, |
| 1164 |
"message_ids": ["MSG01", "MSG02"], |
| 1165 |
"state": "present", |
| 1166 |
"name": "Test alert policy", |
| 1167 |
"description": "get_all_actions coverage" |
| 1168 |
}, |
| 1169 |
"get_alert_policies": [], |
| 1170 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1171 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1172 |
"get_schedule_payload": {"StartTime": "", "EndTime": ""}, |
| 1173 |
"get_severity_payload": {}, |
| 1174 |
"json_data": { |
| 1175 |
"value": [ |
| 1176 |
{ |
| 1177 |
"Id": 100, |
| 1178 |
"Name": "SMS", |
| 1179 |
"Description": "Ignore", |
| 1180 |
"Disabled": False, |
| 1181 |
"ParameterDetails": [] |
| 1182 |
}, |
| 1183 |
{ |
| 1184 |
"Id": 60, |
| 1185 |
"Name": "Trap", |
| 1186 |
"Description": "Trap", |
| 1187 |
"Disabled": False, |
| 1188 |
"ParameterDetails": [ |
| 1189 |
{ |
| 1190 |
"Id": 1, |
| 1191 |
"Name": trap_ip1, |
| 1192 |
"Value": "true", |
| 1193 |
"Type": "boolean", |
| 1194 |
"TemplateParameterTypeDetails": [] |
| 1195 |
} |
| 1196 |
] |
| 1197 |
} |
| 1198 |
] |
| 1199 |
} |
| 1200 |
}, |
| 1201 |
{"message": ACTION_INVALID_VALUE.format("Trap", "Truthy", "traphost1:162", "true, false"), "success": True, |
| 1202 |
"mparams": { |
| 1203 |
"actions": [{ |
| 1204 |
"action_name": "Trap", |
| 1205 |
"parameters": [ |
| 1206 |
{ |
| 1207 |
"name": trap_ip1, |
| 1208 |
"value": "Truthy" |
| 1209 |
} |
| 1210 |
] |
| 1211 |
}], |
| 1212 |
"all_devices": True, |
| 1213 |
"message_ids": ["AMP01", "CTL201"], |
| 1214 |
"state": "present", |
| 1215 |
"name": "Test alert policy", |
| 1216 |
"description": "actions invalid coverage" |
| 1217 |
}, |
| 1218 |
"get_alert_policies": [], |
| 1219 |
"get_target_payload": {"Devices": [123, 124]}, |
| 1220 |
"get_category_or_message": {"MessageIds": ["AMP01", "CTL201"]}, |
| 1221 |
"get_schedule_payload": {"StartTime": "2023-11-01 11:00:00.000", "EndTime": "2023-12-01 12:00:00.000"}, |
| 1222 |
"get_severity_payload": {}, |
| 1223 |
"json_data": { |
| 1224 |
"value": [ |
| 1225 |
{ |
| 1226 |
"Id": 60, |
| 1227 |
"Name": "Trap", |
| 1228 |
"Description": "Trap", |
| 1229 |
"Disabled": False, |
| 1230 |
"ParameterDetails": [ |
| 1231 |
{ |
| 1232 |
"Id": 1, |
| 1233 |
"Name": trap_ip1, |
| 1234 |
"Value": "true", |
| 1235 |
"Type": "boolean", |
| 1236 |
"TemplateParameterTypeDetails": [] |
| 1237 |
} |
| 1238 |
] |
| 1239 |
}] |
| 1240 |
} |
| 1241 |
}, |
| 1242 |
{"message": ACTION_DIS_EXIST.format("SNMPTrap"), "success": True, |
| 1243 |
"mparams": { |
| 1244 |
"actions": [{ |
| 1245 |
"action_name": "SNMPTrap", |
| 1246 |
"parameters": [ |
| 1247 |
{ |
| 1248 |
"name": trap_ip1, |
| 1249 |
"value": "true" |
| 1250 |
} |
| 1251 |
] |
| 1252 |
}], |
| 1253 |
"all_devices": True, |
| 1254 |
"message_ids": ["BIOS101", "RND123"], |
| 1255 |
"state": "present", |
| 1256 |
"name": "Test alert policy", |
| 1257 |
"description": "No existing action coverage" |
| 1258 |
}, |
| 1259 |
"get_alert_policies": [], |
| 1260 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1261 |
"get_category_or_message": {"MessageIds": ["MSG23", "MSG46"]}, |
| 1262 |
"get_schedule_payload": {"StartTime": "2023-11-01 11:00:00.000", "EndTime": "2023-12-01 12:00:00.000"}, |
| 1263 |
"get_severity_payload": {}, |
| 1264 |
"json_data": { |
| 1265 |
"value": [ |
| 1266 |
{ |
| 1267 |
"Id": 60, |
| 1268 |
"Name": "Trap", |
| 1269 |
"Description": "Trap", |
| 1270 |
"Disabled": False, |
| 1271 |
"ParameterDetails": [ |
| 1272 |
{ |
| 1273 |
"Id": 1, |
| 1274 |
"Name": trap_ip1, |
| 1275 |
"Value": "true", |
| 1276 |
"Type": "boolean", |
| 1277 |
"TemplateParameterTypeDetails": [] |
| 1278 |
} |
| 1279 |
] |
| 1280 |
}] |
| 1281 |
} |
| 1282 |
}, |
| 1283 |
{"message": INVALID_TIME.format("from", "2023-20-01 11:00:00.000"), "success": True, |
| 1284 |
"mparams": { |
| 1285 |
"date_and_time": { |
| 1286 |
"date_from": "2023-20-01", |
| 1287 |
"date_to": "2023-10-02", |
| 1288 |
"days": [ |
| 1289 |
"sunday", |
| 1290 |
"monday" |
| 1291 |
], |
| 1292 |
"time_from": "11:00", |
| 1293 |
"time_to": "12:00", |
| 1294 |
"time_interval": True |
| 1295 |
}, |
| 1296 |
"all_devices": True, |
| 1297 |
"message_ids": ["MSG01", "MSG02"], |
| 1298 |
"state": "present", |
| 1299 |
"name": "Test alert policy", |
| 1300 |
"description": "get_schedule coverage" |
| 1301 |
}, |
| 1302 |
"get_alert_policies": [], |
| 1303 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1304 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1305 |
"json_data": { |
| 1306 |
"value": [] |
| 1307 |
} |
| 1308 |
}, |
| 1309 |
{"message": INVALID_TIME.format("from", "2023-10-01 31:00:00.000"), "success": True, |
| 1310 |
"mparams": { |
| 1311 |
"date_and_time": { |
| 1312 |
"date_from": "2023-10-01", |
| 1313 |
"date_to": "2023-10-02", |
| 1314 |
"days": [ |
| 1315 |
"sunday", |
| 1316 |
"monday" |
| 1317 |
], |
| 1318 |
"time_from": "31:00", |
| 1319 |
"time_to": "12:00", |
| 1320 |
"time_interval": True |
| 1321 |
}, |
| 1322 |
"all_devices": True, |
| 1323 |
"message_ids": ["MSG01", "MSG02"], |
| 1324 |
"state": "present", |
| 1325 |
"name": "Test alert policy", |
| 1326 |
"description": "get_schedule coverage" |
| 1327 |
}, |
| 1328 |
"get_alert_policies": [], |
| 1329 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1330 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1331 |
"json_data": { |
| 1332 |
"value": [] |
| 1333 |
} |
| 1334 |
}, |
| 1335 |
{"message": END_START_TIME.format("2023-10-01 12:00:00", "2023-10-02 11:00:00"), "success": True, |
| 1336 |
"mparams": { |
| 1337 |
"date_and_time": { |
| 1338 |
"date_from": "2023-10-02", |
| 1339 |
"date_to": "2023-10-01", |
| 1340 |
"days": [ |
| 1341 |
"sunday", |
| 1342 |
"monday" |
| 1343 |
], |
| 1344 |
"time_from": "11:00", |
| 1345 |
"time_to": "12:00", |
| 1346 |
"time_interval": True |
| 1347 |
}, |
| 1348 |
"all_devices": True, |
| 1349 |
"message_ids": ["MSG01", "MSG02"], |
| 1350 |
"state": "present", |
| 1351 |
"name": "Test alert policy", |
| 1352 |
"description": "get_schedule coverage" |
| 1353 |
}, |
| 1354 |
"get_alert_policies": [], |
| 1355 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1356 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1357 |
"json_data": { |
| 1358 |
"value": [] |
| 1359 |
} |
| 1360 |
}, |
| 1361 |
{"message": INVALID_TIME.format("to", "2023-10-32 32:00:00.000"), "success": True, |
| 1362 |
"mparams": { |
| 1363 |
"date_and_time": { |
| 1364 |
"date_from": "2023-10-01", |
| 1365 |
"date_to": "2023-10-32", |
| 1366 |
"days": [ |
| 1367 |
"sunday", |
| 1368 |
"monday" |
| 1369 |
], |
| 1370 |
"time_from": "11:00", |
| 1371 |
"time_to": "32:00", |
| 1372 |
"time_interval": True |
| 1373 |
}, |
| 1374 |
"all_devices": True, |
| 1375 |
"message_ids": ["MSG01", "MSG02"], |
| 1376 |
"state": "present", |
| 1377 |
"name": "Test alert policy", |
| 1378 |
"description": "get_schedule coverage" |
| 1379 |
}, |
| 1380 |
"get_alert_policies": [], |
| 1381 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1382 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1383 |
"json_data": { |
| 1384 |
"value": [] |
| 1385 |
} |
| 1386 |
}, |
| 1387 |
{"message": INVALID_TARGETS, "success": True, |
| 1388 |
"mparams": { |
| 1389 |
"all_devices": True, |
| 1390 |
"message_ids": ["MSG01", "MSG02"], |
| 1391 |
"state": "present", |
| 1392 |
"name": "Test alert policy", |
| 1393 |
"description": "INVALID_TARGETS coverage" |
| 1394 |
}, |
| 1395 |
"get_alert_policies": [], |
| 1396 |
"get_target_payload": {}, |
| 1397 |
"json_data": { |
| 1398 |
"value": [] |
| 1399 |
} |
| 1400 |
}, |
| 1401 |
{"message": INVALID_ACTIONS, "success": True, |
| 1402 |
"mparams": { |
| 1403 |
"all_devices": True, |
| 1404 |
"message_ids": ["MSG01", "MSG02"], |
| 1405 |
"state": "present", |
| 1406 |
"name": "Test alert policy", |
| 1407 |
"description": "get_schedule coverage", |
| 1408 |
"date_and_time": { |
| 1409 |
"date_from": "2023-10-01", |
| 1410 |
"days": [ |
| 1411 |
"sunday", |
| 1412 |
"monday" |
| 1413 |
], |
| 1414 |
"time_from": "11:00", |
| 1415 |
"time_to": "12:00", |
| 1416 |
"time_interval": True |
| 1417 |
}, |
| 1418 |
}, |
| 1419 |
"get_alert_policies": [], |
| 1420 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1421 |
"get_category_or_message": {"MessageIds": ["MSG01", "MSG02"]}, |
| 1422 |
"get_actions_payload": {}, |
| 1423 |
"json_data": { |
| 1424 |
"value": [] |
| 1425 |
} |
| 1426 |
}, |
| 1427 |
{"message": CATEGORY_FETCH_FAILED, "success": True, |
| 1428 |
"mparams": { |
| 1429 |
"all_devices": True, |
| 1430 |
"category": [ |
| 1431 |
{ |
| 1432 |
"catalog_category": [ |
| 1433 |
{ |
| 1434 |
"category_name": "Audit", |
| 1435 |
"sub_category_names": [ |
| 1436 |
"Users", |
| 1437 |
"Generic" |
| 1438 |
] |
| 1439 |
} |
| 1440 |
], |
| 1441 |
"catalog_name": "Application" |
| 1442 |
} |
| 1443 |
], |
| 1444 |
"state": "present", |
| 1445 |
"name": "Test alert policy", |
| 1446 |
"description": "get_schedule coverage" |
| 1447 |
}, |
| 1448 |
"get_alert_policies": [], |
| 1449 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1450 |
"get_category_data_tree": {}, |
| 1451 |
"json_data": { |
| 1452 |
"value": [] |
| 1453 |
} |
| 1454 |
}, |
| 1455 |
{"message": SUBCAT_IN_CATEGORY.format("General", "Audit"), "success": True, |
| 1456 |
"mparams": { |
| 1457 |
"all_devices": True, |
| 1458 |
"category": [ |
| 1459 |
{ |
| 1460 |
"catalog_category": [ |
| 1461 |
{ |
| 1462 |
"category_name": "Audit", |
| 1463 |
"sub_category_names": [ |
| 1464 |
"General", |
| 1465 |
"Generic" |
| 1466 |
] |
| 1467 |
} |
| 1468 |
], |
| 1469 |
"catalog_name": "Application" |
| 1470 |
} |
| 1471 |
], |
| 1472 |
"state": "present", |
| 1473 |
"name": "Test alert policy", |
| 1474 |
"description": "get_schedule coverage" |
| 1475 |
}, |
| 1476 |
"get_alert_policies": [], |
| 1477 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1478 |
"get_category_data_tree": get_category_data_tree, |
| 1479 |
"json_data": { |
| 1480 |
"value": [] |
| 1481 |
} |
| 1482 |
}, |
| 1483 |
{"message": CATEGORY_IN_CATALOG.format("Audi", "Application"), "success": True, |
| 1484 |
"mparams": { |
| 1485 |
"all_devices": True, |
| 1486 |
"category": [ |
| 1487 |
{ |
| 1488 |
"catalog_category": [ |
| 1489 |
{ |
| 1490 |
"category_name": "Audi", |
| 1491 |
"sub_category_names": [ |
| 1492 |
"General", |
| 1493 |
"Generic" |
| 1494 |
] |
| 1495 |
} |
| 1496 |
], |
| 1497 |
"catalog_name": "Application" |
| 1498 |
} |
| 1499 |
], |
| 1500 |
"state": "present", |
| 1501 |
"name": "Test alert policy", |
| 1502 |
"description": "get_schedule coverage" |
| 1503 |
}, |
| 1504 |
"get_alert_policies": [], |
| 1505 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1506 |
"get_category_data_tree": get_category_data_tree, |
| 1507 |
"json_data": { |
| 1508 |
"value": [] |
| 1509 |
} |
| 1510 |
}, |
| 1511 |
{"message": CATALOG_DIS_EXIST.format("Alpha"), "success": True, |
| 1512 |
"mparams": { |
| 1513 |
"all_devices": True, |
| 1514 |
"category": [ |
| 1515 |
{ |
| 1516 |
"catalog_name": "Alpha" |
| 1517 |
} |
| 1518 |
], |
| 1519 |
"state": "present", |
| 1520 |
"name": "Test alert policy", |
| 1521 |
"description": "get_schedule coverage" |
| 1522 |
}, |
| 1523 |
"get_alert_policies": [], |
| 1524 |
"get_target_payload": {"Groups": [123, 124]}, |
| 1525 |
"get_category_data_tree": get_category_data_tree, |
| 1526 |
"json_data": { |
| 1527 |
"value": [] |
| 1528 |
} |
| 1529 |
} |
| 1530 |
]) |
| 1531 |
def test_ome_alert_policies_state_present(self, params, ome_connection_mock_for_alert_policies, |
| 1532 |
ome_response_mock, ome_default_args, module_mock, mocker): |
| 1533 |
ome_response_mock.success = params.get("success", True) |
| 1534 |
ome_response_mock.json_data = params['json_data'] |
| 1535 |
ome_connection_mock_for_alert_policies.get_all_items_with_pagination.return_value = params[ |
| 1536 |
'json_data'] |
| 1537 |
ome_default_args.update(params['mparams']) |
| 1538 |
mocks = ["get_alert_policies", "validate_ome_data", "get_target_payload", |
| 1539 |
"get_all_actions", "get_severity_payload", "get_category_data_tree", |
| 1540 |
"get_schedule_payload", "get_category_or_message"] |
| 1541 |
for m in mocks: |
| 1542 |
if m in params: |
| 1543 |
mocker.patch(MODULE_PATH + m, return_value=params.get(m, {})) |
| 1544 |
if "create_temp_file" in params: |
| 1545 |
with open(f"{params['mparams'].get('message_file')}", 'w', encoding='utf-8') as fp: |
| 1546 |
fp.write(params["create_temp_file"]) |
| 1547 |
result = self._run_module( |
| 1548 |
ome_default_args, check_mode=params.get('check_mode', False)) |
| 1549 |
if "create_temp_file" in params: |
| 1550 |
fpath = f"{params['mparams'].get('message_file')}" |
| 1551 |
if os.path.exists(fpath): |
| 1552 |
os.remove(fpath) |
| 1553 |
assert result['msg'] == params['message'] |
| 1554 |
|
| 1555 |
@pytest.mark.parametrize("exc_type", |
| 1556 |
[SSLValidationError, ConnectionError, TypeError, ValueError, OSError, HTTPError, URLError]) |
| 1557 |
def test_ome_alert_policies_category_info_main_exception_failure_case(self, exc_type, mocker, ome_default_args, |
| 1558 |
ome_connection_mock_for_alert_policies, |
| 1559 |
ome_response_mock): |
| 1560 |
json_str = to_text(json.dumps({"data": "out"})) |
| 1561 |
ome_default_args.update({"name": "new alert policy", "enable": True}) |
| 1562 |
if exc_type == HTTPError: |
| 1563 |
mocker.patch(MODULE_PATH + 'get_alert_policies', side_effect=exc_type( |
| 1564 |
'https://testhost.com', 401, 'http error message', { |
| 1565 |
"accept-type": "application/json"}, |
| 1566 |
StringIO(json_str))) |
| 1567 |
result = self._run_module(ome_default_args) |
| 1568 |
assert result['failed'] is True |
| 1569 |
elif exc_type == URLError: |
| 1570 |
mocker.patch(MODULE_PATH + 'get_alert_policies', |
| 1571 |
side_effect=exc_type("exception message")) |
| 1572 |
result = self._run_module(ome_default_args) |
| 1573 |
assert result['unreachable'] is True |
| 1574 |
else: |
| 1575 |
mocker.patch(MODULE_PATH + 'get_alert_policies', |
| 1576 |
side_effect=exc_type("exception message")) |
| 1577 |
result = self._run_module(ome_default_args) |
| 1578 |
assert result['failed'] is True |