use of org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression in project graylog2-server by Graylog2.
the class PrecedenceTest method andVsEquality.
@Test
public void andVsEquality() {
final Rule rule = parseRule("rule \"test\" when true == false && true then end");
final LogicalExpression when = rule.when();
assertThat(when).isInstanceOf(AndExpression.class);
AndExpression andExpr = (AndExpression) when;
assertThat(andExpr.left()).isInstanceOf(EqualityExpression.class);
assertThat(andExpr.right()).isInstanceOf(BooleanExpression.class);
}
use of org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression in project graylog2-server by Graylog2.
the class PrecedenceTest method comparisonVsEqual.
@Test
public void comparisonVsEqual() {
final Rule rule = parseRule("rule \"test\" when 1 > 2 == false then end");
final LogicalExpression when = rule.when();
assertThat(when).isInstanceOf(EqualityExpression.class);
EqualityExpression topEqual = (EqualityExpression) when;
assertThat(topEqual.left()).isInstanceOf(ComparisonExpression.class);
assertThat(topEqual.right()).isInstanceOf(BooleanExpression.class);
}
use of org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression in project graylog2-server by Graylog2.
the class PrecedenceTest method orVsEquality.
@Test
public void orVsEquality() {
final Rule rule = parseRule("rule \"test\" when true == false || true then end");
final LogicalExpression when = rule.when();
assertThat(when).isInstanceOf(OrExpression.class);
OrExpression orEprx = (OrExpression) when;
assertThat(orEprx.left()).isInstanceOf(EqualityExpression.class);
assertThat(orEprx.right()).isInstanceOf(BooleanExpression.class);
}
use of org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression in project graylog2-server by Graylog2.
the class PipelineInterpreter method evaluateRuleCondition.
private boolean evaluateRuleCondition(Rule rule, Message message, String msgId, Pipeline pipeline, EvaluationContext context, List<Rule> rulesToRun, InterpreterListener interpreterListener) {
interpreterListener.evaluateRule(rule, pipeline);
final boolean matched;
final LogicalExpression logicalExpression = rule.when();
try {
matched = logicalExpression.evaluateBool(context);
} catch (Exception e) {
context.onEvaluationException(e, logicalExpression);
message.addProcessingError(new Message.ProcessingError(ProcessingFailureCause.RuleConditionEvaluationError, String.format(Locale.ENGLISH, "Error evaluating condition for rule <%s/%s> (pipeline <%s/%s>)", rule.name(), rule.id(), pipeline.name(), pipeline.id()), context.lastEvaluationError().toString()));
interpreterListener.failEvaluateRule(rule, pipeline);
return false;
}
if (matched) {
rule.markMatch();
interpreterListener.satisfyRule(rule, pipeline);
log.debug("[{}] rule `{}` matches, scheduling to run", msgId, rule.name());
rulesToRun.add(rule);
return true;
} else {
rule.markNonMatch();
interpreterListener.dissatisfyRule(rule, pipeline);
log.debug("[{}] rule `{}` does not match", msgId, rule.name());
}
return false;
}
use of org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression in project graylog2-server by Graylog2.
the class PrecedenceTest method parenGroup.
@Test
public void parenGroup() {
final Rule rule = parseRule("rule \"test\" when true == (false == false) then end");
final LogicalExpression when = rule.when();
assertThat(when).isInstanceOf(EqualityExpression.class);
EqualityExpression topEqual = (EqualityExpression) when;
assertThat(topEqual.left()).isInstanceOf(BooleanExpression.class);
assertThat(topEqual.right()).isInstanceOf(EqualityExpression.class);
final BooleanExpression trueExpr = (BooleanExpression) topEqual.left();
assertThat(trueExpr.evaluateBool(null)).isTrue();
final EqualityExpression falseFalse = (EqualityExpression) topEqual.right();
assertThat(falseFalse.evaluateBool(null)).isTrue();
}
Aggregations