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);
}
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;
}
}
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"));
}
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());
}
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"));
}
Aggregations