Guest User

Python Zabbix Auto Delete Host

a guest
Nov 4th, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import sys
  2. from pyzabbix.api import ZabbixAPI
  3.  
  4. zapi = ZabbixAPI(url='http://localhost/zabbix/', user='ZABBIXUSERNAME', password='ZABBIXPASSWORD')
  5.  
  6. TechHostName = str(sys.argv[1])
  7.  
  8. def GetHostInformationZabbix(HostName):
  9.     hostInformation = zapi.do_request('host.get',
  10.                               {
  11.                                 "output":"extend",
  12.                                   "filter":{
  13.                                             "host":[HostName]
  14.                                 }
  15.                               })
  16.                              
  17.     HostID = hostInformation['result'][0]['hostid']
  18.  
  19.     return HostID,
  20.    
  21. def DeleteHost(HostID):
  22.     DeleteInterface = zapi.do_request('host.delete',   # Deletes Host                    
  23.                                           [HostID]                  
  24.                                           )
  25.  
  26. def Main(HostName):
  27.    
  28.     HostInfo= GetHostInformationZabbix(HostName) #passes back (hostid, Listofinterfaces) associated with that HOSTNAME in zabbix
  29.     HostID = HostInformation[0]
  30.  
  31.     DeleteHost(HostID)
  32.    
  33.    
  34. Main(TechHostName) 
  35.  
Advertisement
Add Comment
Please, Sign In to add comment