Code Duplication    Length = 107-107 lines in 3 locations

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 4435-4541 (lines=107) @@
4432
4433
        return self._send_xml_command(cmd)
4434
4435
    def modify_alert(
4436
        self,
4437
        alert_id: str,
4438
        *,
4439
        name: Optional[str] = None,
4440
        comment: Optional[str] = None,
4441
        filter_id: Optional[str] = None,
4442
        event: Optional[AlertEvent] = None,
4443
        event_data: Optional[dict] = None,
4444
        condition: Optional[AlertCondition] = None,
4445
        condition_data: Optional[dict] = None,
4446
        method: Optional[AlertMethod] = None,
4447
        method_data: Optional[dict] = None,
4448
    ) -> Any:
4449
        """Modifies an existing alert.
4450
4451
        Arguments:
4452
            alert_id: UUID of the alert to be modified.
4453
            name: Name of the Alert.
4454
            condition: The condition that must be satisfied for the alert to
4455
                occur. If the event is either 'Updated SecInfo
4456
                arrived' or 'New SecInfo arrived', condition must be 'Always'.
4457
                Otherwise, condition can also be on of 'Severity at least',
4458
                'Filter count changed' or 'Filter count at least'.
4459
            condition_data: Data that defines the condition
4460
            event: The event that must happen for the alert to occur, one of
4461
                'Task run status changed', 'Updated SecInfo arrived' or
4462
                'New SecInfo arrived'
4463
            event_data: Data that defines the event
4464
            method: The method by which the user is alerted, one of 'SCP',
4465
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email';
4466
                if the event is neither 'Updated SecInfo arrived' nor
4467
                'New SecInfo arrived', method can also be one of 'Start Task',
4468
                'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'.
4469
            method_data: Data that defines the method
4470
            filter_id: Filter to apply when executing alert
4471
            comment: Comment for the alert
4472
4473
        Returns:
4474
            The response. See :py:meth:`send_command` for details.
4475
        """
4476
4477
        if not alert_id:
4478
            raise RequiredArgument(
4479
                function=self.modify_alert.__name__, argument='alert_id'
4480
            )
4481
4482
        cmd = XmlCommand("modify_alert")
4483
        cmd.set_attribute("alert_id", str(alert_id))
4484
4485
        if name:
4486
            cmd.add_element("name", name)
4487
4488
        if comment:
4489
            cmd.add_element("comment", comment)
4490
4491
        if filter_id:
4492
            cmd.add_element("filter", attrs={"id": filter_id})
4493
4494
        if condition:
4495
            if not isinstance(condition, AlertCondition):
4496
                raise InvalidArgumentType(
4497
                    function=self.modify_alert.__name__,
4498
                    argument='condition',
4499
                    arg_type=AlertCondition.__name__,
4500
                )
4501
4502
            conditions = cmd.add_element("condition", condition.value)
4503
4504
            if condition_data is not None:
4505
                for key, value in condition_data.items():
4506
                    _data = conditions.add_element("data", value)
4507
                    _data.add_element("name", key)
4508
4509
        if method:
4510
            if not isinstance(method, AlertMethod):
4511
                raise InvalidArgumentType(
4512
                    function=self.modify_alert.__name__,
4513
                    argument='method',
4514
                    arg_type=AlertMethod.__name__,
4515
                )
4516
4517
            methods = cmd.add_element("method", method.value)
4518
4519
            if method_data is not None:
4520
                for key, value in method_data.items():
4521
                    _data = methods.add_element("data", value)
4522
                    _data.add_element("name", key)
4523
4524
        if event:
4525
            if not isinstance(event, AlertEvent):
4526
                raise InvalidArgumentType(
4527
                    function=self.modify_alert.__name__,
4528
                    argument='event',
4529
                    arg_type=AlertEvent.__name__,
4530
                )
4531
4532
            _check_event(event, condition, method)
4533
4534
            events = cmd.add_element("event", event.value)
4535
4536
            if event_data is not None:
4537
                for key, value in event_data.items():
4538
                    _data = events.add_element("data", value)
4539
                    _data.add_element("name", key)
4540
4541
        return self._send_xml_command(cmd)
4542
4543
    def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any:
