Skip to content

Commit 114aa4b

Browse files
author
zhanghe5
committed
添加异常处理
1 parent 8a53ed1 commit 114aa4b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

zabbix_host_delete.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def errmsg(msg):
5757
host_list = f.readlines()
5858
for hostname in host_list:
5959
hostname = hostname.rstrip()
60-
hostid=zapi.host.get({"filter":{"host":hostname},"output":"hostid"})[0]["hostid"]
60+
try:
61+
hostid=zapi.host.get({"filter":{"host":hostname},"output":"hostid"})[0]["hostid"]
62+
except Exception as e:
63+
print "can not get hostid for host:{0}".format(hostname)
64+
continue
6165
print hostname,'\t',hostid
6266
try:
6367
result = zapi.host.delete([hostid])

0 commit comments

Comments
 (0)