本文整理了Java中oi.thekraken.grok.api.Grok.compile()
方法的一些代码示例,展示了Grok.compile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grok.compile()
方法的具体详情如下:
包路径:oi.thekraken.grok.api.Grok
类名称:Grok
方法名:compile
暂无
代码示例来源:origin: apache/metron
private void addGrok(String key, String pattern) throws GrokException {
Grok grok = new Grok();
InputStream patternStream = this.getClass().getResourceAsStream("/patterns/asa");
grok.addPatternFromReader(new InputStreamReader(patternStream));
grok.compile("%{" + pattern + "}");
grokers.put(key, grok);
}
代码示例来源: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: 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: apache/metron
@Override
public void init() {
syslogGrok = new Grok();
InputStream syslogStream = this.getClass().getResourceAsStream("/patterns/asa");
try {
syslogGrok.addPatternFromReader(new InputStreamReader(syslogStream));
syslogGrok.compile(syslogPattern);
} catch (GrokException e) {
LOG.error("[Metron] Failed to load grok patterns from jar", e);
throw new RuntimeException(e.getMessage(), e);
}
for (Entry<String, String> pattern : patternMap.entrySet()) {
try {
addGrok(pattern.getKey(), pattern.getValue());
} catch (GrokException e) {
LOG.error("[Metron] Failed to load grok pattern {} for ASA tag {}", pattern.getValue(), pattern.getKey());
}
}
LOG.info("[Metron] CISCO ASA Parser Initialized");
}
代码示例来源: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: 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: 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: OpenSOC/opensoc-streaming
public GrokSourcefireParser(String filepath) throws GrokException
{
grok = Grok.create(filepath);
grok.compile("%{SOURCEFIRE}");
}
代码示例来源:origin: OpenSOC/opensoc-streaming
public GrokSourcefireParser(String filepath, String pattern) throws GrokException
{
grok = Grok.create(filepath);
grok.compile("%{"+pattern+"}");
}
代码示例来源:origin: OpenSOC/opensoc-streaming
public GrokSourcefireParser() throws GrokException
{
URL pattern_url = getClass().getClassLoader().getResource(
"pattarns/sourcefire");
grok = Grok.create(pattern_url.getFile());
grok.compile("%{SOURCEFIRE}");
}
代码示例来源:origin: OpenSOC/opensoc-streaming
public GrokAsaParser(String filepath, String pattern) throws Exception {
grok = Grok.create(filepath);
grok.compile("%{" + pattern + "}");
}
代码示例来源:origin: com.wavefront/proxy
private Grok grok() {
if (grok != null) return grok;
synchronized (grokLock) {
if (grok != null) return grok;
try {
grok = Grok.create(patternsFile);
grok.compile(pattern);
} catch (GrokException e) {
logger.severe("Invalid grok pattern: " + pattern);
throw Throwables.propagate(e);
}
return grok;
}
}
代码示例来源:origin: wavefrontHQ/java
private Grok grok() {
if (grok != null) return grok;
synchronized (grokLock) {
if (grok != null) return grok;
try {
grok = Grok.create(patternsFile);
grok.compile(pattern);
} catch (GrokException e) {
logger.severe("Invalid grok pattern: " + pattern);
throw Throwables.propagate(e);
}
return grok;
}
}
代码示例来源:origin: OpenSOC/opensoc-streaming
private Map<String, Grok> getGrokMap() throws GrokException, IOException {
Map<String, Grok> map = new HashMap<String, Grok>();
for (Map.Entry<String, String> entry : patternMap.entrySet()) {
File file = stream2file(pattern_url);
Grok grok = Grok.create(file.getPath());
grok.compile("%{" + entry.getValue() + "}");
map.put(entry.getValue(), grok);
}
return map;
}
代码示例来源: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: 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: OpenSOC/opensoc-streaming
public GrokAsaParser() throws Exception {
// pattern_url = Resources.getResource("patterns/asa");
pattern_url = getClass().getClassLoader().getResourceAsStream(
"patterns/asa");
File file = stream2file(pattern_url);
grok = Grok.create(file.getPath());
patternMap = getPatternMap();
grokMap = getGrokMap();
grok.compile("%{CISCO_TAGGED_SYSLOG}");
}
代码示例来源: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;
}
}
代码示例来源: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: org.graylog2/graylog2-server
@Override
public boolean validate(GrokPattern pattern) {
final boolean fieldsMissing = !(Strings.isNullOrEmpty(pattern.name()) || Strings.isNullOrEmpty(pattern.pattern()));
try {
final Grok grok = new Grok();
grok.addPattern(pattern.name(), pattern.pattern());
grok.compile("%{" + pattern.name() + "}");
} catch (GrokException ignored) {
// this only checks for null or empty again.
} catch (PatternSyntaxException e) {
LOG.warn("Invalid regular expression syntax for '" + pattern.name() + "' with pattern " + pattern.pattern(), e);
return false;
}
return fieldsMissing; }
内容来源于网络,如有侵权,请联系作者删除!