Ad Widget

Collapse

Howto set host inventory mode using the api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lynggaard
    Junior Member
    • Sep 2012
    • 11

    #1

    Howto set host inventory mode using the api

    Hi

    I can't seem to figure out how to set the host inventory mode when creating hosts using the API.

    I can specify host inventory fields, which seems to set the mode to manual, but if a use "inventory_mode" as one of the fields I get told that is not allowed.

    SO how do I set host inventory mode to automatic ?
  • Pavels
    Member
    • Oct 2011
    • 83

    #2
    Can you give an example of the request you make to update the inventory mode?

    Comment

    • lynggaard
      Junior Member
      • Sep 2012
      • 11

      #3
      Example request

      ZabbixAPIException(msg, jobj['error']['code'])
      zabbix.zabbix_api.ZabbixAPIException: (u'Error -32602: Invalid params., Incorrect inventory field "inventory_mode". while sending

      {"params": {
      "templates": [ {"templateid": "10001"}],
      "interfaces": [{"ip": "10.8.36.91", "useip": 1, "dns": "www.example.com", "main": 1, "type": 1, "port": 10050}],
      "macros": [],
      "host": "www.example.com",
      "inventory": {
      "inventory_mode": 1,
      "notes": "my notes",
      "tag": "dev",
      "installer_name": "Kokki at 2012-11-02_13-15-12"
      },
      "groups": [{"internal": "0", "groupid": "13", "name": "Project: RCM"}]
      }, "jsonrpc": "2.0", "method": "host.create", "auth": "66d2a264b0e230d997c5567fba69ea5f", "id": 5}', -32602)

      I have also tried setting host_inventory on the host object itself but that was not any better

      Comment

      • Pavels
        Member
        • Oct 2011
        • 83

        #4
        There's a tricky thing with inventory_mode that hasn't been documented yet: although inventory_mode is a property of the host_inventory object, when calling host.update or host.create it needs to be passed with the host objects.

        Also, you don't need to pass the whole host group, only the groupid property is required.

        The following request will work:

        Code:
        {
            "templates": [
                {
                    "templateid": "10001"
                }
            ],
            "interfaces": [
                {
                    "ip": "10.8.36.91",
                    "useip": 1,
                    "dns": "www.example.com",
                    "main": 1,
                    "type": 1,
                    "port": 10050
                }
            ],
            "macros": [],
            "host": "www.example.com",
            "inventory_mode": 1,
            "inventory": {
                "notes": "my notes",
                "tag": "dev",
                "installer_name": "Kokki at 2012-11-02_13-15-12"
            },
            "groups": [
                {
                    "groupid": "13"
                }
            ]
        }

        Comment

        • alyssenko
          Junior Member
          • Dec 2015
          • 6

          #5
          I know this is an old thread but I'm running into the same issue as OP when working with the Zabbix API.

          I'm able to add the host via the API but I can't get host_inventory set to 'automatic', instead it defaults to 'disabled' even though I set it to "1" (automatic) as shown below:

          Code:
          curl -i -X POST -H 'Content-Type:application/json' -d'{"jsonrpc":"2.0","method":"host.create","params":{"host":"'$host'","interfaces":[{"type":1,"main":1,"useip":1,"ip":"'$hostip'","dns":"","port":"10050"}],"groups":[{"groupid":2}],"templates":[{"templateid":"'$templateid'"}],"inventory_mode":1},"auth":"'$authtoken'","id":0}' $api
          Any help or insight would be much appreciated- thanks.

          Comment

          • alyssenko
            Junior Member
            • Dec 2015
            • 6

            #6
            Originally posted by alyssenko
            I know this is an old thread but I'm running into the same issue as OP when working with the Zabbix API.

            I'm able to add the host via the API but I can't get host_inventory set to 'automatic', instead it defaults to 'disabled' even though I set it to "1" (automatic) as shown below:

            Code:
            curl -i -X POST -H 'Content-Type:application/json' -d'{"jsonrpc":"2.0","method":"host.create","params":{"host":"'$host'","interfaces":[{"type":1,"main":1,"useip":1,"ip":"'$hostip'","dns":"","port":"10050"}],"groups":[{"groupid":2}],"templates":[{"templateid":"'$templateid'"}],"inventory_mode":1},"auth":"'$authtoken'","id":0}' $api
            Any help or insight would be much appreciated- thanks.
            I was able to resolve by simply specifying manual host inventory.

            Comment

            Working...