dthre 发表于 2016-9-9 08:57:24

zabbix API 删除host

脚本内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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( for I in get_host_id])
    return host_id
   
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)





脚本使用:


1
2
# python host_delete.py --host='aaa,bbb'
host delete success!



页: [1]
查看完整版本: zabbix API 删除host