use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestOnigurumaRegex method testUtf2.
@Test
public void testUtf2() throws ProcessorException {
OnigurumaRegex grok = new OnigurumaRegex();
grok.setField("message");
grok.setPattern("<(?<syslog_pri>\\d+)>(?<message>é.*)");
Properties props = new Properties(Collections.emptyMap());
Assert.assertTrue("Failed to configure grok", grok.configure(props));
Event e = Tools.getEvent();
e.put("message", "<15>éa text");
Assert.assertTrue(e.process(grok));
Assert.assertEquals("Didn't find the good syslog priority", "15", e.get("syslog_pri"));
Assert.assertEquals("Didn't find the good syslog message", "éa text", e.get("message"));
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestScanBinary method simpleTestWithVariableLengthName2s.
@Test
public void simpleTestWithVariableLengthName2s() throws ProcessorException {
ScanBinary fs = new ScanBinary();
fs.setBitsNames(new String[] { "a", "b", "c" });
fs.setFieldsLength(new Integer[] { 3, 2, 1 });
fs.configure(new Properties(Collections.emptyMap()));
Event e = Event.emptyEvent(ConnectionContext.EMPTY);
e.put("binary", 0b110101);
Assert.assertTrue(fs.processMessage(e, "binary", "value"));
@SuppressWarnings("unchecked") Map<String, Number> value = (Map<String, Number>) e.get("value");
Assert.assertEquals(0b101, value.get("a").intValue());
Assert.assertEquals(0b10, value.get("b").intValue());
Assert.assertEquals(0b1, value.get("c").intValue());
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestFileMap method testSourceLoading.
@Test
public void testSourceLoading() throws ConfigException, IOException {
Properties conf = Tools.loadConf("sources.conf", false);
conf.sources.values().forEach(i -> Assert.assertTrue(i.configure(conf)));
FileMap s = (FileMap) conf.sources.get("source1");
Assert.assertEquals("Reserved", s.get("0"));
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class Start method launch.
public void launch(Properties props) throws ConfigException, IOException {
for (Source s : props.sources.values()) {
if (!s.configure(props)) {
logger.error("failed to start source {}", s.getName());
throw new IllegalStateException();
}
;
}
props.pipelines.stream().forEach(i -> i.configure(props));
for (Sender s : props.senders) {
if (s.configure(props)) {
s.start();
} else {
logger.error("failed to configure output {}", s.getName());
throw new IllegalStateException();
}
;
}
for (int i = 0; i < props.numWorkers; i++) {
Thread t = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
t.setName("ProcessingThread" + i);
t.setDaemon(false);
t.start();
}
for (Receiver r : props.receivers) {
if (r.configure(props)) {
r.start();
} else {
logger.error("failed to configure input {}", r.getName());
throw new IllegalStateException();
}
}
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new StatsMBean.Implementation(), StatsMBean.Implementation.NAME);
JmxReporter reporter = Properties.metrics.getJmxReporter();
reporter.start();
mbs.queryNames(ObjectName.getInstance("metrics", "name", "Pipeline.*.timer"), null).stream().map(i -> i.getKeyProperty("name")).map(i -> i.replaceAll("^Pipeline\\.(.*)\\.timer$", "$1")).forEach(i -> {
try {
mbs.registerMBean(new PipelineStat.Implementation(i), null);
} catch (NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
}
});
int port = props.jmxport;
if (port > 0) {
Helper.start(props.jmxproto, props.jmxlisten, port);
}
} catch (IOException | NotBoundException | NotCompliantMBeanException | MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
throw new RuntimeException("jmx configuration failed: " + e.getMessage(), e);
}
if (props.httpPort >= 0) {
AbstractHttpServer server = new DashboardHttpServer();
server.setPort(props.httpPort);
server.configure(props);
}
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class Tools method runProcessing.
public static ProcessingStatus runProcessing(Event sent, String pipename, List<Processor> steps, BiConsumer<Properties, List<Processor>> prepare) throws ProcessorException {
Properties props = new Properties(Collections.emptyMap());
ProcessingStatus ps = new ProcessingStatus();
ps.mainQueue = props.mainQueue;
ps.status = new ArrayList<>();
ps.repository = props.repository;
Pipeline pipe = new Pipeline(steps, pipename, null);
Map<String, Pipeline> namedPipeLine = Collections.singletonMap(pipename, pipe);
EventsProcessor ep = new EventsProcessor(props.mainQueue, props.outputQueues, namedPipeLine, 100, props.repository);
Processor processor;
steps.forEach(i -> Assert.assertTrue(i.configure(props)));
prepare.accept(props, steps);
sent.inject(pipe, props.mainQueue);
Event toprocess;
// Process all the events, will hang forever is it don't finish
try {
while ((toprocess = props.mainQueue.poll(5, TimeUnit.SECONDS)) != null) {
while ((processor = toprocess.next()) != null) {
EventsProcessor.ProcessingStatus status = ep.process(toprocess, processor);
ps.status.add(status.name());
if (status != loghub.EventsProcessor.ProcessingStatus.SUCCESS) {
toprocess = null;
break;
}
}
if (toprocess != null) {
ps.mainQueue.put(toprocess);
break;
}
}
} catch (InterruptedException e) {
}
return ps;
}
Aggregations