Search in sources :

Example 1 with Expression

use of loghub.Expression in project LogHub by fbacchella.

the class Merge method configure.

@Override
public boolean configure(Properties properties) {
    if (indexSource == null) {
        return false;
    }
    repository = new EventsRepository<String>(properties);
    cumulators = new ConcurrentHashMap<>(seeds.size() + 1);
    // Default to timestamp is to keep the first
    cumulators.put("@timestamp", Cumulator.FIRST.cumulate(null));
    for (Entry<String, Object> i : seeds.entrySet()) {
        cumulators.put(i.getKey(), Cumulator.getCumulator(i.getValue()));
    }
    index = new VarFormatter(indexSource);
    // Prepare fire only if test and processor given for that
    if (fireSource != null && fireProcessor != null) {
        try {
            fire = new Expression(fireSource, properties.groovyClassLoader, properties.formatters);
        } catch (ExpressionException e) {
            Expression.logError(e, fireSource, logger);
            return false;
        }
        if (!fireProcessor.configure(properties)) {
            return false;
        }
    }
    if (timeoutProcessor != null && !timeoutProcessor.configure(properties)) {
        return false;
    }
    if (nextPipeline == null) {
        return false;
    }
    return super.configure(properties);
}
Also used : VarFormatter(loghub.VarFormatter) Expression(loghub.Expression) ExpressionException(loghub.Expression.ExpressionException)

Example 2 with Expression

use of loghub.Expression in project LogHub by fbacchella.

the class FireEvent method process.

@Override
public boolean process(Event event) throws ProcessorException {
    Event newEvent = Event.emptyEvent(ConnectionContext.EMPTY);
    for (Map.Entry<String[], Expression> e : expressions.entrySet()) {
        Object value = e.getValue().eval(event, Collections.emptyMap());
        newEvent.applyAtPath((i, j, k) -> i.put(j, k), e.getKey(), value);
    }
    return newEvent.inject(pipeDestination, mainQueue);
}
Also used : Expression(loghub.Expression) Event(loghub.Event) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Expression

use of loghub.Expression in project LogHub by fbacchella.

the class FireEvent method configure.

@Override
public boolean configure(Properties properties) {
    expressions = new HashMap<>(fields.size());
    for (Map.Entry<String[], String> i : fields.entrySet()) {
        try {
            Expression ex = new Expression(i.getValue(), properties.groovyClassLoader, properties.formatters);
            expressions.put(i.getKey(), ex);
        } catch (ExpressionException e) {
            logger.error("invalid expression for field {}: {}", i.getKey(), i.getValue());
            return false;
        }
    }
    if (!properties.namedPipeLine.containsKey(destination)) {
        logger.error("invalid destination for forked event: {}", destination);
        return false;
    }
    pipeDestination = properties.namedPipeLine.get(destination);
    mainQueue = properties.mainQueue;
    return super.configure(properties);
}
Also used : Expression(loghub.Expression) Map(java.util.Map) HashMap(java.util.HashMap) ExpressionException(loghub.Expression.ExpressionException)

Example 4 with Expression

use of loghub.Expression in project LogHub by fbacchella.

the class Test method configure.

@Override
public boolean configure(Properties properties) {
    thenTransformer.configure(properties);
    elseTransformer.configure(properties);
    try {
        ifClause = new Expression(ifClauseSource, properties.groovyClassLoader, properties.formatters);
    } catch (ExpressionException e) {
        Expression.logError(e, ifClauseSource, logger);
        return false;
    }
    return super.configure(properties);
}
Also used : Expression(loghub.Expression) ExpressionException(loghub.Expression.ExpressionException)

Aggregations

Expression (loghub.Expression)4 ExpressionException (loghub.Expression.ExpressionException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Event (loghub.Event)1 VarFormatter (loghub.VarFormatter)1