[ZBX-11020] JSON host.create inventory problem Created: 2016 Jul 22  Updated: 2017 May 30  Resolved: 2016 Sep 04

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 3.0.2
Fix Version/s: 2.2.15rc1, 3.0.5rc1, 3.2.0beta2

Type: Incident report Priority: Major
Reporter: Vekli Sergey Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: inventory
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

FreeBSD 10.0-RELEASE-p4 FreeBSD 10.0-RELEASE-p4 #0: Tue Jun 3 13:14:57 UTC 2014 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64



 Description   

When creating host via API inventory_mode parameter is ignoring.

$x='{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "'.$cgi->param('hostname').'",
        "interfaces": [
                         {
                          "dns" : "",
                          "ip" : "'.$cgi->param('IP').'",
                          "port" : "10050",
                          "main" : 1,
                          "useip" : 1,
                          "type" : 1

                        },
                        {
                          "dns" : "",
                          "ip" : "'.$cgi->param('IP').'",
                          "port" : "161",
                          "main" : 1,
                          "useip" : 1,
                          "type" : 2

                        }
        ],

        "description":"'.$newdescr.'",
        "groups": [
        '.$groups_for_adding.'

        ],
        "templates": [
            {
                "templateid": "'.$cgi->param('template').'"
            }
        ],
        "inventory_mode": 1



    },
    "id": 2,
    "auth": "xxxx"
}';

When i open created host via web inventory mode in "Disabled".



 Comments   
Comment by Aleksandrs Saveljevs [ 2016 Jul 25 ]

It seems that in order for inventory_mode to work, we also need to specify a non-empty inventory object, like so:

{
    "host": "ZBX-11020-6",
    "interfaces": [
        {
            "dns": "",
            "ip": "127.0.0.1",
            "main": 1,
            "port": "10050",
            "type": 1,
            "useip": 1
        }
    ],
    "groups": [
        "2"
    ],
    "inventory": {
        "macaddress_a": "11:22:33:44:55:66"
    },
    "inventory_mode": "1"
}

It should probably not be required.

Comment by Aleksandrs Saveljevs [ 2016 Aug 03 ]

Fixed for version 3.0 in development branch svn://svn.zabbix.com/branches/dev/ZBX-11020-30 .

Comment by Aleksandrs Saveljevs [ 2016 Aug 03 ]

Fix for version 2.2 is in development branch svn://svn.zabbix.com/branches/dev/ZBX-11020 .

Comment by Aleksandrs Saveljevs [ 2016 Aug 03 ]

There are some questions remaining (like why "inventory_mode" defaults to "disabled" if an empty "inventory" is specified, as opposed to "manual" for non-empty "inventory"), but this should probably be handled in ZBX-6033.

Comment by Aleksandrs Saveljevs [ 2016 Aug 31 ]

(1) No translation string changes in either branch.

iivs CLOSED

Comment by Ivo Kurzemnieks [ 2016 Aug 31 ]

(2) Minor coding style fix for 2.2 in r62085. Please, review.

asaveljevs Thank you! CLOSED.

Comment by Ivo Kurzemnieks [ 2016 Aug 31 ]

TESTED,

but close (2) before merging.

Comment by Aleksandrs Saveljevs [ 2016 Aug 31 ]

Merged in pre-2.2.15rc1 r62105, pre-3.0.5rc1 r62107, and pre-3.2.0beta2 (trunk) r62109.

Comment by Aleksandrs Saveljevs [ 2016 Aug 31 ]

(3) We missed the new array syntax in 2.2 branch. Fixed that in 2.2 directly in r62120:

-    $hostInventory = [];
+    $hostInventory = array(); 

Verified by iivs. CLOSED.

Comment by Aleksandrs Saveljevs [ 2016 Aug 31 ]

(4) Documented API changes on the following pages:

iivs CLOSED

Generated at Thu Apr 25 19:11:05 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.