Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-6758

Throw exception/error if DBExecute() fails in api/classes/CHost.php when creating new host

    XMLWordPrintable

Details

    • Incident report
    • Status: Closed
    • Trivial
    • Resolution: Won't fix
    • 2.0.6
    • None
    • API (A)

    Description

      In the following example JSON the inventory is provided as an array in stead of an object.
      This breaks CHost->create() in:

          if (isset($host['inventory']) && !empty($host['inventory'])) {
              $fields = array_keys($host['inventory']);
              $fields[] = 'inventory_mode';
              $fields = implode(', ', $fields);
              
              $values = array_map('zbx_dbstr', $host['inventory']);
              $values[] = isset($host['inventory_mode']) ? $host['inventory_mode'] : HOST_INVENTORY_MANUAL;
              $values = implode(', ', $values);
              
              DBexecute('INSERT INTO host_inventory (hostid, '.$fields.') VALUES ('.$hostid.', '.$values.')');
          }
      

      DBexecute fails because $fields and $values contain: "0, Array" instead of the data that's provided in the inventory array.
      An error should be thrown here.

      Example JSON

      {
       "jsonrpc": "2.0",
           "method": "host.create",
           "params": {
               "host": "example.tld",
               "name":"example",
               "interfaces": [
                   {
                       "type": 2,
                       "main": 1,
                       "useip": 0,
                       "ip": "192.0.2.1",
                       "dns": "example.tld",
                       "port": "161"
                   }
               ],
               "groups": [
                   {
                       "groupid": "200200000000014"
                   }
               ],
               "templates": [
                   {
                       "templateid": "200200000010086"
                   }
               ],
               "inventory": [
                   {
                   "macaddress_a": "01234"
                   }
               ]
           },
           "auth": "95c673430adb1644fdc6734e602988ec",
           "id": 1
       }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            twouters Thomas Wouters
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: