脚本内容如下:
#!/usr/bin/python #-*- coding:utf8 -*- import json,sys,argparse from zabbix_api import ZabbixAPI server = "http://172.16.206.128/zabbix" username = "Admin" password = "zabbix" zapi = ZabbixAPI(server=server, path="", log_level=0) zapi.login(username, password) def get_args(): parser = argparse.ArgumentParser() parser.add_argument("-H", "--host", help="host name") # 解析所传入的参数 args = parser.parse_args() if not args.host: args.host = raw_input(‘host: ‘) return args def get_host_id(host): get_host_id = zapi.host.get( { "output": "hostid", "filter": { "host":host.split(",") } } ) host_id = [] host_id.append([I[‘hostid‘] for I in get_host_id]) return host_id[0] def delete_host(hosts_id): hosts_delete = zapi.host.delete(hosts_id) return "host delete success!" if __name__ == "__main__": args = get_args() host_id = get_host_id(args.host) print delete_host(host_id)
脚本使用:
# python host_delete.py --host=‘aaa,bbb‘ host delete success!
本文出自 “zengestudy” 博客,请务必保留此出处http://zengestudy.blog.51cto.com/1702365/1850655
原文地址:http://zengestudy.blog.51cto.com/1702365/1850655