zabbix.py
1.05 KB
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
41
42
43
44
45
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author tiexin.yang@yoho.cn
"""
删除zabbix configura里指定ip的host
此操作不可回滚,确认ip无误后再执行
"""
import json,sys,argparse
from zabbix_api import ZabbixAPI
server = "http://zabbix.yohops.com"
username = "yohoops"
password = "rknTpkVa@6ItBP"
zapi = ZabbixAPI(server=server, path="", log_level=0)
zapi.login(username, password)
def get_host_id(hosts):
get_host_id = zapi.host.get(
{
"output": "hostid",
"filter": {
"host": hosts.split(",")
}
}
)
host_id = []
host_id.append([host["hostid"] for host in get_host_id])
if host_id:
return host_id[0]
else:
return False
def delete_host_by_id(hosts_id):
if hosts_id:
hosts_delete = zapi.host.delete(hosts_id)
return "Zabbix host {0} 已成功删除!".format(hosts_id)
else:
return "Host 不存在"
def delete_host_by_ip(private_ip):
hosts_id = get_host_id(private_ip)
print delete_host_by_id(hosts_id)