| @@ 552-658 (lines=107) @@ | ||
| 549 | ||
| 550 | return self._send_xml_command(cmd) |
|
| 551 | ||
| 552 | def modify_alert( |
|
| 553 | self, |
|
| 554 | alert_id: str, |
|
| 555 | *, |
|
| 556 | name: Optional[str] = None, |
|
| 557 | comment: Optional[str] = None, |
|
| 558 | filter_id: Optional[str] = None, |
|
| 559 | event: Optional[AlertEvent] = None, |
|
| 560 | event_data: Optional[dict] = None, |
|
| 561 | condition: Optional[AlertCondition] = None, |
|
| 562 | condition_data: Optional[dict] = None, |
|
| 563 | method: Optional[AlertMethod] = None, |
|
| 564 | method_data: Optional[dict] = None |
|
| 565 | ) -> Any: |
|
| 566 | """Modifies an existing alert. |
|
| 567 | ||
| 568 | Arguments: |
|
| 569 | alert_id: UUID of the alert to be modified. |
|
| 570 | name: Name of the Alert. |
|
| 571 | condition: The condition that must be satisfied for the alert to |
|
| 572 | occur. If the event is either 'Updated SecInfo |
|
| 573 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 574 | Otherwise, condition can also be on of 'Severity at least', |
|
| 575 | 'Filter count changed' or 'Filter count at least'. |
|
| 576 | condition_data: Data that defines the condition |
|
| 577 | event: The event that must happen for the alert to occur, one of |
|
| 578 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 579 | 'New SecInfo arrived' |
|
| 580 | event_data: Data that defines the event |
|
| 581 | method: The method by which the user is alerted, one of 'SCP', |
|
| 582 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 583 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 584 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 585 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 586 | method_data: Data that defines the method |
|
| 587 | filter_id: Filter to apply when executing alert |
|
| 588 | comment: Comment for the alert |
|
| 589 | ||
| 590 | Returns: |
|
| 591 | The response. See :py:meth:`send_command` for details. |
|
| 592 | """ |
|
| 593 | ||
| 594 | if not alert_id: |
|
| 595 | raise RequiredArgument( |
|
| 596 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 597 | ) |
|
| 598 | ||
| 599 | cmd = XmlCommand("modify_alert") |
|
| 600 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 601 | ||
| 602 | if name: |
|
| 603 | cmd.add_element("name", name) |
|
| 604 | ||
| 605 | if comment: |
|
| 606 | cmd.add_element("comment", comment) |
|
| 607 | ||
| 608 | if filter_id: |
|
| 609 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 610 | ||
| 611 | if condition: |
|
| 612 | if not isinstance(condition, AlertCondition): |
|
| 613 | raise InvalidArgumentType( |
|
| 614 | function=self.modify_alert.__name__, |
|
| 615 | argument='condition', |
|
| 616 | arg_type=AlertCondition.__name__, |
|
| 617 | ) |
|
| 618 | ||
| 619 | conditions = cmd.add_element("condition", condition.value) |
|
| 620 | ||
| 621 | if condition_data is not None: |
|
| 622 | for key, value in condition_data.items(): |
|
| 623 | _data = conditions.add_element("data", value) |
|
| 624 | _data.add_element("name", key) |
|
| 625 | ||
| 626 | if method: |
|
| 627 | if not isinstance(method, AlertMethod): |
|
| 628 | raise InvalidArgumentType( |
|
| 629 | function=self.modify_alert.__name__, |
|
| 630 | argument='method', |
|
| 631 | arg_type=AlertMethod.__name__, |
|
| 632 | ) |
|
| 633 | ||
| 634 | methods = cmd.add_element("method", method.value) |
|
| 635 | ||
| 636 | if method_data is not None: |
|
| 637 | for key, value in method_data.items(): |
|
| 638 | _data = methods.add_element("data", value) |
|
| 639 | _data.add_element("name", key) |
|
| 640 | ||
| 641 | if event: |
|
| 642 | if not isinstance(event, AlertEvent): |
|
| 643 | raise InvalidArgumentType( |
|
| 644 | function=self.modify_alert.__name__, |
|
| 645 | argument='event', |
|
| 646 | arg_type=AlertEvent.__name__, |
|
| 647 | ) |
|
| 648 | ||
| 649 | _check_event(event, condition, method) |
|
| 650 | ||
| 651 | events = cmd.add_element("event", event.value) |
|
| 652 | ||
| 653 | if event_data is not None: |
|
| 654 | for key, value in event_data.items(): |
|
| 655 | _data = events.add_element("data", value) |
|
| 656 | _data.add_element("name", key) |
|
| 657 | ||
| 658 | return self._send_xml_command(cmd) |
|
| 659 | ||
| 660 | def modify_audit( |
|
| 661 | self, |
|
| @@ 4434-4540 (lines=107) @@ | ||
| 4431 | ||
| 4432 | return self._send_xml_command(cmd) |
|
| 4433 | ||
| 4434 | def modify_alert( |
|
| 4435 | self, |
|
| 4436 | alert_id: str, |
|
| 4437 | *, |
|
| 4438 | name: Optional[str] = None, |
|
| 4439 | comment: Optional[str] = None, |
|
| 4440 | filter_id: Optional[str] = None, |
|
| 4441 | event: Optional[AlertEvent] = None, |
|
| 4442 | event_data: Optional[dict] = None, |
|
| 4443 | condition: Optional[AlertCondition] = None, |
|
| 4444 | condition_data: Optional[dict] = None, |
|
| 4445 | method: Optional[AlertMethod] = None, |
|
| 4446 | method_data: Optional[dict] = None |
|
| 4447 | ) -> Any: |
|
| 4448 | """Modifies an existing alert. |
|
| 4449 | ||
| 4450 | Arguments: |
|
| 4451 | alert_id: UUID of the alert to be modified. |
|
| 4452 | name: Name of the Alert. |
|
| 4453 | condition: The condition that must be satisfied for the alert to |
|
| 4454 | occur. If the event is either 'Updated SecInfo |
|
| 4455 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 4456 | Otherwise, condition can also be on of 'Severity at least', |
|
| 4457 | 'Filter count changed' or 'Filter count at least'. |
|
| 4458 | condition_data: Data that defines the condition |
|
| 4459 | event: The event that must happen for the alert to occur, one of |
|
| 4460 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 4461 | 'New SecInfo arrived' |
|
| 4462 | event_data: Data that defines the event |
|
| 4463 | method: The method by which the user is alerted, one of 'SCP', |
|
| 4464 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 4465 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 4466 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 4467 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 4468 | method_data: Data that defines the method |
|
| 4469 | filter_id: Filter to apply when executing alert |
|
| 4470 | comment: Comment for the alert |
|
| 4471 | ||
| 4472 | Returns: |
|
| 4473 | The response. See :py:meth:`send_command` for details. |
|
| 4474 | """ |
|
| 4475 | ||
| 4476 | if not alert_id: |
|
| 4477 | raise RequiredArgument( |
|
| 4478 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 4479 | ) |
|
| 4480 | ||
| 4481 | cmd = XmlCommand("modify_alert") |
|
| 4482 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 4483 | ||
| 4484 | if name: |
|
| 4485 | cmd.add_element("name", name) |
|
| 4486 | ||
| 4487 | if comment: |
|
| 4488 | cmd.add_element("comment", comment) |
|
| 4489 | ||
| 4490 | if filter_id: |
|
| 4491 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 4492 | ||
| 4493 | if condition: |
|
| 4494 | if not isinstance(condition, AlertCondition): |
|
| 4495 | raise InvalidArgumentType( |
|
| 4496 | function=self.modify_alert.__name__, |
|
| 4497 | argument='condition', |
|
| 4498 | arg_type=AlertCondition.__name__, |
|
| 4499 | ) |
|
| 4500 | ||
| 4501 | conditions = cmd.add_element("condition", condition.value) |
|
| 4502 | ||
| 4503 | if condition_data is not None: |
|
| 4504 | for key, value in condition_data.items(): |
|
| 4505 | _data = conditions.add_element("data", value) |
|
| 4506 | _data.add_element("name", key) |
|
| 4507 | ||
| 4508 | if method: |
|
| 4509 | if not isinstance(method, AlertMethod): |
|
| 4510 | raise InvalidArgumentType( |
|
| 4511 | function=self.modify_alert.__name__, |
|
| 4512 | argument='method', |
|
| 4513 | arg_type=AlertMethod.__name__, |
|
| 4514 | ) |
|
| 4515 | ||
| 4516 | methods = cmd.add_element("method", method.value) |
|
| 4517 | ||
| 4518 | if method_data is not None: |
|
| 4519 | for key, value in method_data.items(): |
|
| 4520 | _data = methods.add_element("data", value) |
|
| 4521 | _data.add_element("name", key) |
|
| 4522 | ||
| 4523 | if event: |
|
| 4524 | if not isinstance(event, AlertEvent): |
|
| 4525 | raise InvalidArgumentType( |
|
| 4526 | function=self.modify_alert.__name__, |
|
| 4527 | argument='event', |
|
| 4528 | arg_type=AlertEvent.__name__, |
|
| 4529 | ) |
|
| 4530 | ||
| 4531 | _check_event(event, condition, method) |
|
| 4532 | ||
| 4533 | events = cmd.add_element("event", event.value) |
|
| 4534 | ||
| 4535 | if event_data is not None: |
|
| 4536 | for key, value in event_data.items(): |
|
| 4537 | _data = events.add_element("data", value) |
|
| 4538 | _data.add_element("name", key) |
|
| 4539 | ||
| 4540 | return self._send_xml_command(cmd) |
|
| 4541 | ||
| 4542 | def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
|
| 4543 | """Modifies an existing asset. |
|