Do not know why decided to implement that so late. Anyway this is how i’ve done it.
Created ZBX external item:
The itself script looks like this:
pawelski@ZbxServer:/usr/lib/zabbix/externalscripts$ tail get_ip.sh
ping $1 -c 1 | sed -nE ‘s/^PING[^(]+\(([^)]+)\).*/\1/p’
Also, please note that the script – in case the host is not responding will reply with something like:
ping: host blabla unavailable
I do not want that garage in ZABBIX, plus it can really mess up the triggers.
Let’s imagine host replies on 10.10.0.2 IP, later item has value “ping: blabla is not supported”. – what will happen if we apply trigger on this and set it to alert us when the value will change? – many unnecessary alerts, as the IP might not change, but the value of the trigger for sure will, first from “10.10.0.2” to “ping: blabla” and later back to “10.10.0.2”.
I want this sort of values to convert the item in the unsupported state, hence I add pre-processing:
The Parameters value is: \D*\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\D*\s*
And that is it. We will get IPs of our hosts, and when thehost is unavailable it return unsupported item – no garbage in the latest data. Now we can create a trigger on the item to monitor change of the latest value.
Have you already done it in a different way, or maybe you see some potential issues in this solution? If yes please give me a shout, I’m more than happy to discuss it.