4544
        """Modifies an existing asset.

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 1014-1120 (lines=107) @@
1011
1012
        return self._send_xml_command(cmd)
1013
1014
    def modify_alert(
1015
        self,
1016
        alert_id: str,
1017
        *,
1018
        name: Optional[str] = None,
1019
        comment: Optional[str] = None,
1020
        filter_id: Optional[str] = None,
1021
        event: Optional[AlertEvent] = None,
1022
        event_data: Optional[dict] = None,
1023
        condition: Optional[AlertCondition] = None,
1024
        condition_data: Optional[dict] = None,
1025
        method: Optional[AlertMethod] = None,
1026
        method_data: Optional[dict] = None,
1027
    ) -> Any:
1028
        """Modifies an existing alert.
1029
1030
        Arguments:
1031
            alert_id: UUID of the alert to be modified.
1032
            name: Name of the Alert.
1033
            condition: The condition that must be satisfied for the alert to
1034
                occur. If the event is either 'Updated SecInfo
1035
                arrived' or 'New SecInfo arrived', condition must be 'Always'.
1036
                Otherwise, condition can also be on of 'Severity at least',
1037
                'Filter count changed' or 'Filter count at least'.
1038
            condition_data: Data that defines the condition
1039
            event: The event that must happen for the alert to occur, one of
1040
                'Task run status changed', 'Updated SecInfo arrived' or
1041
                'New SecInfo arrived'
1042
            event_data: Data that defines the event
1043
            method: The method by which the user is alerted, one of 'SCP',
1044
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email';
1045
                if the event is neither 'Updated SecInfo arrived' nor
1046
                'New SecInfo arrived', method can also be one of 'Start Task',
1047
                'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'.
1048
            method_data: Data that defines the method
1049
            filter_id: Filter to apply when executing alert
1050
            comment: Comment for the alert
1051
1052
        Returns:
1053
            The response. See :py:meth:`send_command` for details.
1054
        """
1055
1056
        if not alert_id:
1057
            raise RequiredArgument(
1058
                function=self.modify_alert.__name__, argument='alert_id'
1059
            )
1060
1061
        cmd = XmlCommand("modify_alert")
1062
        cmd.set_attribute("alert_id", str(alert_id))
1063
1064
        if name:
1065
            cmd.add_element("name", name)
1066
1067
        if comment:
1068
            cmd.add_element("comment", comment)
1069
1070
        if filter_id:
1071
            cmd.add_element("filter", attrs={"id": filter_id})
1072
1073
        if condition:
1074
            if not isinstance(condition, AlertCondition):
1075
                raise InvalidArgumentType(
1076
                    function=self.modify_alert.__name__,
1077
                    argument='condition',
1078
                    arg_type=AlertCondition.__name__,
1079
                )
1080
1081
            conditions = cmd.add_element("condition", condition.value)
1082
1083
            if condition_data is not None:
1084
                for key, value in condition_data.items():
1085
                    _data = conditions.add_element("data", value)
1086
                    _data.add_element("name", key)
1087
1088
        if method:
1089
            if not isinstance(method, AlertMethod):
1090
                raise InvalidArgumentType(
1091
                    function=self.modify_alert.__name__,
1092
                    argument='method',
1093
                    arg_type=AlertMethod.__name__,
1094
                )
1095
1096
            methods = cmd.add_element("method", method.value)
1097
1098
            if method_data is not None:
1099
                for key, value in method_data.items():
1100
                    _data = methods.add_element("data", value)
1101
                    _data.add_element("name", key)
1102
1103
        if event:
1104
            if not isinstance(event, AlertEvent):
1105
                raise InvalidArgumentType(
1106
                    function=self.modify_alert.__name__,
1107
                    argument='event',
1108
                    arg_type=AlertEvent.__name__,
1109
                )
1110
1111
            _check_event(event, condition, method)
1112
1113
            events = cmd.add_element("event", event.value)
1114
1115
            if event_data is not None:
1116
                for key, value in event_data.items():
1117
                    _data = events.add_element("data", value)
1118
                    _data.add_element("name", key)
1119
1120
        return self._send_xml_command(cmd)
1121
1122
    def modify_audit(
1123
        self,

gvm/protocols/gmpv9/gmpv9.py 1 location

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