Ad Widget

Collapse

API calls return empty Inventory array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Law
    Junior Member
    • Feb 2021
    • 15

    #1

    API calls return empty Inventory array

    Hi Everyone,

    I've been trying to request inventory asset tag data with the API but i keey getting empty arrays. Does anyone else get this issue or am i doing something wrong?
    i keep getting empty arrays, no matter what inventory field i try to request.

    PHP Code

    PHP Code:
    function RequestServers($Server){
        global 
    $AuthKey;
        
    $url "https://$Server/zabbix/api_jsonrpc.php";
      
        
    $headers = array();
        
    $headers[] = "Content-Type: application/json";
        
    $POSTdata = array();
        
    $POSTdata["method"] = "host.get";
        
    $POSTdata["jsonrpc"] = "2.0";
        
    $POSTdata["id"] = 2;
        
    $POSTdata["auth"] = $AuthKey;
        
    $POSTdata["params"]["output"] = "extend";
        
    $POSTdata["params"]["selectInventory"] = "asset_tag";
        
    $POSTjson json_encode($POSTdata);
        
    $ArrResponse APIcallPOST($url$headers$POSTjson);
        
    $data $ArrResponse;
      
        return 
    $data;
    }
    ​ 
    Returned data for 1 server (Json), inventory array is at the back of the data:
    Code:
    [0]=> array(27) { ["hostid"]=> string(5) "10352" ["proxy_hostid"]=> string(5) "10326" ["host"]=> string(11) "V-ADConnect" ["status"]=> string(1) "1" ["lastaccess"]=> string(1) "0" ["ipmi_authtype"]=> string(2) "-1" ["ipmi_privilege"]=> string(1) "2" ["ipmi_username"]=> string(0) "" ["ipmi_password"]=> string(0) "" ["maintenanceid"]=> string(1) "0" ["maintenance_status"]=> string(1) "0" ["maintenance_type"]=> string(1) "0" ["maintenance_from"]=> string(1) "0" ["name"]=> string(11) "V-ADConnect" ["flags"]=> string(1) "0" ["templateid"]=> string(1) "0" ["description"]=> string(24) "word opgekuist binnekort" ["tls_connect"]=> string(1) "1" ["tls_accept"]=> string(1) "1" ["tls_issuer"]=> string(0) "" ["tls_subject"]=> string(0) "" ["proxy_address"]=> string(0) "" ["auto_compress"]=> string(1) "1" ["custom_interfaces"]=> string(1) "0" ["uuid"]=> string(0) "" ["inventory_mode"]=> string(1) "0" [B]["inventory"]=> array(0) { }[/B] }
    Last edited by Martin Law; 07-10-2022, 16:55.
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1782

    #2
    This is in Python but shows your problem:

    >>> host = zapi.host.get(filter={"host":"Testhost"}, output="extend", selectInventory="asset_tag")[0]
    >>> host["inventory"]
    []


    ​= selectInventory set to a string "asset_tag" causes the call to return empty inventory.

    But:

    >>> host = zapi.host.get(filter={"host":"Testhost"}, output="extend", selectInventory=["asset_tag"])[0]
    >>> host["inventory"]
    {'asset_tag': 'testing'}


    ​= selectInventory set to a list of strings causes it to return the correct inventory property.

    Markku

    Comment

    • Martin Law
      Junior Member
      • Feb 2021
      • 15

      #3
      Hi Markku,

      That works indeed, thanks for the tip.
      So the inventory items need to be listed in an array instead of a string.

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        Originally posted by Martin Law
        Hi Markku,

        That works indeed, thanks for the tip.
        So the inventory items need to be listed in an array instead of a string.
        selectInventory query Return an inventory property with host inventory data.

        It returns whole inventory (query), so it is an array... you just need to select, which fields you need to be shown... you can return multiple inventory values at once with this, if you specify multiple values to be returned...

        Comment

        Working...