本文整理了Java中oi.thekraken.grok.api.Grok
类的一些代码示例,展示了Grok
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grok
类的具体详情如下:
包路径:oi.thekraken.grok.api.Grok
类名称:Grok
暂无
代码示例来源:origin: spotify/heroic
@JsonCreator
public GrokProcessor(
@JsonProperty("patterns") Map<String, String> patterns,
@JsonProperty("pattern") String pattern
) {
checkNotNull(patterns, "patterns");
checkNotNull(pattern, "pattern");
final Grok grok = new Grok();
try {
for (final Map.Entry<String, String> e : DEFAULT_PATTERNS.entrySet()) {
grok.addPattern(e.getKey(), e.getValue());
}
for (final Map.Entry<String, String> e : patterns.entrySet()) {
grok.addPattern(e.getKey(), e.getValue());
}
grok.compile(pattern);
} catch (final Exception e) {
throw new RuntimeException(e);
}
this.instance = grok;
}
代码示例来源:origin: spotify/heroic
public Map<String, Object> parse(final String input) {
final Match m = instance.match(input);
if (m == Match.EMPTY) {
return ImmutableMap.of();
}
m.captures();
return m.toMap();
}
}
代码示例来源:origin: apache/metron
private static Grok getGrok(String grokExpr) throws GrokException {
Grok grok = new Grok();
InputStream input = GrokFunctions.class.getResourceAsStream("/patterns/common");
if(input != null) {
grok.addPatternFromReader(new InputStreamReader(input));
}
if(grokExpr != null) {
grok.addPatternFromReader(new StringReader("pattern " + grokExpr));
grok.compile("%{pattern}");
}
return grok;
}
代码示例来源:origin: apache/metron
@Bean
public Grok commonGrok() throws GrokException {
Grok grok = new Grok();
grok.addPatternFromReader(new InputStreamReader(getClass().getResourceAsStream(
"/patterns/common")));
return grok;
}
}
代码示例来源:origin: OpenSOC/opensoc-streaming
public GrokAsaParser(String filepath) throws Exception {
grok = Grok.create(filepath);
// grok.getNamedRegexCollection().put("ciscotag","CISCOFW302013_302014_302015_302016");
grok.compile("%{CISCO_TAGGED_SYSLOG}");
}
代码示例来源:origin: apache/metron
@Override
public GrokValidation validateGrokStatement(GrokValidation grokValidation) throws RestException {
Map<String, Object> results;
try {
if (grokValidation.getPatternLabel() == null) {
throw new RestException("Pattern label is required");
}
if (Strings.isEmpty(grokValidation.getStatement())) {
throw new RestException("Grok statement is required");
}
Grok grok = new Grok();
grok.addPatternFromReader(new InputStreamReader(getClass().getResourceAsStream(
"/patterns/common")));
grok.addPatternFromReader(new StringReader(grokValidation.getStatement()));
String grokPattern = "%{" + grokValidation.getPatternLabel() + "}";
grok.compile(grokPattern);
Match gm = grok.match(grokValidation.getSampleData());
gm.captures();
results = gm.toMap();
results.remove(grokValidation.getPatternLabel());
} catch (Exception e) {
throw new RestException(e);
}
grokValidation.setResults(results);
return grokValidation;
}
代码示例来源:origin: org.graylog2/graylog2-server
private GrokTesterResponse doTestGrok(String string, String pattern, boolean namedCapturesOnly) throws GrokException {
final Set<GrokPattern> grokPatterns = grokPatternService.loadAll();
final Grok grok = new Grok();
for (GrokPattern grokPattern : grokPatterns) {
grok.addPattern(grokPattern.name(), grokPattern.pattern());
}
grok.compile(pattern, namedCapturesOnly);
final Match match = grok.match(string);
match.captures();
final Map<String, Object> matches = match.toMap();
final GrokTesterResponse response;
if (matches.isEmpty()) {
response = GrokTesterResponse.create(false, Collections.<GrokTesterResponse.Match>emptyList(), pattern, string);
} else {
final List<GrokTesterResponse.Match> responseMatches = Lists.newArrayList();
for (final Map.Entry<String, Object> entry : matches.entrySet()) {
final Object value = entry.getValue();
if (value != null) {
responseMatches.add(GrokTesterResponse.Match.create(entry.getKey(), value.toString()));
}
}
response = GrokTesterResponse.create(true, responseMatches, pattern, string);
}
return response;
}
}
代码示例来源:origin: apache/metron
@Override
public void init() {
grok = new Grok();
try {
InputStream commonInputStream = openInputStream(patternsCommonDir);
LOG.debug("Grok parser loading common patterns from: {}", patternsCommonDir);
if (commonInputStream == null) {
throw new RuntimeException(
"Unable to initialize grok parser: Unable to load " + patternsCommonDir + " from either classpath or HDFS");
}
grok.addPatternFromReader(new InputStreamReader(commonInputStream));
LOG.debug("Loading parser-specific patterns from: {}", grokPath);
InputStream patterInputStream = openInputStream(grokPath);
if (patterInputStream == null) {
throw new RuntimeException("Grok parser unable to initialize grok parser: Unable to load " + grokPath
+ " from either classpath or HDFS");
}
grok.addPatternFromReader(new InputStreamReader(patterInputStream));
if (LOG.isDebugEnabled()) {
LOG.debug("Grok parser set the following grok expression: {}", grok.getNamedRegexCollectionById(patternLabel));
}
String grokPattern = "%{" + patternLabel + "}";
grok.compile(grokPattern);
LOG.debug("Compiled grok pattern {}", grokPattern);
} catch (Throwable e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException("Grok parser Error: " + e.getMessage(), e);
}
}
代码示例来源:origin: stackoverflow.com
Grok grok = Grok.create("pat.txt");
// compile and add semantic
grok.compile("%{NUMBER:hits} %{USER:word}");
String str = "234 wdfd\n";
Match m = grok.match(str);
m.captures();
// Print
System.out.println(m.toJson());
// Here you dont need to create a new instance of grok [grok = Grok.EMPTY;]
str = "ssdfsdf\n";
// here you can reuse the matcher if you want.
Match m2 = grok.match(str);
m2.captures();
System.out.println(m2.toJson());
代码示例来源:origin: caskdata/cdap
@Override
protected void configure(Map<String, String> settings) {
addPatterns(grok);
try {
this.pattern = determinePattern(settings);
grok.compile(pattern);
} catch (GrokException e) {
LOG.error("Failed to compile grok pattern '{}'", pattern, e);
}
}
代码示例来源:origin: com.wavefront/proxy
@Override
public void verifyAndInit() throws ConfigurationException {
Grok grok = new Grok();
for (String pattern : additionalPatterns) {
String[] parts = pattern.split(" ");
String regex = String.join(" ", Arrays.copyOfRange(parts, 1, parts.length));
try {
grok.addPattern(name, regex);
} catch (GrokException e) {
throw new ConfigurationException("bad grok pattern: " + pattern);
代码示例来源:origin: org.graylog2/graylog2-server
grok.addPattern(grokPattern.name(), grokPattern.pattern());
grok.compile((String) extractorConfig.get("grok_pattern"), namedCapturesOnly);
} catch (GrokException e) {
log.error("Unable to parse grok patterns", e);
代码示例来源:origin: stackoverflow.com
public Grok[] generateMoreGroks() {
return new Grok[] {
new Grok(), new Grok(), new Grok() };
}
代码示例来源:origin: co.cask.cdap/cdap-formats
protected void addPattern(Grok grok, String resource) {
URL url = this.getClass().getClassLoader().getResource(resource);
if (url == null) {
LOG.error("Resource '{}' for grok pattern was not found", resource);
return;
}
try {
String patternFile = Resources.toString(url, Charsets.UTF_8);
try {
grok.addPatternFromReader(new StringReader(patternFile));
} catch (GrokException e) {
LOG.error("Invalid grok pattern from resource '{}'", resource, e);
}
} catch (IOException e) {
LOG.error("Failed to load resource '{}' for grok pattern", resource, e);
}
}
代码示例来源:origin: OpenSOC/opensoc-streaming
public GrokSourcefireParser(String filepath) throws GrokException
{
grok = Grok.create(filepath);
grok.compile("%{SOURCEFIRE}");
}
代码示例来源:origin: co.cask.cdap/cdap-formats
@Override
protected void configure(Map<String, String> settings) {
addPatterns(grok);
try {
this.pattern = determinePattern(settings);
grok.compile(pattern);
} catch (GrokException e) {
LOG.error("Failed to compile grok pattern '{}'", pattern, e);
}
}
代码示例来源:origin: wavefrontHQ/java
@Override
public void verifyAndInit() throws ConfigurationException {
Grok grok = new Grok();
for (String pattern : additionalPatterns) {
String[] parts = pattern.split(" ");
String regex = String.join(" ", Arrays.copyOfRange(parts, 1, parts.length));
try {
grok.addPattern(name, regex);
} catch (GrokException e) {
throw new ConfigurationException("bad grok pattern: " + pattern);
代码示例来源:origin: caskdata/cdap
protected void addPattern(Grok grok, String resource) {
URL url = this.getClass().getClassLoader().getResource(resource);
if (url == null) {
LOG.error("Resource '{}' for grok pattern was not found", resource);
return;
}
try {
String patternFile = Resources.toString(url, Charsets.UTF_8);
try {
grok.addPatternFromReader(new StringReader(patternFile));
} catch (GrokException e) {
LOG.error("Invalid grok pattern from resource '{}'", resource, e);
}
} catch (IOException e) {
LOG.error("Failed to load resource '{}' for grok pattern", resource, e);
}
}
代码示例来源:origin: OpenSOC/opensoc-streaming
public GrokSourcefireParser(String filepath, String pattern) throws GrokException
{
grok = Grok.create(filepath);
grok.compile("%{"+pattern+"}");
}
代码示例来源:origin: org.graylog2/graylog2-server
@Override
public Grok load(@Nonnull String pattern) throws Exception {
final Grok grok = new Grok();
for (GrokPattern grokPattern : patterns()) {
grok.addPattern(grokPattern.name(), grokPattern.pattern());
}
grok.compile(pattern, namedCapturesOnly);
return grok;
}
}
内容来源于网络,如有侵权,请联系作者删除!