2

I need to delete automatically my unreachable/down host in zabbix. All host are monitored using active agent hence network discovery auto delete is not handy/useful in my case.

I have written a small python script to delete/remove host from zabbix using zabbix-api. However what I want to achieve is as below:

1 : Find all host if the host is unreachable for more than 2 hours

2 : Mark their status and update list of to be deleted host

3 : Delete all these hosts after 24 hours cycle.

If in case step 2 is not possible I am very much comfortable with step 1 and 3 as of now.

I am unable to find correct api response of zabbix to identify the host which are down or unreachable for more than an hour or xyz time.

PS: I have referred to URL1 and URL2 but still no luck.

user355522
  • 23
  • 1
  • 5

1 Answers1

1

I used trigger value to remove host from zabbix, checck if below code works for you as well:

from zabbix_api import ZabbixAPI, Already_Exists
z = ZabbixAPI(server="https://zabbix.example.com/zabbix")
z.login("exampleuser", "exampleuser")
for trigger in z.trigger.get({"output": [ "triggerid", "description", "priority" ], "filter": { "value": 1 }, "sortfield": "priority", "sortorder": "DESC"}):
    if trigger["description"] == 'Zabbix agent on {HOST.NAME} is unreachable for 5 minutes':
        trigmsg = z.trigger.get({"triggerids": trigger["triggerid"], "selectHosts": "extend"})
        for tm in trigmsg:
            for l in tm['hosts']:
                print l['name'], l['hostid']
                print "Will kill host " + l['hostid'] + " " + l['host'] + trigger["description"]
                z.host.delete( [int(l['hostid'])] )
Pratap
  • 665
  • 6
  • 22