I'm trying to make a script on Python, which works with zabbix-api.
For example: Trigger worked, problem appears and then I make an "action trigger", which will work on that host, where problem appeared. For the script, I need to get host (and host id), where problem appeared and then resolve the problem. But I don't know how to get only this host. Please, could you help me with this or maybe give me some advice, what am I doing wrong?
I tried something like:
my_host = zabbix_log.host.get(limit=1, output=["hostid", "name", "host"])[0]
Of course, it works, but I understand, that this is only give to me some random host, and not the host where problem appeared
I used command line arguments (macros) for resolving my issue. The point was to get hostname and hostid where problem appears.
So inside "script window" in global scripts I wrote something like:
python script.py {HOSTNAME} {HOST.ID}
And in the script.py
:
import sys
hostname = sys.argv[1]
hostid = sys.argv[2]
Supported macros: