0

I am getting the following errors while using the Zabbix Python API for host creation,

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)

my python code is:

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}]})
j0k
  • 22,600
  • 28
  • 79
  • 90
zhiguo.wang
  • 4,393
  • 4
  • 16
  • 8

1 Answers1

1

I still haven't tried the Zabbix 2.0 API, but this was how I did it in 1.8.x

I'm quite sure dns field is mandatory,

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

Also, from the docs ,

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

it does seem "Invalid params., No interfaces for host" is complaining about a missing "interfaces" parameter,

Joao Figueiredo
  • 3,120
  • 3
  • 31
  • 40
  • Oh, 2.x have change this API. Yes,is the problem of without interfaces in params. **Thank you** – zhiguo.wang Sep 04 '12 at 09:35
  • Thumbs up for mentioning the "Invalid params.". It could have been a real timesink to find out what the reason for this message is. Thanks! – Alex Fedulov Apr 28 '14 at 14:42