Search in sources :

Example 1 with GrokCompiler

use of io.krakens.grok.api.GrokCompiler in project graylog2-server by Graylog2.

the class MongoDbGrokPatternService method validateAll.

@Override
public boolean validateAll(Collection<GrokPattern> newPatterns) throws GrokException {
    final Set<GrokPattern> patterns = loadAll();
    final GrokCompiler grokCompiler = GrokCompiler.newInstance();
    for (GrokPattern newPattern : newPatterns) {
        final boolean fieldsMissing = Strings.isNullOrEmpty(newPattern.name()) || Strings.isNullOrEmpty(newPattern.pattern());
        if (fieldsMissing) {
            return false;
        }
        grokCompiler.register(newPattern.name(), newPattern.pattern());
    }
    for (GrokPattern storedPattern : patterns) {
        grokCompiler.register(storedPattern.name(), storedPattern.pattern());
    }
    for (GrokPattern newPattern : newPatterns) {
        grokCompiler.compile("%{" + newPattern.name() + "}");
    }
    return true;
}
Also used : GrokCompiler(io.krakens.grok.api.GrokCompiler)

Example 2 with GrokCompiler

use of io.krakens.grok.api.GrokCompiler in project graylog2-server by Graylog2.

the class MongoDbGrokPatternService method validate.

@Override
public boolean validate(GrokPattern pattern) throws GrokException {
    checkNotNull(pattern, "A pattern must be given");
    final Set<GrokPattern> patterns = loadAll();
    final boolean fieldsMissing = Strings.isNullOrEmpty(pattern.name()) || Strings.isNullOrEmpty(pattern.pattern());
    final GrokCompiler grokCompiler = GrokCompiler.newInstance();
    for (GrokPattern storedPattern : patterns) {
        grokCompiler.register(storedPattern.name(), storedPattern.pattern());
    }
    grokCompiler.register(pattern.name(), pattern.pattern());
    grokCompiler.compile("%{" + pattern.name() + "}");
    return !fieldsMissing;
}
Also used : GrokCompiler(io.krakens.grok.api.GrokCompiler)

Example 3 with GrokCompiler

use of io.krakens.grok.api.GrokCompiler in project graylog2-server by Graylog2.

the class MongoDbGrokPatternService method match.

@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.match(sampleData).captureFlattened();
}
Also used : Grok(io.krakens.grok.api.Grok) GrokCompiler(io.krakens.grok.api.GrokCompiler)

Example 4 with GrokCompiler

use of io.krakens.grok.api.GrokCompiler in project graylog2-server by Graylog2.

the class InMemoryGrokPatternService method validateAll.

@Override
public boolean validateAll(Collection<GrokPattern> newPatterns) throws GrokException {
    final Set<GrokPattern> patterns = loadAll();
    final GrokCompiler grokCompiler = GrokCompiler.newInstance();
    for (GrokPattern newPattern : newPatterns) {
        final boolean fieldsMissing = Strings.isNullOrEmpty(newPattern.name()) || Strings.isNullOrEmpty(newPattern.pattern());
        if (fieldsMissing) {
            return false;
        }
        grokCompiler.register(newPattern.name(), newPattern.pattern());
    }
    for (GrokPattern storedPattern : patterns) {
        grokCompiler.register(storedPattern.name(), storedPattern.pattern());
    }
    for (GrokPattern newPattern : newPatterns) {
        grokCompiler.compile("%{" + newPattern.name() + "}");
    }
    return true;
}
Also used : GrokCompiler(io.krakens.grok.api.GrokCompiler)

Example 5 with GrokCompiler

use of io.krakens.grok.api.GrokCompiler in project graylog2-server by Graylog2.

the class InMemoryGrokPatternService method validate.

@Override
public boolean validate(GrokPattern pattern) throws GrokException {
    final Set<GrokPattern> patterns = loadAll();
    final boolean fieldsMissing = Strings.isNullOrEmpty(pattern.name()) || Strings.isNullOrEmpty(pattern.pattern());
    final GrokCompiler grokCompiler = GrokCompiler.newInstance();
    for (GrokPattern storedPattern : patterns) {
        grokCompiler.register(storedPattern.name(), storedPattern.pattern());
    }
    grokCompiler.register(pattern.name(), pattern.pattern());
    grokCompiler.compile("%{" + pattern.name() + "}");
    return !fieldsMissing;
}
Also used : GrokCompiler(io.krakens.grok.api.GrokCompiler)

Aggregations

GrokCompiler (io.krakens.grok.api.GrokCompiler)7 Grok (io.krakens.grok.api.Grok)3 Match (io.krakens.grok.api.Match)1 GrokException (io.krakens.grok.api.exception.GrokException)1 Map (java.util.Map)1 GrokPattern (org.graylog2.grok.GrokPattern)1 GrokTesterResponse (org.graylog2.rest.resources.tools.responses.GrokTesterResponse)1