Search in sources :

Example 1 with GrokException

use of oi.thekraken.grok.api.exception.GrokException in project graylog2-server by Graylog2.

the class InMemoryGrokPatternService method validate.

@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;
}
Also used : Grok(oi.thekraken.grok.api.Grok) GrokException(oi.thekraken.grok.api.exception.GrokException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with GrokException

use of oi.thekraken.grok.api.exception.GrokException in project graylog2-server by Graylog2.

the class MongoDbGrokPatternService method validate.

@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;
}
Also used : Grok(oi.thekraken.grok.api.Grok) GrokException(oi.thekraken.grok.api.exception.GrokException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

PatternSyntaxException (java.util.regex.PatternSyntaxException)2 Grok (oi.thekraken.grok.api.Grok)2 GrokException (oi.thekraken.grok.api.exception.GrokException)2