oi.thekraken.grok.api.Grok.addPattern()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中oi.thekraken.grok.api.Grok.addPattern()方法的一些代码示例,展示了Grok.addPattern()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grok.addPattern()方法的具体详情如下:
包路径:oi.thekraken.grok.api.Grok
类名称:Grok
方法名:addPattern

Grok.addPattern介绍

暂无

代码示例

代码示例来源: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: 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: org.graylog2/graylog2-server

grok.addPattern(grokPattern.name(), grokPattern.pattern());

代码示例来源: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;    }

代码示例来源: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: 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;
}

代码示例来源:origin: com.wavefront/proxy

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: wavefrontHQ/java

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);

相关文章