Code Duplication    Length = 107-107 lines in 2 locations

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 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_tls_certificate(
661
        self,

gvm/protocols/gmpv7/gmpv7.py 1 location

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