Search in sources :

Example 1 with Processor

use of loghub.Processor in project LogHub by fbacchella.

the class Test method process.

@Override
public boolean process(Event event) throws ProcessorException {
    Boolean testResult = Boolean.TRUE.equals(ifClause.eval(event, Collections.emptyMap()));
    Processor nextTransformer = testResult ? thenTransformer : elseTransformer;
    event.insertProcessor(nextTransformer);
    return testResult;
}
Also used : Processor(loghub.Processor)

Example 2 with Processor

use of loghub.Processor in project LogHub by fbacchella.

the class Configuration method parsePipeline.

private Pipeline parsePipeline(ConfigListener.PipenodesList desc, String currentPipeLineName, int depth, AtomicInteger subPipeCount) throws ConfigException {
    List<Processor> allSteps = new ArrayList<Processor>() {

        @Override
        public String toString() {
            StringBuilder buffer = new StringBuilder();
            buffer.append("PipeList(");
            for (Processor i : this) {
                buffer.append(i);
                buffer.append(", ");
            }
            buffer.setLength(buffer.length() - 2);
            buffer.append(')');
            return buffer.toString();
        }
    };
    desc.processors.stream().map(i -> {
        return getProcessor(i, currentPipeLineName, depth, subPipeCount);
    }).forEach(allSteps::add);
    Pipeline pipe = new Pipeline(allSteps, currentPipeLineName + (depth == 0 ? "" : "$" + subPipeCount.getAndIncrement()), desc.nextPipelineName);
    return pipe;
}
Also used : PropertyContext(loghub.RouteParser.PropertyContext) Arrays(java.util.Arrays) ArrayContext(loghub.RouteParser.ArrayContext) Input(loghub.configuration.ConfigListener.Input) URL(java.net.URL) LoggerContext(org.apache.logging.log4j.core.LoggerContext) URISyntaxException(java.net.URISyntaxException) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) URLClassLoader(java.net.URLClassLoader) CharStreams(org.antlr.v4.runtime.CharStreams) Helpers(loghub.Helpers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) ObjectReference(loghub.configuration.ConfigListener.ObjectReference) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) DateTimeException(java.time.DateTimeException) Receiver(loghub.Receiver) TimeZone(java.util.TimeZone) Collection(java.util.Collection) LiteralContext(loghub.RouteParser.LiteralContext) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Reader(java.io.Reader) RouteLexer(loghub.RouteLexer) ZoneId(java.time.ZoneId) RouteParser(loghub.RouteParser) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Processor(loghub.Processor) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ThrowingFunction(loghub.Helpers.ThrowingFunction) ThrowingConsumer(loghub.Helpers.ThrowingConsumer) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CharStream(org.antlr.v4.runtime.CharStream) Sender(loghub.Sender) ThrowingPredicate(loghub.Helpers.ThrowingPredicate) Output(loghub.configuration.ConfigListener.Output) BeanValueContext(loghub.RouteParser.BeanValueContext) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Pipeline(loghub.Pipeline) IOException(java.io.IOException) Source(loghub.Source) File(java.io.File) Consumer(java.util.function.Consumer) NamedSubPipeline(loghub.processors.NamedSubPipeline) RecognitionException(org.antlr.v4.runtime.RecognitionException) Paths(java.nio.file.Paths) AnonymousSubPipeline(loghub.processors.AnonymousSubPipeline) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) InputStream(java.io.InputStream) Processor(loghub.Processor) ArrayList(java.util.ArrayList) Pipeline(loghub.Pipeline) NamedSubPipeline(loghub.processors.NamedSubPipeline) AnonymousSubPipeline(loghub.processors.AnonymousSubPipeline)

Example 3 with Processor

use of loghub.Processor in project LogHub by fbacchella.

the class TestFailure method test.

@Test(expected = ProcessorException.class)
public void test() throws ProcessorException {
    Processor p = new Processor() {

        @Override
        public boolean process(Event event) throws ProcessorException {
            throw event.buildException("test failure", new RuntimeException("test failure"));
        }

        @Override
        public String getName() {
            return null;
        }
    };
    Event event = Tools.getEvent();
    event.process(p);
}
Also used : Processor(loghub.Processor) Event(loghub.Event) Test(org.junit.Test)

Example 4 with Processor

use of loghub.Processor in project LogHub by fbacchella.

the class TestToJson method test1.

@Test
public void test1() throws ProcessorException {
    Event e = Tools.getEvent();
    Processor t = new ParseJson();
    e.put("message", "{\"a\": [ 1, 2.0 , 3.01 , {\"b\": true} ] }");
    e.process(t);
    @SuppressWarnings("unchecked") Collection<Object> a = (Collection<Object>) e.get("a");
    a.stream().forEach((i) -> logger.debug(i.getClass()));
    logger.debug(e);
}
Also used : ParseJson(loghub.processors.ParseJson) Processor(loghub.Processor) Event(loghub.Event) Collection(java.util.Collection) Test(org.junit.Test)

Example 5 with Processor

use of loghub.Processor in project LogHub by fbacchella.

the class FieldsProcessor method delegate.

private void delegate(Set<String> nextfields, Event event) {
    final Iterator<String> processing = nextfields.iterator();
    Processor fieldProcessor;
    if (this instanceof AsyncFieldsProcessor) {
        fieldProcessor = new AsyncFieldSubProcessor(processing, ((AsyncFieldsProcessor<?>) this).getTimeout());
    } else {
        fieldProcessor = new FieldSubProcessor(processing);
    }
    if (processing.hasNext()) {
        event.insertProcessor(fieldProcessor);
    }
    throw IgnoredEventException.INSTANCE;
}
Also used : Processor(loghub.Processor) AsyncProcessor(loghub.AsyncProcessor)

Aggregations

Processor (loghub.Processor)6 Event (loghub.Event)3 Collection (java.util.Collection)2 Pipeline (loghub.Pipeline)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 DateTimeException (java.time.DateTimeException)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1