Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DROOLS-7639] ansible-rulebook : support event path for collecting el… #124

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,98 @@ public void testSelectAttrWithScientificNotation() {

rulesExecutor.dispose();
}

@Test
public void testSelectAttrForArrayInArray() {

String JSON_ARRAY_IN_ARRAY =
"""
{
"rules":[
{
"Rule":{
"name":"r1",
"condition":{
"AllCondition":[
{
"SelectAttrExpression":{
"lhs":{
"Event":"incident.alerts.tags"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, this rule doesn't match because "Event":"incident.alerts.tags" doesn't treat alerts as an array. If we change it to "Event":"incident.alerts[1].tags", the rule would match.

},
"rhs":{
"key":{
"String":"value"
},
"operator":{
"String":"=="
},
"value":{
"String":"DiskUsage"
}
}
}
}
]
},
"actions":[
{
"Action":{
"action":"debug",
"action_args":{
"msg":"Found a match with alerts"
}
}
}
],
"enabled":true
}
}
]
}
""";

RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(JSON_ARRAY_IN_ARRAY);

List<Match> matchedRules = rulesExecutor.processFacts( """
{
"incident":{
"id":"aaa",
"active":false,
"alerts":[
{
"id":"bbb",
"tags":[
{
"name":"alertname",
"value":"MariadbDown"
},
{
"name":"severity",
"value":"critical"
}
],
"status":"Ok"
},
{
"id":"ccc",
"tags":[
{
"name":"severity",
"value":"critical"
},
{
"name":"alertname",
"value":"DiskUsage"
}
],
"status":"Ok"
}
]
}
}
""" ).join();
assertEquals( 1, matchedRules.size() );

rulesExecutor.dispose();
}
}
Loading