Package oi.thekraken.grok.api

Examples of oi.thekraken.grok.api.Grok


   */
  private Grok g = Grok.EMPTY;

  @Test
  public void test000_basic() {
    Grok g = new Grok();
    boolean thrown = false;

    // expected exception
    try {
      g.addPatternFromFile("/good/luck");
    } catch (GrokException e) {
      thrown = true;
    }
    assertTrue(thrown);

    thrown = false;

    try {
      g.addPattern(null, "");
    } catch (GrokException e) {
      thrown = true;
    }
    assertTrue(thrown);

    thrown = false;
    try {
      g.copyPatterns(null);
    } catch (GrokException e) {
      thrown = true;
    }
    assertTrue(thrown);

    thrown = false;
    try {
      g.copyPatterns(new HashMap<String, String>());
    } catch (GrokException e) {
      thrown = true;
    }
    assertTrue(thrown);
  }
View Full Code Here


  }

  @Test
  public void test001_static_metod_factory() throws Throwable {

    Grok staticGrok = Grok.create("patterns/patterns", "%{USERNAME}");
    Match gm = staticGrok.match("root");
    gm.captures();
    assertEquals("{USERNAME=root}", gm.toMap().toString());

    gm = staticGrok.match("r00t");
    gm.captures();
    assertEquals("{USERNAME=r00t}", gm.toMap().toString());

    gm = staticGrok.match("guest");
    gm.captures();
    assertEquals("{USERNAME=guest}", gm.toMap().toString());

    gm = staticGrok.match("guest1234");
    gm.captures();
    assertEquals("{USERNAME=guest1234}", gm.toMap().toString());

    gm = staticGrok.match("john doe");
    gm.captures();
    assertEquals("{USERNAME=john}", gm.toMap().toString());
  }
