Search in sources :

Example 11 with Properties

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

Example 12 with Properties

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

Example 13 with Properties

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

Example 14 with Properties

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);
    }
}
Also used : PipelineStat(loghub.jmx.PipelineStat) ParameterException(com.beust.jcommander.ParameterException) Parameter(com.beust.jcommander.Parameter) AbstractHttpServer(loghub.netty.http.AbstractHttpServer) ConfigException(loghub.configuration.ConfigException) JmxReporter(com.codahale.metrics.jmx.JmxReporter) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer) MBeanRegistrationException(javax.management.MBeanRegistrationException) ManagementFactory(java.lang.management.ManagementFactory) NotBoundException(java.rmi.NotBoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) FieldsProcessor(loghub.processors.FieldsProcessor) JCommander(com.beust.jcommander.JCommander) IOException(java.io.IOException) TestEventProcessing(loghub.configuration.TestEventProcessing) ObjectName(javax.management.ObjectName) StatsMBean(loghub.jmx.StatsMBean) InputStreamReader(java.io.InputStreamReader) MalformedObjectNameException(javax.management.MalformedObjectNameException) Logger(org.apache.logging.log4j.Logger) Helper(loghub.jmx.Helper) Configuration(loghub.configuration.Configuration) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LogManager(org.apache.logging.log4j.LogManager) Properties(loghub.configuration.Properties) NotBoundException(java.rmi.NotBoundException) AbstractHttpServer(loghub.netty.http.AbstractHttpServer) MBeanServer(javax.management.MBeanServer) MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) IOException(java.io.IOException) JmxReporter(com.codahale.metrics.jmx.JmxReporter) StatsMBean(loghub.jmx.StatsMBean) PipelineStat(loghub.jmx.PipelineStat) MBeanRegistrationException(javax.management.MBeanRegistrationException)

Example 15 with Properties

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;
}
Also used : EventsProcessor(loghub.EventsProcessor) Properties(loghub.configuration.Properties) EventsProcessor(loghub.EventsProcessor)

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