创建主机时zabbix python api错误

时间:2012-09-04 02:10:33

标签: python api zabbix

使用Zabbix Python API创建主机时,我收到以下错误,

Traceback (most recent call last):
File "test.py", line 57, in <module>
zapi.host.create({ 'name':'testname', 'host' : '192.168.1.1','ip' :
 '192.178.1.2','port' : 10050,'useip' : 0,'groups' : [{
 "groupid":gid}],'templates' : [{ "templateid":tid}]})
 File "/home/zhiguo/zabbix/zabbix_api.py", line 346, in method
 return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
 File "/home/zhiguo/zabbix/zabbix_api.py", line 80, in wrapper
 return self.do_request(self.json_obj(method, opts))['result']
 File "/home/zhiguo/zabbix/zabbix_api.py", line 353, in do_request
 return self.parent.do_request(req)
 File "/home/zhiguo/zabbix/zabbix_api.py", line 307, in do_request
 raise ZabbixAPIException(msg, jobj['error']['code'])
 zabbix_api.ZabbixAPIException: (u'Error -32602: Invalid params., No 
 interfaces for host "192.168.1.1". while sending {"params": {"templates": {"templateid": "10085"}], "name": "testname", "ip": "192.178.1.2", "useip": 0, 
 "host": "192.168.1.1", "groups": [{"groupid": "6"}], "port": 10050},
 "jsonrpc": "2.0", "method": "host.create", "auth": 
 "7894f7d64a3f30e1754dd9d2eeb5a493", "id": 4}', -32602)

我的python代码是:

zapi.host.create({ 'name':'testname', 'host' : '192.168.1.1','ip' :   
'192.178.1.2',  'port'   : 10050,'useip' : 0,'groups' : [{ "groupid":gid}],  
'templates' : [{ "templateid":tid}]})

1 个答案:

答案 0 :(得分:1)

我还没有尝试过Zabbix 2.0 API, 但这就是我在1.8.x中的表现。

我很确定 dns 字段是强制性的,

hostid = zapi.host.create({ 'host': host_name, 'dns' : host_name,'ip' : host_ip, 
'groups': [{"groupid":hostgroup_id}]})['hostids'][0]

此外,来自docs

  "interfaces":[
      {
          "type":1,
          "main":1,
          "useip":1,
          "ip":"192.168.3.1",
          "dns":"",
          "port":10050
      }

似乎“无效的参数。,没有主机接口”抱怨缺少“接口”参数,