Search in sources :

Example 71 with Properties

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();
}
Also used : HashMap(java.util.HashMap) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 72 with Properties

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));
}
Also used : Identity(loghub.processors.Identity) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 73 with Properties

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);
}
Also used : StringReader(java.io.StringReader) Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 74 with Properties

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();
    }
}
Also used : ConfigException(loghub.configuration.ConfigException) IOException(java.io.IOException) Properties(loghub.configuration.Properties)

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