[ZBX-9093] Can't create host with inventory through API Created: 2014 Dec 01  Updated: 2017 May 30  Resolved: 2015 Jan 27

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A), Documentation (D)
Affects Version/s: 2.0.13, 2.2.7, 2.4.2
Fix Version/s: 2.0.15rc1, 2.2.9rc1, 2.4.4rc1, 2.5.0

Type: Incident report Priority: Major
Reporter: Thomas MEVEL Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: host, inventory, mysql
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Database : MySQL


Issue Links:
Duplicate
duplicates ZBX-7102 Error creating host via API with meth... Closed

 Description   

When calling host.create through api_jsonrpc.php with inventory object, inserting fails.

After investigation, error is the same as ZBX-7561 : Field 'hardware_full' doesn't have a default value .

The source would be calling DBExecute directly from CHost::insert.

Not tested, but it seems that the example from the documentation ( https://www.zabbix.com/documentation/2.4/manual/api/reference/host/create ) wouldn't work.



 Comments   
Comment by richlv [ 2014 Dec 01 ]

just in case, could you please add exact request & response json ?

Comment by Thomas MEVEL [ 2014 Dec 02 ]

Sure, here is the request (data content edited) :

{
  "jsonrpc":"2.0",
  "method":"host.create",
  "params":{ 
         "host":"srv-backup1",
         "interfaces" :[
                 {
                      "type" : 1,
                       "main" : 1, "ip" : "186.154.53.62", 
                       "port" : "10574",
                       "useip" : 1,
                       "dns" : "" 
                 } 
         ],
         "proxy_hostid":0,
         "ipmi_privilege":2,
         "groups": [  { "groupid":"8"},{ "groupid":"1"} ], 
         "templates":[ ],
         "inventory": { "serialno_a": "AA25641", "tag": "1" } 
 },
 "auth":"73704a74c6ca1befde153ba87502fba5",
 "id":1 
}

Response won't give much help as it fails giving a success result (see ZBX-9094) :

{
 "jsonrpc":"2.0",
 "result": {"hostids":["10106"]},
 "id":1
}
Comment by Alexander Vladishev [ 2014 Dec 02 ]

I confirm the issue in 2.0, 2.2 and 2.4 branches r50976.

Comment by Leif Johnson [ 2014 Dec 18 ]

It look like the host inventory get's disabled on host.create. Changing the inventory mode via

 "inventory_mode": 1 

does not appear to work either.

Using host.update afterwards does appear to work and could be a work around.

    "inventory_mode": 1,
        "inventory": {
            "macaddress_a": "01234",
            "macaddress_b": "56768"
        }
Comment by Ivo Kurzemnieks [ 2015 Jan 14 ]

(1) No translation string changes.

sasha CLOSED

Comment by Ivo Kurzemnieks [ 2015 Jan 14 ]

RESOLVED in svn://svn.zabbix.com/branches/dev/ZBX-9093

Comment by Alexander Vladishev [ 2015 Jan 14 ]

(2) Take a look at my changes in r51591.

iivs Thanks!
CLOSED.

Comment by Ivo Kurzemnieks [ 2015 Jan 15 ]

API documentation updated:

Fixed in:

  • pre-2.0.15rc1 r51620
  • pre-2.2.9rc1 r51621
  • pre-2.4.4rc1 r51622
  • pre-2.5.0 r51624
Comment by Oleg Egorov (Inactive) [ 2015 Jan 26 ]

(3) SQL statement execution has failed \"INSERT INTO host_inventory (macaddress_a,macaddress_b,hostid,inventory_mode,hardware_full,software_full,contact,location,notes,host_networks,site_notes,poc_1_notes,poc_2_notes) VALUES ('01234','56768','1','0','','','','','','','','','')

host.create
API request used from documentation:
https://www.zabbix.com/documentation/3.0/manual/api/reference/host/create

{
        "host": "NA1",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "192.168.3.1",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "13"
            }
        ],
        "templates": [
            {
                "templateid": "10111"
            }
        ],
        "inventory": {
            "macaddress_a": "01234",
            "macaddress_b": "56768"
        }
    }

Clean installation (trunk)

sasha Thank you for a report! RESOLVED in r51842.

iivs Good fix! Thanks!
CLOSED.

Comment by Ivo Kurzemnieks [ 2015 Jan 27 ]

TESTED.

Comment by Alexander Vladishev [ 2015 Jan 27 ]

Fixed in:

pre-2.0.15 r51855
pre-2.2.9 r51856
pre-2.4.4 r51857
pre-2.5.0 (trunk) r51858

Generated at Sat Apr 20 16:22:01 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.