| @@ 4360-4466 (lines=107) @@ | ||
| 4357 | ||
| 4358 | return self._send_xml_command(cmd) |
|
| 4359 | ||
| 4360 | def modify_alert( |
|
| 4361 | self, |
|
| 4362 | alert_id: str, |
|
| 4363 | *, |
|
| 4364 | name: Optional[str] = None, |
|
| 4365 | comment: Optional[str] = None, |
|
| 4366 | filter_id: Optional[str] = None, |
|
| 4367 | event: Optional[AlertEvent] = None, |
|
| 4368 | event_data: Optional[dict] = None, |
|
| 4369 | condition: Optional[AlertCondition] = None, |
|
| 4370 | condition_data: Optional[dict] = None, |
|
| 4371 | method: Optional[AlertMethod] = None, |
|
| 4372 | method_data: Optional[dict] = None |
|
| 4373 | ) -> Any: |
|
| 4374 | """Modifies an existing alert. |
|
| 4375 | ||
| 4376 | Arguments: |
|
| 4377 | alert_id: UUID of the alert to be modified. |
|
| 4378 | name: Name of the Alert. |
|
| 4379 | condition: The condition that must be satisfied for the alert to |
|
| 4380 | occur. If the event is either 'Updated SecInfo |
|
| 4381 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 4382 | Otherwise, condition can also be on of 'Severity at least', |
|
| 4383 | 'Filter count changed' or 'Filter count at least'. |
|
| 4384 | condition_data: Data that defines the condition |
|
| 4385 | event: The event that must happen for the alert to occur, one of |
|
| 4386 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 4387 | 'New SecInfo arrived' |
|
| 4388 | event_data: Data that defines the event |
|
| 4389 | method: The method by which the user is alerted, one of 'SCP', |
|
| 4390 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 4391 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 4392 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 4393 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 4394 | method_data: Data that defines the method |
|
| 4395 | filter_id: Filter to apply when executing alert |
|
| 4396 | comment: Comment for the alert |
|
| 4397 | ||
| 4398 | Returns: |
|
| 4399 | The response. See :py:meth:`send_command` for details. |
|
| 4400 | """ |
|
| 4401 | ||
| 4402 | if not alert_id: |
|
| 4403 | raise RequiredArgument( |
|
| 4404 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 4405 | ) |
|
| 4406 | ||
| 4407 | cmd = XmlCommand("modify_alert") |
|
| 4408 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 4409 | ||
| 4410 | if name: |
|
| 4411 | cmd.add_element("name", name) |
|
| 4412 | ||
| 4413 | if comment: |
|
| 4414 | cmd.add_element("comment", comment) |
|
| 4415 | ||
| 4416 | if filter_id: |
|
| 4417 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 4418 | ||
| 4419 | if condition: |
|
| 4420 | if not isinstance(condition, AlertCondition): |
|
| 4421 | raise InvalidArgumentType( |
|
| 4422 | function=self.modify_alert.__name__, |
|
| 4423 | argument='condition', |
|
| 4424 | arg_type=AlertCondition.__name__, |
|
| 4425 | ) |
|
| 4426 | ||
| 4427 | conditions = cmd.add_element("condition", condition.value) |
|
| 4428 | ||
| 4429 | if condition_data is not None: |
|
| 4430 | for key, value in condition_data.items(): |
|
| 4431 | _data = conditions.add_element("data", value) |
|
| 4432 | _data.add_element("name", key) |
|
| 4433 | ||
| 4434 | if method: |
|
| 4435 | if not isinstance(method, AlertMethod): |
|
| 4436 | raise InvalidArgumentType( |
|
| 4437 | function=self.modify_alert.__name__, |
|
| 4438 | argument='method', |
|
| 4439 | arg_type=AlertMethod.__name__, |
|
| 4440 | ) |
|
| 4441 | ||
| 4442 | methods = cmd.add_element("method", method.value) |
|
| 4443 | ||
| 4444 | if method_data is not None: |
|
| 4445 | for key, value in method_data.items(): |
|
| 4446 | _data = methods.add_element("data", value) |
|
| 4447 | _data.add_element("name", key) |
|
| 4448 | ||
| 4449 | if event: |
|
| 4450 | if not isinstance(event, AlertEvent): |
|
| 4451 | raise InvalidArgumentType( |
|
| 4452 | function=self.modify_alert.__name__, |
|
| 4453 | argument='event', |
|
| 4454 | arg_type=AlertEvent.__name__, |
|
| 4455 | ) |
|
| 4456 | ||
| 4457 | _check_event(event, condition, method) |
|
| 4458 | ||
| 4459 | events = cmd.add_element("event", event.value) |
|
| 4460 | ||
| 4461 | if event_data is not None: |
|
| 4462 | for key, value in event_data.items(): |
|
| 4463 | _data = events.add_element("data", value) |
|
| 4464 | _data.add_element("name", key) |
|
| 4465 | ||
| 4466 | return self._send_xml_command(cmd) |
|
| 4467 | ||
| 4468 | def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
|
| 4469 | """Modifies an existing asset. |
|
| @@ 516-622 (lines=107) @@ | ||
| 513 | ||
| 514 | return self._send_xml_command(cmd) |
|
| 515 | ||
| 516 | def modify_alert( |
|
| 517 | self, |
|
| 518 | alert_id: str, |
|
| 519 | *, |
|
| 520 | name: Optional[str] = None, |
|
| 521 | comment: Optional[str] = None, |
|
| 522 | filter_id: Optional[str] = None, |
|
| 523 | event: Optional[AlertEvent] = None, |
|
| 524 | event_data: Optional[dict] = None, |
|
| 525 | condition: Optional[AlertCondition] = None, |
|
| 526 | condition_data: Optional[dict] = None, |
|
| 527 | method: Optional[AlertMethod] = None, |
|
| 528 | method_data: Optional[dict] = None |
|
| 529 | ) -> Any: |
|
| 530 | """Modifies an existing alert. |
|
| 531 | ||
| 532 | Arguments: |
|
| 533 | alert_id: UUID of the alert to be modified. |
|
| 534 | name: Name of the Alert. |
|
| 535 | condition: The condition that must be satisfied for the alert to |
|
| 536 | occur. If the event is either 'Updated SecInfo |
|
| 537 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 538 | Otherwise, condition can also be on of 'Severity at least', |
|
| 539 | 'Filter count changed' or 'Filter count at least'. |
|
| 540 | condition_data: Data that defines the condition |
|
| 541 | event: The event that must happen for the alert to occur, one of |
|
| 542 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 543 | 'New SecInfo arrived' |
|
| 544 | event_data: Data that defines the event |
|
| 545 | method: The method by which the user is alerted, one of 'SCP', |
|
| 546 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 547 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 548 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 549 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 550 | method_data: Data that defines the method |
|
| 551 | filter_id: Filter to apply when executing alert |
|
| 552 | comment: Comment for the alert |
|
| 553 | ||
| 554 | Returns: |
|
| 555 | The response. See :py:meth:`send_command` for details. |
|
| 556 | """ |
|
| 557 | ||
| 558 | if not alert_id: |
|
| 559 | raise RequiredArgument( |
|
| 560 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 561 | ) |
|
| 562 | ||
| 563 | cmd = XmlCommand("modify_alert") |
|
| 564 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 565 | ||
| 566 | if name: |
|
| 567 | cmd.add_element("name", name) |
|
| 568 | ||
| 569 | if comment: |
|
| 570 | cmd.add_element("comment", comment) |
|
| 571 | ||
| 572 | if filter_id: |
|
| 573 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 574 | ||
| 575 | if condition: |
|
| 576 | if not isinstance(condition, AlertCondition): |
|
| 577 | raise InvalidArgumentType( |
|
| 578 | function=self.modify_alert.__name__, |
|
| 579 | argument='condition', |
|
| 580 | arg_type=AlertCondition.__name__, |
|
| 581 | ) |
|
| 582 | ||
| 583 | conditions = cmd.add_element("condition", condition.value) |
|
| 584 | ||
| 585 | if condition_data is not None: |
|
| 586 | for key, value in condition_data.items(): |
|
| 587 | _data = conditions.add_element("data", value) |
|
| 588 | _data.add_element("name", key) |
|
| 589 | ||
| 590 | if method: |
|
| 591 | if not isinstance(method, AlertMethod): |
|
| 592 | raise InvalidArgumentType( |
|
| 593 | function=self.modify_alert.__name__, |
|
| 594 | argument='method', |
|
| 595 | arg_type=AlertMethod.__name__, |
|
| 596 | ) |
|
| 597 | ||
| 598 | methods = cmd.add_element("method", method.value) |
|
| 599 | ||
| 600 | if method_data is not None: |
|
| 601 | for key, value in method_data.items(): |
|
| 602 | _data = methods.add_element("data", value) |
|
| 603 | _data.add_element("name", key) |
|
| 604 | ||
| 605 | if event: |
|
| 606 | if not isinstance(event, AlertEvent): |
|
| 607 | raise InvalidArgumentType( |
|
| 608 | function=self.modify_alert.__name__, |
|
| 609 | argument='event', |
|
| 610 | arg_type=AlertEvent.__name__, |
|
| 611 | ) |
|
| 612 | ||
| 613 | _check_event(event, condition, method) |
|
| 614 | ||
| 615 | events = cmd.add_element("event", event.value) |
|
| 616 | ||
| 617 | if event_data is not None: |
|
| 618 | for key, value in event_data.items(): |
|
| 619 | _data = events.add_element("data", value) |
|
| 620 | _data.add_element("name", key) |
|
| 621 | ||
| 622 | return self._send_xml_command(cmd) |
|
| 623 | ||
| 624 | def modify_tls_certificate( |
|
| 625 | self, |
|