Search in sources :

Example 1 with Properties

use of loghub.configuration.Properties 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 Properties

use of loghub.configuration.Properties in project LogHub by fbacchella.

the class Nsca method configure.

@Override
public boolean configure(Properties properties) {
    try {
        NagiosSettings settings = new NagiosSettings();
        if (port > 0) {
            settings.setPort(port);
        }
        if (nagiosServer != null) {
            settings.setNagiosHost(nagiosServer);
        }
        if (encryption != null) {
            settings.setEncryption(encryption);
        }
        if (password != null) {
            settings.setPassword(password);
        }
        if (connectTimeout >= 0) {
            settings.setConnectTimeout(connectTimeout);
        }
        if (timeout >= 0) {
            settings.setTimeout(timeout);
        }
        if (largeMessageSupport) {
            settings.enableLargeMessageSupport();
        }
        sender = new NagiosPassiveCheckSender(settings);
        // Uses a map to ensure that each field is tested, for easier debuging
        return MAPFIELD.enumerate().map(i -> {
            if (!mapping.containsKey(i)) {
                logger.error("NSCA mapping field '{}' missing", i);
                return false;
            } else {
                return true;
            }
        }).allMatch(i -> i) && super.configure(properties);
    } catch (IllegalArgumentException e) {
        logger.error("invalid NSCA configuration: {}", e.getMessage());
        return false;
    }
}
Also used : Arrays(java.util.Arrays) MessagePayload(com.googlecode.jsendnsca.MessagePayload) NagiosException(com.googlecode.jsendnsca.NagiosException) NagiosSettings(com.googlecode.jsendnsca.NagiosSettings) IOException(java.io.IOException) HashMap(java.util.HashMap) BlockingQueue(java.util.concurrent.BlockingQueue) NagiosPassiveCheckSender(com.googlecode.jsendnsca.NagiosPassiveCheckSender) Level(com.googlecode.jsendnsca.Level) Stream(java.util.stream.Stream) Encryption(com.googlecode.jsendnsca.encryption.Encryption) Sender(loghub.Sender) Map(java.util.Map) Event(loghub.Event) Properties(loghub.configuration.Properties) NagiosPassiveCheckSender(com.googlecode.jsendnsca.NagiosPassiveCheckSender) NagiosSettings(com.googlecode.jsendnsca.NagiosSettings)

Example 3 with Properties

use of loghub.configuration.Properties in project LogHub by fbacchella.

the class TestFire method test.

@Test
public void test() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("fire.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("count", 2);
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    Event old = conf.mainQueue.remove();
    Event newevent = conf.mainQueue.remove();
    Assert.assertEquals("Not matching old event", old.get("count"), 2);
    Assert.assertEquals("Event not fired", 6, newevent.get("c"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 4 with Properties

use of loghub.configuration.Properties in project LogHub by fbacchella.

the class TestGeoip2 method testProcess.

@Test
public void testProcess() throws ProcessorException {
    Properties props = new Properties(Collections.emptyMap());
    Geoip2 geoip = new Geoip2();
    geoip.setField("ip");
    geoip.setDestination("geoip");
    Geoip2.LocationType[] types = Geoip2.LocationType.values();
    String[] typesNames = new String[types.length];
    for (int i = 0; i < types.length; i++) {
        typesNames[i] = types[i].name().toLowerCase();
    }
    geoip.setTypes(typesNames);
    geoip.setLocale("en");
    geoip.configure(props);
    Event e = Tools.getEvent();
    e.put("ip", "8.8.8.8");
    geoip.process(e);
    @SuppressWarnings("unchecked") Map<Object, Object> geoinfos = (Map<Object, Object>) e.get("geoip");
    assertEquals("not enough elements", 7, geoinfos.size());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Properties

use of loghub.configuration.Properties in project LogHub by fbacchella.

the class TestGrok method TestNoMatch.

@Test
public void TestNoMatch() throws ProcessorException {
    Grok grok = new Grok();
    grok.setFields(new String[] { "host" });
    grok.setPattern("%{HOSTNAME:.}\\.google\\.com");
    Properties props = new Properties(Collections.emptyMap());
    Assert.assertTrue("Failed to configure grok", grok.configure(props));
    Event e = Tools.getEvent();
    e.put("host", "www.yahoo.com");
    Assert.assertFalse(grok.processMessage(e, "host", "host"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Aggregations

Properties (loghub.configuration.Properties)74 Test (org.junit.Test)65 Event (loghub.Event)64 Pipeline (loghub.Pipeline)23 Date (java.util.Date)17 Map (java.util.Map)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)10 Collections (java.util.Collections)7 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)7 Level (org.apache.logging.log4j.Level)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 LogUtils (loghub.LogUtils)6 ProcessorException (loghub.ProcessorException)6 Tools (loghub.Tools)6 Assert (org.junit.Assert)6 BeforeClass (org.junit.BeforeClass)6 ConfigException (loghub.configuration.ConfigException)5 StringReader (java.io.StringReader)4