本文整理了Java中io.krakens.grok.api.Grok
类的一些代码示例,展示了Grok
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grok
类的具体详情如下:
包路径:io.krakens.grok.api.Grok
类名称:Grok
[英]Grok parse arbitrary text and structure it.
Grok is simple API that allows you to easily parse logs and other files (single line). With Grok, you can turn unstructured log and event data into structured data.
[中]Grok解析任意文本并构造它。
Grok是一个简单的API,允许您轻松解析日志和其他文件(单行)。使用Grok,您可以将非结构化日志和事件数据转换为结构化数据。
代码示例来源:origin: Graylog2/graylog2-server
@Override
protected Result[] run(String value) {
// the extractor instance is rebuilt every second anyway
final Match match = grok.match(value);
final Map<String, Object> matches = match.capture();
final List<Result> results = new ArrayList<>(matches.size());
for (final Map.Entry<String, Object> entry : matches.entrySet()) {
// never add null values to the results, those don't make sense for us
if (entry.getValue() != null) {
results.add(new Result(entry.getValue(), entry.getKey(), -1, -1));
}
}
return results.toArray(new Result[0]);
}
}
代码示例来源:origin: apache/nifi
private static void populateSchemaFieldNames(final Grok grok, String grokExpression, final List<RecordField> fields) {
final Set<String> namedGroups = GrokUtils.getNameGroups(GrokUtils.GROK_PATTERN.pattern());
while (grokExpression.length() > 0) {
final Matcher matcher = GrokUtils.GROK_PATTERN.matcher(grokExpression);
if (matcher.find()) {
final Map<String, String> extractedGroups = GrokUtils.namedGroups(matcher, namedGroups);
final String subName = extractedGroups.get("subname");
if (subName == null) {
final String subPatternName = extractedGroups.get("pattern");
if (subPatternName == null) {
continue;
}
final String subExpression = grok.getPatterns().get(subPatternName);
populateSchemaFieldNames(grok, subExpression, fields);
} else {
DataType dataType = RecordFieldType.STRING.getDataType();
final RecordField recordField = new RecordField(subName, dataType);
fields.add(recordField);
}
if (grokExpression.length() > matcher.end() + 1) {
grokExpression = grokExpression.substring(matcher.end());
} else {
break;
}
} else {
break;
}
}
}
代码示例来源: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
Map<String, String> grokPatterns = grok.getPatterns();
grok.setSaved_pattern(key);
groks.put(key, grok);
} catch (Exception e) {
if (this.complexity(value.getNamedRegex()) < 20) {
continue;
Match match = value.match(text);
if (match.isNull()) {
continue;
代码示例来源:origin: vmware/hillview
Set<String> columnsFound = new HashSet<String>();
String currentPattern = grok.getOriginalGrokPattern();
int index = 0;
boolean continueIteration = true;
Map<String, String> patternDefinitions = grok.getPatterns();
Set<String> groups = GrokUtils.getNameGroups(grok.getNamedRegex());
for (String s : groups) {
String name = grok.getNamedRegexCollectionById(s);
if (columnsFound.contains(name))
result.add(name);
代码示例来源:origin: thekrakken/java-grok
@Test
public void test001_captureMathod() {
compiler.register("foo", ".*");
Grok grok = compiler.compile("%{foo}");
Match match = grok.match("Hello World");
assertEquals("(?<name0>.*)", grok.getNamedRegex());
assertEquals("Hello World", match.getSubject());
Map<String, Object> map = match.capture();
assertEquals(1, map.size());
assertEquals("Hello World", map.get("foo"));
assertEquals("{foo=Hello World}", map.toString());
}
代码示例来源:origin: thekrakken/java-grok
public int compare(Grok g1, Grok g2) {
return (this.complexity(g1.getNamedRegex()) < this.complexity(g2.getNamedRegex())) ? 1 : 0;
}
代码示例来源:origin: apache/nifi
static RecordSchema createRecordSchema(final Grok grok) {
final List<RecordField> fields = new ArrayList<>();
String grokExpression = grok.getOriginalGrokPattern();
populateSchemaFieldNames(grok, grokExpression, fields);
fields.add(new RecordField(GrokRecordReader.STACK_TRACE_COLUMN_NAME, RecordFieldType.STRING.getDataType(), true));
fields.add(new RecordField(GrokRecordReader.RAW_MESSAGE_NAME, RecordFieldType.STRING.getDataType(), true));
final RecordSchema schema = new SimpleRecordSchema(fields);
return schema;
}
代码示例来源:origin: thekrakken/java-grok
String id = this.grok.getNamedRegexCollectionById(key);
if (id != null && !id.isEmpty()) {
key = id;
代码示例来源:origin: thekrakken/java-grok
return new Grok(
pattern,
namedRegex,
代码示例来源:origin: io.krakens/java-grok
Map<String, String> grokPatterns = grok.getPatterns();
grok.setSaved_pattern(key);
groks.put(key, grok);
} catch (Exception e) {
if (this.complexity(value.getNamedRegex()) < 20) {
continue;
Match match = value.match(text);
if (match.isNull()) {
continue;
代码示例来源:origin: thekrakken/java-grok
@Test
public void test002_captureMathodMulti() throws GrokException {
compiler.register("foo", ".*");
compiler.register("bar", ".*");
Grok grok = compiler.compile("%{foo} %{bar}");
Match match = grok.match("Hello World");
assertEquals("(?<name0>.*) (?<name1>.*)", grok.getNamedRegex());
assertEquals("Hello World", match.getSubject());
Map<String, Object> map = match.capture();
assertEquals(2, map.size());
assertEquals("Hello", map.get("foo"));
assertEquals("World", map.get("bar"));
assertEquals("{foo=Hello, bar=World}", map.toString());
}
代码示例来源:origin: io.krakens/java-grok
public int compare(Grok g1, Grok g2) {
return (this.complexity(g1.getNamedRegex()) < this.complexity(g2.getNamedRegex())) ? 1 : 0;
}
代码示例来源:origin: thekrakken/java-grok
@Test
public void test003_samePattern() throws GrokException {
String pattern = "Hello World";
Grok grok = compiler.compile(pattern);
assertEquals(pattern, grok.getOriginalGrokPattern());
}
代码示例来源:origin: io.krakens/java-grok
String id = this.grok.getNamedRegexCollectionById(key);
if (id != null && !id.isEmpty()) {
key = id;
代码示例来源:origin: io.krakens/java-grok
return new Grok(
pattern,
namedRegex,
代码示例来源:origin: apache/nifi
final Match match = grok.match(line);
valueMap = match.capture();
final StringBuilder trailingText = new StringBuilder();
while ((nextLine = reader.readLine()) != null) {
final Match nextLineMatch = grok.match(nextLine);
final Map<String, Object> nextValueMap = nextLineMatch.capture();
if (nextValueMap.isEmpty()) {
代码示例来源:origin: thekrakken/java-grok
@Test
public void test003_captureMathodNasted() throws GrokException {
compiler.register("foo", "\\w+ %{bar}");
compiler.register("bar", "\\w+");
Grok grok = compiler.compile("%{foo}");
Match match = grok.match("Hello World");
assertEquals("(?<name0>\\w+ (?<name1>\\w+))", grok.getNamedRegex());
assertEquals("Hello World", match.getSubject());
Map<String, Object> map = match.capture();
assertEquals(2, map.size());
assertEquals("Hello World", map.get("foo"));
assertEquals("World", map.get("bar"));
assertEquals("{foo=Hello World, bar=World}", map.toString());
}
代码示例来源: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
@Test
public void test006_testLoadPatternFromFileIso_8859_1() throws IOException, GrokException {
File temp = tempFolder.newFile("grok-tmp-pattern");
try (FileOutputStream fis = new FileOutputStream(temp);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fis, StandardCharsets.ISO_8859_1))) {
bw.write("TEST §");
}
GrokCompiler compiler = GrokCompiler.newInstance();
compiler.register(new FileInputStream(temp), StandardCharsets.ISO_8859_1);
Grok grok = compiler.compile("%{TEST}");
assertEquals("(?<name0>§)", grok.getNamedRegex());
}
内容来源于网络,如有侵权,请联系作者删除!