Search in sources :

Example 11 with DeserializedEvent

use of com.nextdoor.bender.deserializer.DeserializedEvent in project bender by Nextdoor.

the class Re2jRegexDeserializerTest method testNoMatches.

@Test(expected = DeserializationException.class)
public void testNoMatches() {
    List<ReFieldConfig> fields = new ArrayList<>();
    fields.add(new ReFieldConfig("foo", ReFieldType.STRING));
    Pattern p = Pattern.compile("(test i am)");
    Re2jRegexDeserializer deser = new Re2jRegexDeserializer(p, fields);
    DeserializedEvent event = deser.deserialize("i am a test");
}
Also used : Pattern(com.google.re2j.Pattern) DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with DeserializedEvent

use of com.nextdoor.bender.deserializer.DeserializedEvent in project bender by Nextdoor.

the class RegexDeserializerTest method testTestAlbLog.

@Test
public void testTestAlbLog() {
    List<ReFieldConfig> fields = new ArrayList<>();
    fields.add(new ReFieldConfig("type", ReFieldType.STRING));
    fields.add(new ReFieldConfig("timestamp", ReFieldType.STRING));
    fields.add(new ReFieldConfig("elb", ReFieldType.STRING));
    fields.add(new ReFieldConfig("client_ip", ReFieldType.STRING));
    fields.add(new ReFieldConfig("client_port", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("target_ip", ReFieldType.STRING));
    fields.add(new ReFieldConfig("target_port", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("request_processing_time", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("target_processing_time", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("response_processing_time", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("elb_status_code", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("target_status_code", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("received_bytes", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("sent_bytes", ReFieldType.NUMBER));
    fields.add(new ReFieldConfig("request_verb", ReFieldType.STRING));
    fields.add(new ReFieldConfig("url", ReFieldType.STRING));
    fields.add(new ReFieldConfig("protocol", ReFieldType.STRING));
    fields.add(new ReFieldConfig("user_agent", ReFieldType.STRING));
    fields.add(new ReFieldConfig("ssl_cipher", ReFieldType.STRING));
    fields.add(new ReFieldConfig("ssl_protocol", ReFieldType.STRING));
    fields.add(new ReFieldConfig("target_group_arn", ReFieldType.STRING));
    fields.add(new ReFieldConfig("trace_id", ReFieldType.STRING));
    Pattern p = Pattern.compile("([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*):([0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) (-|[0-9]*) (-|[0-9]*) ([-0-9]*) ([-0-9]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\" (\\\"[^\\\"]*\\\") ([A-Z0-9-]+) ([A-Za-z0-9.-]*) ([^ ]*) ([^ ]*)$", Pattern.DOTALL);
    RegexDeserializer deser = new RegexDeserializer(p, fields);
    DeserializedEvent event = deser.deserialize("https 2017-06-15T04:55:00.142369Z app/foo/1234 127.12.12.12:1337 127.13.13.13:7331 1.001 2.002 3.003 201 200 687 461 \"GET https://foo.com:443/bar/123?baz=1 HTTP/1.1\" \"123-123-123-123-123\" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-west-1:123:targetgroup/foo-bar-https/123 \"Root=1-123-123\"");
    assertEquals("https", event.getField("type"));
    assertEquals("2017-06-15T04:55:00.142369Z", event.getField("timestamp"));
    assertEquals("app/foo/1234", event.getField("elb"));
    assertEquals("127.12.12.12", event.getField("client_ip"));
    assertEquals("1337", event.getField("client_port"));
    assertEquals("127.13.13.13", event.getField("target_ip"));
    assertEquals("7331", event.getField("target_port"));
    assertEquals("1.001", event.getField("request_processing_time"));
    assertEquals("2.002", event.getField("target_processing_time"));
    assertEquals("3.003", event.getField("response_processing_time"));
    assertEquals("201", event.getField("elb_status_code"));
    assertEquals("200", event.getField("target_status_code"));
    assertEquals("687", event.getField("received_bytes"));
    assertEquals("461", event.getField("sent_bytes"));
    assertEquals("GET", event.getField("request_verb"));
    assertEquals("https://foo.com:443/bar/123?baz=1", event.getField("url"));
    assertEquals("HTTP/1.1", event.getField("protocol"));
    assertEquals("\"123-123-123-123-123\"", event.getField("user_agent"));
    assertEquals("ECDHE-RSA-AES128-GCM-SHA256", event.getField("ssl_cipher"));
    assertEquals("TLSv1.2", event.getField("ssl_protocol"));
    assertEquals("arn:aws:elasticloadbalancing:us-west-1:123:targetgroup/foo-bar-https/123", event.getField("target_group_arn"));
    assertEquals("\"Root=1-123-123\"", event.getField("trace_id"));
}
Also used : Pattern(java.util.regex.Pattern) DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with DeserializedEvent

use of com.nextdoor.bender.deserializer.DeserializedEvent in project bender by Nextdoor.

the class RegexDeserializerTest method testNoMatches.

@Test(expected = DeserializationException.class)
public void testNoMatches() {
    List<ReFieldConfig> fields = new ArrayList<>();
    fields.add(new ReFieldConfig("foo", ReFieldType.STRING));
    Pattern p = Pattern.compile("(test i am)");
    RegexDeserializer deser = new RegexDeserializer(p, fields);
    DeserializedEvent event = deser.deserialize("i am a test");
}
Also used : Pattern(java.util.regex.Pattern) DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with DeserializedEvent

use of com.nextdoor.bender.deserializer.DeserializedEvent in project bender by Nextdoor.

the class RegexDeserializerTest method testSingleMatch.

@Test
public void testSingleMatch() {
    List<ReFieldConfig> fields = new ArrayList<>();
    fields.add(new ReFieldConfig("foo", ReFieldType.STRING));
    Pattern p = Pattern.compile("(.*)");
    RegexDeserializer deser = new RegexDeserializer(p, fields);
    DeserializedEvent event = deser.deserialize("test i am");
    assertEquals("test i am", event.getField("foo"));
}
Also used : Pattern(java.util.regex.Pattern) DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with DeserializedEvent

use of com.nextdoor.bender.deserializer.DeserializedEvent in project bender by Nextdoor.

the class GenericJsonDeserializerTest method testSetField.

@Test
public void testSetField() throws UnsupportedEncodingException, IOException {
    DeserializedEvent devent = getEvent("basic.json");
    /*
     * Verify payload type
     */
    assertNotNull(devent.getPayload());
    assertEquals(devent.getPayload().getClass(), JsonObject.class);
    devent.setField("$.new_field", "foo");
    /*
     * Verify payload data
     */
    JsonObject obj = (JsonObject) devent.getPayload();
    assertTrue(obj.has("a_string"));
    assertTrue(obj.get("a_string").isJsonPrimitive());
    assertTrue(obj.get("a_string").getAsJsonPrimitive().isString());
    assertEquals("foo", obj.get("a_string").getAsString());
    assertTrue(obj.has("a_bool"));
    assertTrue(obj.get("a_bool").isJsonPrimitive());
    assertTrue(obj.get("a_bool").getAsJsonPrimitive().isBoolean());
    assertEquals(true, obj.get("a_bool").getAsBoolean());
    assertTrue(obj.has("a_number"));
    assertTrue(obj.get("a_number").isJsonPrimitive());
    assertTrue(obj.get("a_number").getAsJsonPrimitive().isNumber());
    assertEquals(1, obj.get("a_number").getAsInt());
    assertTrue(obj.has("an_obj"));
    assertTrue(obj.get("an_obj").isJsonObject());
    assertTrue(obj.get("an_obj").getAsJsonObject().has("foo"));
    assertTrue(obj.has("new_field"));
    assertTrue(obj.get("new_field").isJsonPrimitive());
    assertTrue(obj.get("new_field").getAsJsonPrimitive().isString());
    assertEquals("foo", obj.get("new_field").getAsString());
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Aggregations

DeserializedEvent (com.nextdoor.bender.deserializer.DeserializedEvent)23 Test (org.junit.Test)20 JsonObject (com.google.gson.JsonObject)11 ArrayList (java.util.ArrayList)7 Pattern (java.util.regex.Pattern)4 Pattern (com.google.re2j.Pattern)3 OperationException (com.nextdoor.bender.operation.OperationException)2 Context (com.amazonaws.services.lambda.runtime.Context)1 AmazonS3URI (com.amazonaws.services.s3.AmazonS3URI)1 JsonElement (com.google.gson.JsonElement)1 InternalEvent (com.nextdoor.bender.InternalEvent)1 AmazonS3ClientFactory (com.nextdoor.bender.aws.AmazonS3ClientFactory)1 BenderConfig (com.nextdoor.bender.config.BenderConfig)1 ConfigurationException (com.nextdoor.bender.config.ConfigurationException)1 HandlerResources (com.nextdoor.bender.config.HandlerResources)1 Source (com.nextdoor.bender.config.Source)1 DeserializerProcessor (com.nextdoor.bender.deserializer.DeserializerProcessor)1 IpcSenderService (com.nextdoor.bender.ipc.IpcSenderService)1 TransportException (com.nextdoor.bender.ipc.TransportException)1 BenderLayout (com.nextdoor.bender.logging.BenderLayout)1