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

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 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.