Search in sources :

Example 1 with GrokException

use of io.thekraken.grok.api.exception.GrokException in project LogHub by fbacchella.

the class Grok method configure.

@Override
public boolean configure(Properties properties) {
    Helpers.ThrowingConsumer<InputStream> grokloader = is -> grok.addPatternFromReader(new InputStreamReader(new BufferedInputStream(is)));
    try {
        Helpers.readRessources(properties.classloader, PATTERNSFOLDER, grokloader);
        customPatterns.forEach((k, v) -> {
            try {
                grok.addPattern(k.toString(), v.toString());
            } catch (GrokException e) {
                logger.warn("invalid grok pattern {}: {}", k, v);
            }
        });
        // Switch to true when  https://github.com/thekrakken/java-grok/issues/61 is fixed
        grok.compile(pattern, false);
    } catch (IOException | URISyntaxException e) {
        logger.error("unable to load patterns: {}", e.getMessage());
        logger.catching(Level.DEBUG, e);
        return false;
    } catch (GrokException | PatternSyntaxException e) {
        logger.error("wrong pattern {}: {}", pattern, e.getMessage());
        logger.catching(Level.DEBUG, e);
        return false;
    }
    return super.configure(properties);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) PatternSyntaxException(java.util.regex.PatternSyntaxException) GrokException(io.thekraken.grok.api.exception.GrokException) URISyntaxException(java.net.URISyntaxException) Level(org.apache.logging.log4j.Level) Match(io.thekraken.grok.api.Match) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) List(java.util.List) Helpers(loghub.Helpers) Map(java.util.Map) Collections(java.util.Collections) Event(loghub.Event) InputStream(java.io.InputStream) Properties(loghub.configuration.Properties) InputStreamReader(java.io.InputStreamReader) Helpers(loghub.Helpers) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) GrokException(io.thekraken.grok.api.exception.GrokException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with GrokException

use of io.thekraken.grok.api.exception.GrokException in project incubator-gobblin by apache.

the class GrokToJsonConverter method init.

@Override
public Converter<String, JsonArray, String, JsonObject> init(WorkUnitState workUnit) {
    super.init(workUnit);
    String pattern = workUnit.getProp(GROK_PATTERN);
    String patternsFile = workUnit.getProp(BASE_PATTERNS_FILE);
    this.nullStringRegexes = DatasetFilterUtils.getPatternsFromStrings(workUnit.getPropAsList(NULLSTRING_REGEXES, ""));
    InputStreamReader grokPatterns;
    try {
        if (patternsFile == null) {
            grokPatterns = new InputStreamReader(getClass().getResourceAsStream("/grok/grok-base-patterns"), "UTF8");
        } else {
            grokPatterns = new InputStreamReader(new FileInputStream(patternsFile), "UTF8");
        }
        grok = new Grok();
        grok.addPatternFromReader(grokPatterns);
        grok.compile(pattern);
    } catch (GrokException | FileNotFoundException | UnsupportedEncodingException e) {
        throw new RuntimeException("Error initializing GROK: " + e);
    }
    return this;
}
Also used : InputStreamReader(java.io.InputStreamReader) Grok(io.thekraken.grok.api.Grok) GrokException(io.thekraken.grok.api.exception.GrokException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileInputStream(java.io.FileInputStream)

Aggregations

GrokException (io.thekraken.grok.api.exception.GrokException)2 InputStreamReader (java.io.InputStreamReader)2 Grok (io.thekraken.grok.api.Grok)1 Match (io.thekraken.grok.api.Match)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Event (loghub.Event)1 Helpers (loghub.Helpers)1 Properties (loghub.configuration.Properties)1 Level (org.apache.logging.log4j.Level)1