use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class EmailFilter method accepts.
/**
* Checks if the alarm is accepted by the filter.
*
* @param alarm the northbound alarm
* @return true, if successful
*/
public boolean accepts(NorthboundAlarm alarm) {
if (!isEnabled()) {
return false;
}
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(getRule());
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
} catch (Exception e) {
LOG.warn("accepts: can't evaluate expression {} for alarm {} because: {}", getRule(), alarm.getUei(), e.getMessage());
}
LOG.debug("accepts: checking {} ? {}", getRule(), passed);
return passed;
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class SnmpTrapMapping method accepts.
/**
* Verifies if the mapping object accepts a given northbound alarm.
*
* @param alarm the northbound alarm
* @return true, if the alarm is accepted
*/
public boolean accepts(NorthboundAlarm alarm) {
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(getRule());
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
} catch (Exception e) {
LOG.warn("mapping accepts: can't evaluate expression {} for alarm {} because: {}", getRule(), alarm.getUei(), e.getMessage());
}
LOG.debug("mapping accepts: checking {} ? {}", getRule(), passed);
return passed;
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class SnmpTrapMappingGroup method accepts.
/**
* Verifies if the mapping group object accepts a given northbound alarm.
*
* @param alarm the northbound alarm
* @return true, if the alarm is accepted.
*/
public boolean accepts(NorthboundAlarm alarm) {
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(getRule());
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
if (passed) {
boolean mappingAccepted = false;
for (SnmpTrapMapping mapping : getMappings()) {
if (mapping.accepts(alarm)) {
mappingAccepted = true;
break;
}
}
passed = mappingAccepted;
}
} catch (Exception e) {
LOG.warn("mapping group accepts: can't evaluate expression {} for alarm {} because: {}", getRule(), alarm.getUei(), e.getMessage());
}
LOG.debug("mapping group accepts: {} ? {}", getRule(), passed);
return passed;
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class SyslogFilter method passFilter.
/**
* Pass filter.
*
* @param alarm the alarm
* @return true, if successful
*/
public boolean passFilter(NorthboundAlarm alarm) {
if (!isEnabled()) {
return false;
}
StandardEvaluationContext context = new StandardEvaluationContext(alarm);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(getRule());
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
} catch (Exception e) {
LOG.warn("passFilter: can't evaluate expression {} for alarm {} because: {}", getRule(), alarm.getUei(), e.getMessage());
}
LOG.debug("passFilter: checking {} ? {}", getRule(), passed);
return passed;
}
use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.
the class SyslogEventForwarder method passFilter.
/**
* Pass filter.
*
* @param filter the filter
* @param event the event
* @return true, if successful
*/
private boolean passFilter(SyslogFilter filter, Event event) {
StandardEvaluationContext context = new StandardEvaluationContext(event);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(filter.getRule());
boolean passed = false;
try {
passed = (Boolean) exp.getValue(context, Boolean.class);
} catch (Exception e) {
LOG.warn("passFilter: can't evaluate expression {} for alarm {} because: {}", filter.getRule(), event.getUei(), e.getMessage());
}
LOG.debug("passFilter: checking {} ? {}", filter.getRule(), passed);
return passed;
}
Aggregations