[SOLVED] Use RegEX into a Rule

I’m using this code into a rule to find some match into a string for each items into a group:

grpZabbixPing_Souliss.members.forEach[node |
        //Recupero il valore del Ping
        var Pattern mypattern
        var String ptn = ".*"+node.name+" check ICMP ping \\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d (\\d)"
        logInfo("Monitor-SoulissPing","Pattern: "+ptn)
		mypattern = Pattern::compile(ptn)
		var Matcher mymatcher
		mymatcher = mypattern.matcher(results)
		var String my_result
		my_result = mymatcher.group(1)
        logInfo("Monitor-SoulissPing","Nodo: "+node.name+ " Ping Status: "+my_result)


It happen that on first check the RegEx code do not found any results then rule end, but I need code will be executed for each item in my group.

I find this in log:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Zabbix Souliss Ping Status': No match found

Any suggestion?


You probably need to check if your results are null, before doing something with them that causes an error (and exit).

If you have the Regex transformation installed, this can be reduced to

val String my_result = transform("REGEX", ".*"+node.name+" check ICMP ping \\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d (\\d).*", results)
logInfo("Monitor-SoulissPing","Nodo: "+node.name+ " Ping Status: "+my_result)

The docs indicate that Matcher will return null if there is no matching Group. But you probably need to add logging to determine if the error is being generated by the find or the group. Or you can use the transform and avoid the problem entirely and you should get a null in my_result if there is no match without an error I think.

1 Like

Hi @rlkoshak
I have regEx Trasformation installed, and your code work like a charm.

Many Thanks