Package oi.thekraken.grok.api

Examples of oi.thekraken.grok.api.Grok


    logs.add("43.131.249.156");
    logs.add("170.36.40.12");
    logs.add("124.2.84.36");
   
   
    Grok grok = Grok.create("patterns/patterns", "%{IP}");
    List<String> json = grok.captures(logs);
    assertNotNull(json);
    int i = 0;
    for(String elem : json){
      assertNotNull(elem);
      assertEquals(elem, grok.capture(logs.get(i)));
      i++;
      //assert
    }
   
  }
View Full Code Here


    logs.add("43.131.249.156");
    logs.add("170.36.40.12");
    logs.add("124.2.84.36");
   
   
    Grok grok = Grok.create("patterns/patterns", "%{IP}");
    List<String> json = grok.captures(logs);
    assertNotNull(json);
    int i = 0;
    for(String elem : json){
      System.out.println(elem);
      assertNotNull(elem);
      assertEquals(elem, grok.capture(logs.get(i)));
      i++;
      //assert
    }
   
  }
View Full Code Here

public class BasicTest {

  @Test
  public void test001_compileFailOnInvalidExpression() throws GrokException {

    Grok g = Grok.create("patterns/patterns", null);

    List<String> badRegxp = new ArrayList<String>();
    badRegxp.add("[");
    badRegxp.add("[foo");
    badRegxp.add("?");
    badRegxp.add("foo????");
    badRegxp.add("(?-");

    boolean thrown = false;

    /** This should always throw */
    for (String regx : badRegxp) {
      try {
        g.compile(regx);
      } catch (PatternSyntaxException e) {
        thrown = true;
      }
      assertTrue(thrown);
      thrown = false;
View Full Code Here

  }

  @Test
  public void test002_compileSuccessValidExpression() throws GrokException {

    Grok g = Grok.create("patterns/patterns");

    List<String> regxp = new ArrayList<String>();
    regxp.add("[hello]");
    regxp.add("(test)");
    regxp.add("(?:hello)");
    regxp.add("(?=testing)");

    for (String regx : regxp) {
      g.compile(regx);
    }
  }
View Full Code Here

    }
  }

  @Test
  public void test003_samePattern() throws GrokException {
    Grok g = Grok.create("patterns/patterns");

    String pattern = "Hello World";
    g.compile(pattern);
    assertEquals(pattern, g.getOriginalGrokPattern());
  }
View Full Code Here

    assertEquals(pattern, g.getOriginalGrokPattern());
  }

  @Test
  public void test004_sameExpantedPatern() throws GrokException {
    Grok g = Grok.create("patterns/patterns");

    g.addPattern("test", "hello world");
    g.compile("%{test}");
    assertEquals("(?<name0>hello world)", g.getNamedRegex());
  }
View Full Code Here

    File temp = File.createTempFile("grok-tmp-pattern", ".tmp");getClass();
    BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
    bw.write("TEST \\d+");
    bw.close();

    Grok grok = Grok.create(temp.getAbsolutePath());
    grok.compile("%{TEST}");
    assertEquals("(?<name0>\\d+)", grok.getNamedRegex());
    temp.delete();
  }
View Full Code Here

  public final static String LOG_FILE = "src/test/resources/message/messages";

  @Test
  public void test001_linux_messages() throws GrokException, IOException {
    Grok g = new Grok();
    g.addPatternFromFile("patterns/patterns");
    g.compile("%{MESSAGESLOG}");

    BufferedReader br = new BufferedReader(new FileReader(LOG_FILE));
    String line;
    System.out.println("Starting test with linux messages log -- may take a while");
    while ((line = br.readLine()) != null) {
      Match gm = g.match(line);
      gm.captures();
      assertNotNull(gm.toJson());
      assertNotEquals("{\"Error\":\"Error\"}", gm.toJson());
    }
    br.close();
View Full Code Here

  public final static String LOG_FILE = "src/test/resources/access_log";
  public final static String LOG_DIR_NASA = "src/test/resources/nasa/";

  @Test
  public void test001_httpd_access() throws GrokException, IOException {
    Grok g = Grok.create("patterns/patterns", "%{COMMONAPACHELOG}");

    BufferedReader br = new BufferedReader(new FileReader(LOG_FILE));
    String line;
    System.out.println("Starting test with httpd log");
    while ((line = br.readLine()) != null) {
      //System.out.println(line);
      Match gm = g.match(line);
      gm.captures();
      assertNotNull(gm.toJson());
      assertNotEquals("{\"Error\":\"Error\"}", gm.toJson());
    }
    br.close();
View Full Code Here

    br.close();
  }

  @Test
  public void test002_nasa_httpd_access() throws GrokException, IOException {
    Grok g = Grok.create("patterns/patterns", "%{COMMONAPACHELOG}");
    System.out.println("Starting test with nasa log -- may take a while");
    BufferedReader br;
    String line;
    File dir = new File(LOG_DIR_NASA);
    for (File child : dir.listFiles()) {
      br = new BufferedReader(new FileReader(LOG_DIR_NASA + child.getName()));
      while ((line = br.readLine()) != null) {
        //System.out.println(child.getName() + " " +line);
        Match gm = g.match(line);
        gm.captures();
        assertNotNull(gm.toJson());
        assertNotEquals("{\"Error\":\"Error\"}", gm.toJson());
      }
      br.close();
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.