Reputation: 33
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
Upvotes: 0
Views: 823
Reputation: 33
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:
Upvotes: 1
Reputation: 1978
Question 1: how to find all hosts with problems?
Use the problem.get
method. You can then filter by $.name
the resulting JSON, if needed.
See: https://www.zabbix.com/documentation/current/en/manual/api/reference/problem/get
Question 2: how to close a problem?
Use the event.acknowledge
method.
See:
Upvotes: 1