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)
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'))
def test_append_alert_method_data(self): method_data_type = schema.get_type('MethodData') method_data = method_data_type.create_container({ 'URL': "foo.bar", 'composer_include_notes': True, 'composer_include_overrides': True, 'defense_center_ip': "123.456.789.0", 'defense_center_port': 8307, 'delta_report_id': "123", 'delta_type': 'previous', 'details_url': None, 'from_address': "*****@*****.**", 'message': "A quick brown fox jumped over the lazy dog.", 'message_attach': "roses are red", 'notice': "2", 'notice_attach_format': "123", 'notice_report_format': "123", 'pkcs12': "MIILrgIBAzCCCy0GCSqGSIb3DQEHA", 'pkcs12_credential': "123", 'recipient_credential': "123", 'scp_host': "localhost", 'scp_known_hosts': "192.168.10.130", 'scp_path': "report.xml", 'scp_report_format': "123", 'scp_credential': "123", 'send_host': "localhost", 'send_port': 8080, 'send_report_format': "123", 'smb_credential': "123", 'smb_file_path': "report.xml", 'smb_share_path': "gvm-reports", 'snmp_agent': "localhost", 'snmp_community': "public", 'snmp_message': "$e", 'start_task_task': "123", 'subject': "[GVM] Task '$n': $e", 'submethod': "syslog", 'to_address': "*****@*****.**", 'tp_sms_hostname': "fluffy", 'tp_sms_tls_workaround': 0, 'verinice_server_credential': "123", 'verinice_server_report_format': "123", 'verinice_server_url': "localhost", }) with_details_url = method_data_type.create_container({ 'URL': "foo.bar", 'composer_include_notes': True, 'composer_include_overrides': True, 'defense_center_ip': "123.456.789.0", 'defense_center_port': 8307, 'delta_report_id': "123", 'delta_type': 'previous', 'details_url': 'http://www.foo.com', 'from_address': "*****@*****.**", 'message': "A quick brown fox jumped over the lazy dog.", 'message_attach': "roses are red", 'notice': "2", 'notice_attach_format': "123", 'notice_report_format': "123", 'pkcs12': "MIILrgIBAzCCCy0GCSqGSIb3DQEHA", 'pkcs12_credential': "123", 'recipient_credential': "123", 'scp_host': "localhost", 'scp_known_hosts': "192.168.10.130", 'scp_path': "report.xml", 'scp_report_format': "123", 'scp_credential': "123", 'send_host': "localhost", 'send_port': 8080, 'send_report_format': "123", 'smb_credential': "123", 'smb_file_path': "report.xml", 'smb_share_path': "gvm-reports", 'snmp_agent': "localhost", 'snmp_community': "public", 'snmp_message': "$e", 'start_task_task': "123", 'subject': "[GVM] Task '$n': $e", 'submethod': "syslog", 'to_address': "*****@*****.**", 'tp_sms_hostname': "fluffy", 'tp_sms_tls_workaround': 0, 'verinice_server_credential': "123", 'verinice_server_report_format': "123", 'verinice_server_url': "localhost", }) empty_data = method_data_type.create_container({}) self.assertIsNone(append_alert_method_data('SMB', empty_data)) self.assertEqual( append_alert_method_data('SMB', method_data), { 'smb_credential': '123', 'smb_file_path': 'report.xml', 'smb_share_path': 'gvm-reports', 'delta_report_id': '123', 'delta_type': 'previous', 'composer_include_notes': 'True', 'composer_include_overrides': 'True', }, ) self.assertEqual( append_alert_method_data('SMB', with_details_url), { 'smb_credential': '123', 'smb_file_path': 'report.xml', 'smb_share_path': 'gvm-reports', 'delta_report_id': '123', 'delta_type': 'previous', 'details_url': 'http://www.foo.com', 'composer_include_notes': 'True', 'composer_include_overrides': 'True', }, )