use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestEvent method TestLoop.
@Test
public void TestLoop() {
Map<String, Object> conf = new HashMap<>();
conf.put("maxSteps", 5);
Properties props = new Properties(conf);
Event e = Event.emptyTestEvent(ConnectionContext.EMPTY);
e.appendProcessor(new Looper());
EventsProcessor ep = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
// e.appendProcessor(p);
Processor processor;
int numsteps = 0;
int loop = 0;
while ((processor = e.next()) != null) {
logger.debug("doing step");
loop++;
if (ep.process(e, processor) != ProcessingStatus.SUCCESS) {
break;
}
;
Assert.assertTrue("Not counting processing", e.stepsCount() > numsteps);
Assert.assertTrue("Not stopping processing", e.stepsCount() <= props.maxSteps);
Assert.assertTrue("Not stopping processing", e.stepsCount() <= loop);
numsteps = e.stepsCount();
}
Assert.assertTrue("Breaking early", e.stepsCount() >= props.maxSteps);
e.end();
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestProcessor method testIf.
@Test
public void testIf() throws ProcessorException {
Event e = new EventInstance(ConnectionContext.EMPTY);
Processor p = new Identity();
p.setIf("true");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertTrue(p.isprocessNeeded(e));
p.setIf("false");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertFalse(p.isprocessNeeded(e));
p.setIf("0");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertFalse(p.isprocessNeeded(e));
p.setIf("1");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertTrue(p.isprocessNeeded(e));
p.setIf("0.1");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertTrue(p.isprocessNeeded(e));
p.setIf("\"bob\"");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertTrue(p.isprocessNeeded(e));
p.setIf("\"\"");
p.configure(new Properties(Collections.emptyMap()));
Assert.assertFalse(p.isprocessNeeded(e));
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestNsca method test.
@Test
public void test() throws ConfigException, IOException {
String conf = "pipeline[main] {} output $main | { loghub.senders.Nsca { password: \"password\", encryption: \"RIJNDAEL192\", nagiosServer: \"localhost\", largeMessageSupport: true, mapping: { \"level\": \"level\", \"service\": \"service\", \"message\": \"message\", \"host\": \"host\", } } }";
Properties p = Configuration.parse(new StringReader(conf));
Nsca sender = (Nsca) p.senders.stream().findAny().get();
Assert.assertTrue(sender.configure(p));
Event ev = Event.emptyEvent(ConnectionContext.EMPTY);
ev.put("level", "CRITICAL");
ev.put("service", "aservice");
ev.put("message", "message");
ev.put("host", "host");
sender.send(ev);
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class Start method configure.
private void configure() {
if (testedprocessor != null) {
test = true;
dumpstats = false;
}
if (pipeLineTest != null) {
TestEventProcessing.check(pipeLineTest, configFile);
exitcode = 0;
}
if (dumpstats) {
final long starttime = System.nanoTime();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public synchronized void start() {
long endtime = System.nanoTime();
double runtime = ((double) (endtime - starttime)) / 1.0e9;
System.out.format("received: %.2f/s\n", Stats.received.get() / runtime);
System.out.format("dropped: %.2f/s\n", Stats.dropped.get() / runtime);
System.out.format("sent: %.2f/s\n", Stats.sent.get() / runtime);
System.out.format("failed: %.2f/s\n", Stats.failed.get() / runtime);
System.out.format("thrown: %.2f/s\n", Stats.thrown.get() / runtime);
}
});
}
try {
Properties props = Configuration.parse(configFile);
if (!test) {
launch(props);
logger.warn("LogHub started");
exitcode = 0;
} else if (testedprocessor != null) {
testProcessor(props, testedprocessor);
}
} catch (ConfigException e) {
Throwable t = e;
if (e.getCause() != null) {
t = e.getCause();
}
String message = t.getMessage();
if (message == null) {
message = t.getClass().getSimpleName();
}
System.out.format("Error in %s: %s\n", e.getLocation(), message);
exitcode = 1;
} catch (IllegalStateException e) {
exitcode = 1;
} catch (RuntimeException e) {
e.printStackTrace();
exitcode = 1;
} catch (IOException e) {
System.out.format("can't read configuration file %s: %s\n", configFile, e.getMessage());
exitcode = 11;
}
if (canexit && exitcode != 0) {
System.exit(exitcode);
} else if (exitcode != 0) {
throw new RuntimeException();
}
}
Aggregations