Search in sources :

Example 6 with DeserializedEvent

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

the class GenericJsonDeserializerTest method testGetNestedField.

@Test
public void testGetNestedField() throws UnsupportedEncodingException, IOException {
    String input = TestUtils.getResourceString(this.getClass(), "basic.json");
    GenericJsonDeserializer deser = new GenericJsonDeserializer(Collections.emptyList());
    deser.init();
    DeserializedEvent event = deser.deserialize(input);
    assertEquals("bar", event.getField("$.an_obj.foo"));
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) Test(org.junit.Test)

Example 7 with DeserializedEvent

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

the class GenericJsonDeserializerTest method testGetNestedObjField.

@Test(expected = NoSuchElementException.class)
public void testGetNestedObjField() throws UnsupportedEncodingException, IOException {
    String input = TestUtils.getResourceString(this.getClass(), "basic.json");
    GenericJsonDeserializer deser = new GenericJsonDeserializer(Collections.emptyList());
    deser.init();
    DeserializedEvent event = deser.deserialize(input);
    event.getField("$.an_obj");
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) Test(org.junit.Test)

Example 8 with DeserializedEvent

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

the class GenericJsonDeserializerTest method testValidNestedJson.

@Test
public void testValidNestedJson() throws UnsupportedEncodingException, IOException {
    DeserializedEvent devent = getEvent("nested.json");
    JsonObject obj = (JsonObject) devent.getPayload();
    /*
     * Verify MESSAGE was converted to a json object
     */
    assertTrue(obj.has("MESSAGE"));
    assertTrue(obj.get("MESSAGE").isJsonObject());
    /*
     * Check members of MESSAGE object
     */
    JsonObject nested = obj.get("MESSAGE").getAsJsonObject();
    assertTrue(nested.has("a_string"));
    assertTrue(nested.has("an_obj"));
    assertTrue(nested.get("an_obj").isJsonObject());
    /*
     * Verify sub nested json was also converted
     */
    nested = nested.get("an_obj").getAsJsonObject();
    assertTrue(nested.has("a_num"));
    assertEquals(123, nested.get("a_num").getAsInt());
}
Also used : DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 9 with DeserializedEvent

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

the class Re2jRegexDeserializerTest 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);
    Re2jRegexDeserializer deser = new Re2jRegexDeserializer(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(com.google.re2j.Pattern) DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with DeserializedEvent

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

the class Re2jRegexDeserializerTest method testSingleMatch.

@Test
public void testSingleMatch() {
    List<ReFieldConfig> fields = new ArrayList<>();
    fields.add(new ReFieldConfig("foo", ReFieldType.STRING));
    Pattern p = Pattern.compile("(.*)");
    Re2jRegexDeserializer deser = new Re2jRegexDeserializer(p, fields);
    DeserializedEvent event = deser.deserialize("test i am");
    assertEquals("test i am", event.getField("foo"));
}
Also used : Pattern(com.google.re2j.Pattern) DeserializedEvent(com.nextdoor.bender.deserializer.DeserializedEvent) ArrayList(java.util.ArrayList) 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