Created
November 14, 2018 10:50
-
-
Save guelau/e1f0b4577385bd1292cc03e4569006a6 to your computer and use it in GitHub Desktop.
Autoregister and remove Host in Zabbix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Based on Samuel Cozannet's script | |
# Updated by Laurent ([email protected]) | |
# | |
# Note: requires pyzabbix to be installed. | |
# [email protected]~# pip install pyzabbix | |
# | |
from pyzabbix import ZabbixAPI | |
import argparse | |
import sys | |
import yaml | |
import json | |
import pprint | |
parser = argparse.ArgumentParser(description="delete a host with a given IP Address from Zabbix") | |
parser.add_argument('-c', action="store", dest="conffile", default='.zabbixapi.yaml') | |
parser.add_argument('hostip', type=str, help = 'IP address of host to delete') | |
args = parser.parse_args() | |
with open(args.conffile, 'r') as f: | |
conf = yaml.load(f) | |
zapi = ZabbixAPI(server=conf["zabbix-api"]["endpoint"]) | |
zapi.login(conf["zabbix-api"]["login"], conf["zabbix-api"]["password"]) | |
hostid=zapi.host.get(filter={'ip': args.hostip } ) | |
if hostid: | |
id = hostid[0]["hostid"] | |
print("deleting host {0}".format(id) + " with IP Address {0}".format(args.hostip)) | |
result = zapi.host.delete(id) | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zabbix-api: endpoint: "http://localhost" login: "rpc" password: "rpcpassword" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment