| @@ 4437-4543 (lines=107) @@ | ||
| 4434 | ||
| 4435 | return self._send_xml_command(cmd) |
|
| 4436 | ||
| 4437 | def modify_alert( |
|
| 4438 | self, |
|
| 4439 | alert_id: str, |
|
| 4440 | *, |
|
| 4441 | name: Optional[str] = None, |
|
| 4442 | comment: Optional[str] = None, |
|
| 4443 | filter_id: Optional[str] = None, |
|
| 4444 | event: Optional[AlertEvent] = None, |
|
| 4445 | event_data: Optional[dict] = None, |
|
| 4446 | condition: Optional[AlertCondition] = None, |
|
| 4447 | condition_data: Optional[dict] = None, |
|
| 4448 | method: Optional[AlertMethod] = None, |
|
| 4449 | method_data: Optional[dict] = None |
|
| 4450 | ) -> Any: |
|
| 4451 | """Modifies an existing alert. |
|
| 4452 | ||
| 4453 | Arguments: |
|
| 4454 | alert_id: UUID of the alert to be modified. |
|
| 4455 | name: Name of the Alert. |
|
| 4456 | condition: The condition that must be satisfied for the alert to |
|
| 4457 | occur. If the event is either 'Updated SecInfo |
|
| 4458 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 4459 | Otherwise, condition can also be on of 'Severity at least', |
|
| 4460 | 'Filter count changed' or 'Filter count at least'. |
|
| 4461 | condition_data: Data that defines the condition |
|
| 4462 | event: The event that must happen for the alert to occur, one of |
|
| 4463 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 4464 | 'New SecInfo arrived' |
|
| 4465 | event_data: Data that defines the event |
|
| 4466 | method: The method by which the user is alerted, one of 'SCP', |
|
| 4467 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 4468 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 4469 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 4470 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 4471 | method_data: Data that defines the method |
|
| 4472 | filter_id: Filter to apply when executing alert |
|
| 4473 | comment: Comment for the alert |
|
| 4474 | ||
| 4475 | Returns: |
|
| 4476 | The response. See :py:meth:`send_command` for details. |
|
| 4477 | """ |
|
| 4478 | ||
| 4479 | if not alert_id: |
|
| 4480 | raise RequiredArgument( |
|
| 4481 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 4482 | ) |
|
| 4483 | ||
| 4484 | cmd = XmlCommand("modify_alert") |
|
| 4485 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 4486 | ||
| 4487 | if name: |
|
| 4488 | cmd.add_element("name", name) |
|
| 4489 | ||
| 4490 | if comment: |
|
| 4491 | cmd.add_element("comment", comment) |
|
| 4492 | ||
| 4493 | if filter_id: |
|
| 4494 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 4495 | ||
| 4496 | if condition: |
|
| 4497 | if not isinstance(condition, AlertCondition): |
|
| 4498 | raise InvalidArgumentType( |
|
| 4499 | function=self.modify_alert.__name__, |
|
| 4500 | argument='condition', |
|
| 4501 | arg_type=AlertCondition.__name__, |
|
| 4502 | ) |
|
| 4503 | ||
| 4504 | conditions = cmd.add_element("condition", condition.value) |
|
| 4505 | ||
| 4506 | if condition_data is not None: |
|
| 4507 | for key, value in condition_data.items(): |
|
| 4508 | _data = conditions.add_element("data", value) |
|
| 4509 | _data.add_element("name", key) |
|
| 4510 | ||
| 4511 | if method: |
|
| 4512 | if not isinstance(method, AlertMethod): |
|
| 4513 | raise InvalidArgumentType( |
|
| 4514 | function=self.modify_alert.__name__, |
|
| 4515 | argument='method', |
|
| 4516 | arg_type=AlertMethod.__name__, |
|
| 4517 | ) |
|
| 4518 | ||
| 4519 | methods = cmd.add_element("method", method.value) |
|
| 4520 | ||
| 4521 | if method_data is not None: |
|
| 4522 | for key, value in method_data.items(): |
|
| 4523 | _data = methods.add_element("data", value) |
|
| 4524 | _data.add_element("name", key) |
|
| 4525 | ||
| 4526 | if event: |
|
| 4527 | if not isinstance(event, AlertEvent): |
|
| 4528 | raise InvalidArgumentType( |
|
| 4529 | function=self.modify_alert.__name__, |
|
| 4530 | argument='event', |
|
| 4531 | arg_type=AlertEvent.__name__, |
|
| 4532 | ) |
|
| 4533 | ||
| 4534 | _check_event(event, condition, method) |
|
| 4535 | ||
| 4536 | events = cmd.add_element("event", event.value) |
|
| 4537 | ||
| 4538 | if event_data is not None: |
|
| 4539 | for key, value in event_data.items(): |
|
| 4540 | _data = events.add_element("data", value) |
|
| 4541 | _data.add_element("name", key) |
|
| 4542 | ||
| 4543 | return self._send_xml_command(cmd) |
|
| 4544 | ||
| 4545 | def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
|
| 4546 | """Modifies an existing asset. |
|
| @@ 722-828 (lines=107) @@ | ||
| 719 | ||
| 720 | return self._send_xml_command(cmd) |
|
| 721 | ||
| 722 | def modify_alert( |
|
| 723 | self, |
|
| 724 | alert_id: str, |
|
| 725 | *, |
|
| 726 | name: Optional[str] = None, |
|
| 727 | comment: Optional[str] = None, |
|
| 728 | filter_id: Optional[str] = None, |
|
| 729 | event: Optional[AlertEvent] = None, |
|
| 730 | event_data: Optional[dict] = None, |
|
| 731 | condition: Optional[AlertCondition] = None, |
|
| 732 | condition_data: Optional[dict] = None, |
|
| 733 | method: Optional[AlertMethod] = None, |
|
| 734 | method_data: Optional[dict] = None |
|
| 735 | ) -> Any: |
|
| 736 | """Modifies an existing alert. |
|
| 737 | ||
| 738 | Arguments: |
|
| 739 | alert_id: UUID of the alert to be modified. |
|
| 740 | name: Name of the Alert. |
|
| 741 | condition: The condition that must be satisfied for the alert to |
|
| 742 | occur. If the event is either 'Updated SecInfo |
|
| 743 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 744 | Otherwise, condition can also be on of 'Severity at least', |
|
| 745 | 'Filter count changed' or 'Filter count at least'. |
|
| 746 | condition_data: Data that defines the condition |
|
| 747 | event: The event that must happen for the alert to occur, one of |
|
| 748 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 749 | 'New SecInfo arrived' |
|
| 750 | event_data: Data that defines the event |
|
| 751 | method: The method by which the user is alerted, one of 'SCP', |
|
| 752 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 753 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 754 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 755 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 756 | method_data: Data that defines the method |
|
| 757 | filter_id: Filter to apply when executing alert |
|
| 758 | comment: Comment for the alert |
|
| 759 | ||
| 760 | Returns: |
|
| 761 | The response. See :py:meth:`send_command` for details. |
|
| 762 | """ |
|
| 763 | ||
| 764 | if not alert_id: |
|
| 765 | raise RequiredArgument( |
|
| 766 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 767 | ) |
|
| 768 | ||
| 769 | cmd = XmlCommand("modify_alert") |
|
| 770 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 771 | ||
| 772 | if name: |
|
| 773 | cmd.add_element("name", name) |
|
| 774 | ||
| 775 | if comment: |
|
| 776 | cmd.add_element("comment", comment) |
|
| 777 | ||
| 778 | if filter_id: |
|
| 779 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 780 | ||
| 781 | if condition: |
|
| 782 | if not isinstance(condition, AlertCondition): |
|
| 783 | raise InvalidArgumentType( |
|
| 784 | function=self.modify_alert.__name__, |
|
| 785 | argument='condition', |
|
| 786 | arg_type=AlertCondition.__name__, |
|
| 787 | ) |
|
| 788 | ||
| 789 | conditions = cmd.add_element("condition", condition.value) |
|
| 790 | ||
| 791 | if condition_data is not None: |
|
| 792 | for key, value in condition_data.items(): |
|
| 793 | _data = conditions.add_element("data", value) |
|
| 794 | _data.add_element("name", key) |
|
| 795 | ||
| 796 | if method: |
|
| 797 | if not isinstance(method, AlertMethod): |
|
| 798 | raise InvalidArgumentType( |
|
| 799 | function=self.modify_alert.__name__, |
|
| 800 | argument='method', |
|
| 801 | arg_type=AlertMethod.__name__, |
|
| 802 | ) |
|
| 803 | ||
| 804 | methods = cmd.add_element("method", method.value) |
|
| 805 | ||
| 806 | if method_data is not None: |
|
| 807 | for key, value in method_data.items(): |
|
| 808 | _data = methods.add_element("data", value) |
|
| 809 | _data.add_element("name", key) |
|
| 810 | ||
| 811 | if event: |
|
| 812 | if not isinstance(event, AlertEvent): |
|
| 813 | raise InvalidArgumentType( |
|
| 814 | function=self.modify_alert.__name__, |
|
| 815 | argument='event', |
|
| 816 | arg_type=AlertEvent.__name__, |
|
| 817 | ) |
|
| 818 | ||
| 819 | _check_event(event, condition, method) |
|
| 820 | ||
| 821 | events = cmd.add_element("event", event.value) |
|
| 822 | ||
| 823 | if event_data is not None: |
|
| 824 | for key, value in event_data.items(): |
|
| 825 | _data = events.add_element("data", value) |
|
| 826 | _data.add_element("name", key) |
|
| 827 | ||
| 828 | return self._send_xml_command(cmd) |
|
| 829 | ||
| 830 | def modify_audit( |
|
| 831 | self, |
|