Zabbix 2.0: Regular Expression to extract value from a String for a trigger?
I am using Zabbix 2.0.4 to monitor several Java applications. Most values are exported via JMX. One of those exported attributes is a string that is constructed like this: [IP_1],[port_1],[ms_time_1];[IP_2],[port_2],[ms_time_2]; eg:
192.168.105.20,5060,15638;192.168.105.30,5060,9753;
I want to construct a trigger based on the ms_time value for a given IP address. My first problem is: how do I get this value from the string? I have this regexp, which captures the correct number when I test it in several regular expression test tools:
192\.168\.105\.20,[\d]+,([\d]+)
But somehow, this doesn't seem to work in Zabbix. I have tried different versions of the regexp, e.g. using [0-9] or [:digit:] instead of [\d], but to no avail.
My trigger should get active when the ms_time value exceeds 15000, so my whole trigger definition currently looks like this:
{MY_HOST:jmx["com.example:type=Attributes",StringValue].regexp("192\.168\.105\.20,[\d]+,([\d]+)")}>15000
I couldn't find any examples where a regexp was used to extract a value from a string and use that value for further processing.
Solution 1:
Function regexp
returns 1 if the item's value matches the regular expression provided as the argument, and returns 0 otherwise. It does not return the extracted value.
In general, what you are trying to do is currently not possible, but there are two feature requests that may make it possible in the future: ZBXNEXT-1638 (store the whole value, but extract a piece of information later) and ZBXNEXT-1427 (extract a piece of information upon receival).
As a workaround, if the threshold value for ms_time
would be a round value (say, 10000), it would be possible to trigger based on ms_time
length:
192\.168\.105\.20,[\d]+,([\d]{5,})
Solution 2:
With the help of Asaveljevs' Answer, I finally managed to create a working trigger expression. Checking for the length of ms_time does not work in my case, but checking each digits value is a possibility. With leading zeros this is something like this:
{MY_HOST:jmx["com.example:type=Attributes",StringValue].regexp("192.168.105.20,
[[:digit:]]+,((0[0-9])|(1[0-4]))[[:digit:]][[:digit:]][[:digit:]];")}=0
This should match any number < 15000. Of course, another solution would be to invert the whole thing and look for any match >= 15000...
So thanks again, and let's hope these feature requests get implemented soon! ;-)