Пример #1
0
    def test_append_alert_event_data(self):
        event_data_type = schema.get_type('EventData')
        event_data = event_data_type.create_container({
            'feed_event': 'new',
            'status': None,
            'secinfo_type': 'nvt'
        })
        with_status = event_data_type.create_container({'status': 'Done'})
        empty_data = event_data_type.create_container({})

        self.assertIsNone(
            append_alert_event_data('Task run status changed', empty_data))
        self.assertIsNone(
            append_alert_event_data('Task run status changed', event_data))
        self.assertEqual(
            append_alert_event_data('Task run status changed', with_status),
            {'status': 'Done'},
        )

        self.assertEqual(
            append_alert_event_data('Updated SecInfo arrived', event_data),
            {'secinfo_type': 'nvt'},
        )
        self.assertEqual(
            append_alert_event_data('New SecInfo arrived', event_data),
            {'secinfo_type': 'nvt'},
        )
Пример #2
0
    def mutate(root, info, input_object):
        gmp = get_gmp(info)

        if input_object.event_data is not None:
            event_data = append_alert_event_data(
                input_object.event, input_object.event_data
            )
        else:
            event_data = None

        if input_object.method_data is not None:
            method_data = append_alert_method_data(
                input_object.method,
                input_object.method_data,
                report_formats=input_object.report_formats,
            )
        else:
            method_data = None

        if input_object.condition_data is not None:
            condition_data = append_alert_condition_data(
                input_object.condition, input_object.condition_data
            )
        else:
            condition_data = None

        if input_object.filter_id is not None:
            filter_id = str(input_object.filter_id)
        else:
            filter_id = None

        gmp.modify_alert(
            alert_id=str(input_object.alert_id),
            name=input_object.name,
            condition=get_alert_condition_from_string(input_object.condition),
            event=get_alert_event_from_string(input_object.event),
            method=get_alert_method_from_string(input_object.method),
            comment=input_object.comment,
            method_data=method_data,
            condition_data=condition_data,
            event_data=event_data,
            filter_id=filter_id,
        )

        return ModifyAlert(ok=True)
Пример #3
0
    def mutate(root, info, input_object):
        gmp = get_gmp(info)

        if input_object.event_data is not None:
            event_data = append_alert_event_data(
                input_object.event, input_object.event_data
            )
        else:
            event_data = None

        if input_object.method_data is not None:
            method_data = append_alert_method_data(
                input_object.method,
                input_object.method_data,
                report_formats=input_object.report_formats,
            )
        else:
            method_data = None

        if input_object.condition_data is not None:
            condition_data = append_alert_condition_data(
                input_object.condition, input_object.condition_data
            )
        else:
            condition_data = None

        if input_object.filter_id is not None:
            filter_id = str(input_object.filter_id)
        else:
            filter_id = None

        resp = gmp.create_alert(
            input_object.name,
            get_alert_condition_from_string(input_object.condition),
            get_alert_event_from_string(input_object.event),
            get_alert_method_from_string(input_object.method),
            comment=input_object.comment,
            method_data=method_data,
            condition_data=condition_data,
            event_data=event_data,
            filter_id=filter_id,
        )

        return CreateAlert(alert_id=resp.get('id'))