| @@ 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. |
|
| @@ 885-991 (lines=107) @@ | ||
| 882 | ||
| 883 | return self._send_xml_command(cmd) |
|
| 884 | ||
| 885 | def modify_alert( |
|
| 886 | self, |
|
| 887 | alert_id: str, |
|
| 888 | *, |
|
| 889 | name: Optional[str] = None, |
|
| 890 | comment: Optional[str] = None, |
|
| 891 | filter_id: Optional[str] = None, |
|
| 892 | event: Optional[AlertEvent] = None, |
|
| 893 | event_data: Optional[dict] = None, |
|
| 894 | condition: Optional[AlertCondition] = None, |
|
| 895 | condition_data: Optional[dict] = None, |
|
| 896 | method: Optional[AlertMethod] = None, |
|
| 897 | method_data: Optional[dict] = None |
|
| 898 | ) -> Any: |
|
| 899 | """Modifies an existing alert. |
|
| 900 | ||
| 901 | Arguments: |
|
| 902 | alert_id: UUID of the alert to be modified. |
|
| 903 | name: Name of the Alert. |
|
| 904 | condition: The condition that must be satisfied for the alert to |
|
| 905 | occur. If the event is either 'Updated SecInfo |
|
| 906 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
|
| 907 | Otherwise, condition can also be on of 'Severity at least', |
|
| 908 | 'Filter count changed' or 'Filter count at least'. |
|
| 909 | condition_data: Data that defines the condition |
|
| 910 | event: The event that must happen for the alert to occur, one of |
|
| 911 | 'Task run status changed', 'Updated SecInfo arrived' or |
|
| 912 | 'New SecInfo arrived' |
|
| 913 | event_data: Data that defines the event |
|
| 914 | method: The method by which the user is alerted, one of 'SCP', |
|
| 915 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
|
| 916 | if the event is neither 'Updated SecInfo arrived' nor |
|
| 917 | 'New SecInfo arrived', method can also be one of 'Start Task', |
|
| 918 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
|
| 919 | method_data: Data that defines the method |
|
| 920 | filter_id: Filter to apply when executing alert |
|
| 921 | comment: Comment for the alert |
|
| 922 | ||
| 923 | Returns: |
|
| 924 | The response. See :py:meth:`send_command` for details. |
|
| 925 | """ |
|
| 926 | ||
| 927 | if not alert_id: |
|
| 928 | raise RequiredArgument( |
|
| 929 | function=self.modify_alert.__name__, argument='alert_id' |
|
| 930 | ) |
|
| 931 | ||
| 932 | cmd = XmlCommand("modify_alert") |
|
| 933 | cmd.set_attribute("alert_id", str(alert_id)) |
|
| 934 | ||
| 935 | if name: |
|
| 936 | cmd.add_element("name", name) |
|
| 937 | ||
| 938 | if comment: |
|
| 939 | cmd.add_element("comment", comment) |
|
| 940 | ||
| 941 | if filter_id: |
|
| 942 | cmd.add_element("filter", attrs={"id": filter_id}) |
|
| 943 | ||
| 944 | if condition: |
|
| 945 | if not isinstance(condition, AlertCondition): |
|
| 946 | raise InvalidArgumentType( |
|
| 947 | function=self.modify_alert.__name__, |
|
| 948 | argument='condition', |
|
| 949 | arg_type=AlertCondition.__name__, |
|
| 950 | ) |
|
| 951 | ||
| 952 | conditions = cmd.add_element("condition", condition.value) |
|
| 953 | ||
| 954 | if condition_data is not None: |
|
| 955 | for key, value in condition_data.items(): |
|
| 956 | _data = conditions.add_element("data", value) |
|
| 957 | _data.add_element("name", key) |
|
| 958 | ||
| 959 | if method: |
|
| 960 | if not isinstance(method, AlertMethod): |
|
| 961 | raise InvalidArgumentType( |
|
| 962 | function=self.modify_alert.__name__, |
|
| 963 | argument='method', |
|
| 964 | arg_type=AlertMethod.__name__, |
|
| 965 | ) |
|
| 966 | ||
| 967 | methods = cmd.add_element("method", method.value) |
|
| 968 | ||
| 969 | if method_data is not None: |
|
| 970 | for key, value in method_data.items(): |
|
| 971 | _data = methods.add_element("data", value) |
|
| 972 | _data.add_element("name", key) |
|
| 973 | ||
| 974 | if event: |
|
| 975 | if not isinstance(event, AlertEvent): |
|
| 976 | raise InvalidArgumentType( |
|
| 977 | function=self.modify_alert.__name__, |
|
| 978 | argument='event', |
|
| 979 | arg_type=AlertEvent.__name__, |
|
| 980 | ) |
|
| 981 | ||
| 982 | _check_event(event, condition, method) |
|
| 983 | ||
| 984 | events = cmd.add_element("event", event.value) |
|
| 985 | ||
| 986 | if event_data is not None: |
|
| 987 | for key, value in event_data.items(): |
|
| 988 | _data = events.add_element("data", value) |
|
| 989 | _data.add_element("name", key) |
|
| 990 | ||
| 991 | return self._send_xml_command(cmd) |
|
| 992 | ||
| 993 | def modify_audit( |
|
| 994 | self, |
|