Skip to content

Commit a77326e

Browse files
author
zhanghe5
committed
更新读取文件的格式
1 parent bd12c36 commit a77326e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

zabbix_host_update.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_options():
3232
0 - (default) monitored host;
3333
1 - unmonitored host.""")
3434
parser.add_option("-f","--file",dest="filename",\
35-
metavar="FILE",help="Load values from input file. Specify - for standard input Each line of file contains whitespace delimited: <hostname>\\t<status>")
35+
metavar="FILE",help="Load values from input file. Specify - for standard input Each line of file contains whitespace delimited: <hostname>4space<status>")
3636

3737
options,args = parser.parse_args()
3838

@@ -65,20 +65,22 @@ def errmsg(msg):
6565
with open(file,"r") as f:
6666
content = f.readlines()
6767
for i in content:
68-
l = i.split("\t")
68+
l = i.split(" ")
6969
n = len(l)
7070
hostname = l[0].rstrip()
7171
status = l[1].rstrip()
7272
hostid=zapi.host.get({"filter":{"host":hostname}})[0]["hostid"]
7373
print n,'\t',hostname,'\t',hostid,'\t',status
7474
try:
75-
zapi.host.update({"hostid":hostid,"status":status})
75+
msg = zapi.host.update({"hostid":hostid,"status":status})
76+
print msg
7677
except Exception as e:
7778
print str(e)
7879
else:
7980
hostid=zapi.host.get({"filter":{"host":hostname}})[0]["hostid"]
8081
print hostname,'\t',hostid,'\t',status
8182
try:
82-
zapi.host.update({"hostid":hostid,"status":status})
83+
msg = zapi.host.update({"hostid":hostid,"status":status})
84+
print msg
8385
except Exception as e:
8486
print str(e)

0 commit comments

Comments
 (0)