View Full Code Here

  /** FROM HERE WE WILL USE STATIC GROK */

  @Test
  public void test012_day() throws Throwable {

    Grok grok = Grok.create("patterns/patterns", "%{DAY}");

    List<String> days = new ArrayList<String>();
    days.add("Mon");
    days.add("Monday");
    days.add("Tue");
    days.add("Tuesday");
    days.add("Wed");
    days.add("Wednesday");
    days.add("Thu");
    days.add("Thursday");
    days.add("Fri");
    days.add("Friday");
    days.add("Sat");
    days.add("Saturday");
    days.add("Sun");
    days.add("Sunday");

    int i = 0;
    for(String day : days){
      Match m = grok.match(day);
      m.captures();
      assertNotNull(m.toMap());
      assertEquals(m.toMap().get("DAY"), days.get(i));
      i++;
    }
View Full Code Here

    }
  }

  @Test
  public void test013_IpSet() throws Throwable {
    Grok grok = Grok.create("patterns/patterns", "%{IP}");

    BufferedReader br = new BufferedReader(new FileReader("src/test/resources/ip"));
    String line;
    System.out.println("Starting test with ip");
    while ((line = br.readLine()) != null) {
      Match gm = grok.match(line);
      gm.captures();
      assertNotNull(gm.toJson());
      assertNotEquals("{\"Error\":\"Error\"}", gm.toJson());
      assertEquals(gm.toMap().get("IP"), line);
    }
View Full Code Here

  }

  @Test
  public void test014_month() throws Throwable {

    Grok grok = Grok.create("patterns/patterns", "%{MONTH}");

    String[] array = {"Jan", "January", "Feb", "February", "Mar", "March", "Apr", "April", "May", "Jun", "June",
            "Jul", "July", "Aug", "August", "Sep", "September", "Oct", "October", "Nov",
            "November", "Dec", "December"};
    List<String> months = new ArrayList<String>(Arrays.asList(array));
    int i = 0;
    for (String month : months) {
      Match m = grok.match(month);
      m.captures();
      assertNotNull(m.toMap());
      assertEquals(m.toMap().get("MONTH"), months.get(i));
      i++;
    }
View Full Code Here

    }
  }

  @Test
  public void test015_iso8601() throws GrokException{
    Grok grok = Grok.create("patterns/patterns", "%{TIMESTAMP_ISO8601}");

    String[] array =
        {"2001-01-01T00:00:00",
        "1974-03-02T04:09:09",
        "2010-05-03T08:18:18+00:00",
        "2004-07-04T12:27:27-00:00",
        "2001-09-05T16:36:36+0000",
        "2001-11-06T20:45:45-0000",
        "2001-12-07T23:54:54Z",
        "2001-01-01T00:00:00.123456",
        "1974-03-02T04:09:09.123456",
        "2010-05-03T08:18:18.123456+00:00",
        "2004-07-04T12:27:27.123456-00:00",
        "2001-09-05T16:36:36.123456+0000",
        "2001-11-06T20:45:45.123456-0000",
        "2001-12-07T23:54:54.123456Z"};

    List<String> times = new ArrayList<String>(Arrays.asList(array));
    int i = 0;
    for (String time : times) {
      Match m = grok.match(time);
      m.captures();
      assertNotNull(m.toMap());
      assertEquals(m.toMap().get("TIMESTAMP_ISO8601"), times.get(i));
      i++;
    }
View Full Code Here

    }
  }

  @Test
  public void test016_uri() throws GrokException{
    Grok grok = Grok.create("patterns/patterns", "%{URI}");

    String[] array =
        {
            "http://www.google.com",
            "telnet://helloworld",
            "http://www.example.com/",
            "http://www.example.com/test.html",
            "http://www.example.com/test.html?foo=bar",
            "http://www.example.com/test.html?foo=bar&fizzle=baz",
            "http://www.example.com:80/test.html?foo=bar&fizzle=baz",
            "https://www.example.com:443/test.html?foo=bar&fizzle=baz",
            "https://user@www.example.com:443/test.html?foo=bar&fizzle=baz",
            "https://user:pass@somehost/fetch.pl",
            "puppet:///",
            "http://www.foo.com",
            "http://www.foo.com/",
            "http://www.foo.com/?testing",
            "http://www.foo.com/?one=two",
            "http://www.foo.com/?one=two&foo=bar",
            "foo://somehost.com:12345",
            "foo://user@somehost.com:12345",
            "foo://user@somehost.com:12345/",
            "foo://user@somehost.com:12345/foo.bar/baz/fizz",
            "foo://user@somehost.com:12345/foo.bar/baz/fizz?test",
            "foo://user@somehost.com:12345/foo.bar/baz/fizz?test=1&sink&foo=4",
            "http://www.google.com/search?hl=en&source=hp&q=hello+world+%5E%40%23%24&btnG=Google+Search",
            "http://www.freebsd.org/cgi/url.cgi?ports/sysutils/grok/pkg-descr",
            "http://www.google.com/search?q=CAPTCHA+ssh&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official",
            "svn+ssh://somehost:12345/testing"};

    List<String> uris = new ArrayList<String>(Arrays.asList(array));
    int i = 0;
    for (String uri : uris) {
      Match m = grok.match(uri);
      m.captures();
      assertNotNull(m.toMap());
      assertEquals(m.toMap().get("URI"), uris.get(i));
      assertNotNull(m.toMap().get("URIPROTO"));
      i++;
View Full Code Here

    }
  }

  @Test
  public void test017_nonMachingList() throws GrokException {
    Grok grok = Grok.create("patterns/patterns", "%{URI}");

    String[] array =
        {
        "http://www.google.com",
        "telnet://helloworld",
        "",
        "svn+ssh://somehost:12345/testing"
        };
    List<String> uris = new ArrayList<String>(Arrays.asList(array));
    int i = 0;
    for (String uri : uris) {
      Match m = grok.match(uri);
      m.captures();
      assertNotNull(m.toMap());
      if (i == 2) {
        assertEquals(Collections.EMPTY_MAP, m.toMap());
      }
View Full Code Here

TOP

Related Classes of oi.thekraken.grok.api.Grok

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.