Check if values of two string-type items are equal in a Zabbix trigger

Michał Kosmulski picture Michał Kosmulski · Mar 13, 2012 · Viewed 11k times · Source

I am monitoring an application using Zabbix and have defined a custom item which returns a string value. Since my item's values are actually checksums, they will only contain the characters [0-9a-f]. Two mirror copies of my application are running on two servers for the sake of redundancy. I would like to create a trigger which would take the item values from both machines and fire if they are not the same.

For a moment, let's forget about the moment when values change (it's not an atomic operation, so the system may see inconsistent state, which is not a real error, for a short time), since I could work around it by looking at several previous values.

The crux is: how to write a Zabbix trigger expression which could compare for equality the string values of two items (the same item on two mirror hosts, actually)?

Both according to the fine manual and as I confirmed in praxis, the standard operators = and # only work on numeric values, so I can't just write the natural {host1:myitem[param].last(0)} # {host2:myitem[param].last(0)}. Functions such as change() or diff() can only compare values of the same item at different points in time. Functions such as regexp() can only compare the item's value with a constant string/regular expression, not with another item's value. This is very limiting.

I could move the comparison logic into the script which my custom item executes, but it's a bit messy and not elegant, so if at all possible, I would prefer to have this logic inside my Zabbix trigger.

Perhaps despite the limitations listed above, someone can come up with a workaround?

Answer

Joao Figueiredo picture Joao Figueiredo · Mar 13, 2012

Workaround:

{host1:myitem[param].change(0)} # {host2:myitem[param].change(0)}

When only one of the servers sees a modification since the previously received value, an event is triggered.

From the Zabbix Manual,

change (float, int, str, text, log)
Returns difference between last and previous values. For strings:
0 - values are equal
1 - values differ