Search in sources :

Example 1 with JexlEngine

use of org.apache.commons.jexl3.JexlEngine in project opennms by OpenNMS.

the class IpInterfaceScan method isIpMatching.

protected static boolean isIpMatching(final InetAddress ip, final String expr) {
    try {
        JexlEngine parser = new JexlEngine();
        Expression e = parser.createExpression(generateExpr(expr));
        final Map<String, Object> context = new HashMap<String, Object>();
        context.put("iplike", IPLike.class);
        context.put("ipaddr", ip.getHostAddress());
        Boolean out = (Boolean) e.evaluate(new MapContext(context));
        return out;
    } catch (Exception e) {
        LOG.error("Can't process rule '{}' while checking IP {}.", expr, ip, e);
        return false;
    }
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) HashMap(java.util.HashMap) MapContext(org.apache.commons.jexl2.MapContext)

Example 2 with JexlEngine

use of org.apache.commons.jexl3.JexlEngine in project jmeter by apache.

the class Jexl2Function method threadFinished.

@Override
public void threadFinished() {
    JexlEngine engine = threadLocalJexl.get();
    if (engine != null) {
        engine.clearCache();
        threadLocalJexl.remove();
    }
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine)

Example 3 with JexlEngine

use of org.apache.commons.jexl3.JexlEngine in project jmeter by apache.

the class Jexl2Function method getJexlEngine.

/**
     * Get JexlEngine from ThreadLocal
     * @return JexlEngine
     */
private static JexlEngine getJexlEngine() {
    JexlEngine engine = threadLocalJexl.get();
    if (engine == null) {
        engine = new JexlEngine();
        engine.setCache(512);
        engine.setLenient(false);
        engine.setSilent(false);
        threadLocalJexl.set(engine);
    }
    return engine;
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine)

Example 4 with JexlEngine

use of org.apache.commons.jexl3.JexlEngine in project jmeter by apache.

the class Jexl3Function method getJexlEngine.

/**
     * Get JexlEngine from ThreadLocal
     * @return JexlEngine
     */
private static JexlEngine getJexlEngine() {
    JexlEngine engine = threadLocalJexl.get();
    if (engine == null) {
        engine = new JexlBuilder().cache(512).silent(true).strict(true).debug(false).create();
        threadLocalJexl.set(engine);
    }
    return engine;
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder)

Example 5 with JexlEngine

use of org.apache.commons.jexl3.JexlEngine in project opennms by OpenNMS.

the class GraphResultsController method getSuggestedReports.

/**
 * <p>getSuggestedReports</p>
 *
 * @return an array of {@link java.lang.String} objects.
 */
public String[] getSuggestedReports(ResourceId resourceId, String matching) {
    List<String> metricList = new ArrayList<>();
    JexlEngine expressionParser = new JexlEngine();
    try {
        ExpressionImpl e = (ExpressionImpl) expressionParser.createExpression(matching);
        for (List<String> list : e.getVariables()) {
            if (list.get(0).equalsIgnoreCase("math")) {
                continue;
            }
            if (list.get(0).equalsIgnoreCase("datasources")) {
                metricList.add(list.get(1).intern());
            } else {
                metricList.add(list.get(0).intern());
            }
        }
    } catch (Exception e) {
    }
    if (!metricList.isEmpty()) {
        List<String> templates = new ArrayList<>();
        for (PrefabGraph graph : m_graphResultsService.getAllPrefabGraphs(resourceId)) {
            boolean found = false;
            for (String c : graph.getColumns()) {
                if (metricList.contains(c)) {
                    found = true;
                    continue;
                }
            }
            if (found) {
                templates.add(graph.getName());
            }
        }
        if (!templates.isEmpty()) {
            return templates.toArray(new String[templates.size()]);
        }
    }
    return new String[] { "all" };
}
Also used : ExpressionImpl(org.apache.commons.jexl2.ExpressionImpl) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) JexlEngine(org.apache.commons.jexl2.JexlEngine) ArrayList(java.util.ArrayList) MissingParameterException(org.opennms.web.servlet.MissingParameterException) RrdException(org.jrobin.core.RrdException)

Aggregations

JexlEngine (org.apache.commons.jexl2.JexlEngine)10 MapContext (org.apache.commons.jexl2.MapContext)5 Expression (org.apache.commons.jexl2.Expression)3 HashMap (java.util.HashMap)2 JexlContext (org.apache.commons.jexl2.JexlContext)2 JexlEngine (org.apache.commons.jexl3.JexlEngine)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 ExpressionImpl (org.apache.commons.jexl2.ExpressionImpl)1 JexlException (org.apache.commons.jexl2.JexlException)1 JexlBuilder (org.apache.commons.jexl3.JexlBuilder)1 DBException (org.jkiss.dbeaver.DBException)1 RrdException (org.jrobin.core.RrdException)1 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)1 MissingParameterException (org.opennms.web.servlet.MissingParameterException)1