本文整理了Java中io.krakens.grok.api.Grok.capture()
方法的一些代码示例,展示了Grok.capture()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grok.capture()
方法的具体详情如下:
包路径:io.krakens.grok.api.Grok
类名称:Grok
方法名:capture
[英]Match the given log with the named regex. And return the json representation of the matched element
[中]将给定日志与命名的正则表达式匹配。并返回匹配元素的json表示形式
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Map<String, Object> match(GrokPattern pattern, String sampleData) throws GrokException {
final Set<GrokPattern> patterns = loadAll();
final GrokCompiler grokCompiler = GrokCompiler.newInstance();
for (GrokPattern storedPattern : patterns) {
grokCompiler.register(storedPattern.name(), storedPattern.pattern());
}
grokCompiler.register(pattern.name(), pattern.pattern());
Grok grok = grokCompiler.compile("%{" + pattern.name() + "}");
return grok.capture(sampleData);
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Map<String, Object> match(GrokPattern pattern, String sampleData) throws GrokException {
final Set<GrokPattern> patterns = loadAll();
final GrokCompiler grokCompiler = GrokCompiler.newInstance();
for(GrokPattern storedPattern : patterns) {
grokCompiler.register(storedPattern.name(), storedPattern.pattern());
}
grokCompiler.register(pattern.name(), pattern.pattern());
Grok grok = grokCompiler.compile("%{" + pattern.name() + "}");
return grok.capture(sampleData);
}
代码示例来源:origin: thekrakken/java-grok
/**
* Match the given list of <tt>log</tt> with the named regex
* and return the list of json representation of the matched elements.
*
* @param logs : list of log
* @return list of maps containing matches
*/
public ArrayList<Map<String, Object>> capture(List<String> logs) {
final ArrayList<Map<String, Object>> matched = new ArrayList<>();
for (String log : logs) {
matched.add(capture(log));
}
return matched;
}
代码示例来源:origin: io.krakens/java-grok
/**
* Match the given list of <tt>log</tt> with the named regex
* and return the list of json representation of the matched elements.
*
* @param logs : list of log
* @return list of maps containing matches
*/
public ArrayList<Map<String, Object>> capture(List<String> logs) {
final ArrayList<Map<String, Object>> matched = new ArrayList<>();
for (String log : logs) {
matched.add(capture(log));
}
return matched;
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test_001() throws GrokException {
List<String> logs = new ArrayList<>();
logs.add("178.21.82.201");
logs.add("11.178.94.216");
logs.add("238.222.236.81");
logs.add("231.49.38.155");
logs.add("206.0.116.17");
logs.add("191.199.247.47");
logs.add("43.131.249.156");
logs.add("170.36.40.12");
logs.add("124.2.84.36");
Grok grok = compiler.compile("%{IP}");
ArrayList<Map<String, Object>> capture = grok.capture(logs);
assertNotNull(capture);
int counter = 0;
for (Map<String, Object> elem : capture) {
assertNotNull(elem);
assertEquals(elem, grok.capture(logs.get(counter)));
counter++;
}
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test_002() throws GrokException {
List<String> logs = new ArrayList<>();
logs.add("178.21.82.201");
logs.add("11.178.94.216");
logs.add("");
logs.add("231.49.38.155");
logs.add("206.0.116.17");
logs.add("191.199.247.47");
logs.add("43.131.249.156");
logs.add("170.36.40.12");
logs.add("124.2.84.36");
Grok grok = compiler.compile("%{IP}");
ArrayList<Map<String, Object>> capture = grok.capture(logs);
assertNotNull(capture);
int counter = 0;
for (Map<String, Object> elem : capture) {
assertNotNull(elem);
assertEquals(elem, grok.capture(logs.get(counter)));
counter++;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!