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

Host prototypes are sometimes lost during import

XMLWordPrintable

    • Icon: Problem report Problem report
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • None
    • 4.0.11rc1, 4.2.5rc1
    • API (A)

      This is not a 100% visibly reproducible, because sometimes returned objects in import referencer are correct and it just looks like it works, however there is a problem in function selectHostPrototypes(). It returns too much data and the list of host prototypes may be incorrect. The query there asks for more that one host/template and gets confused in the process of joining three tables.

      Here's how I could reproduce this all the time (but not with other hosts/templates)
      1. Create a template with few host prototypes like {#HP1}, {#HP2}, {#HP3}
      2. Create a host with few host prototypes like {#HP1}, {#HP2}, {#HP3}
      3. Export host and template.
      4. Merge both hosts and templates into one XML (no linkage).
      5. Change host prototypes names {#HP1} to {#HP0} on both host and template.
      6a. Select "Create new" and "Delete missing" (no updating).
      6b (possibly same issue). For discovery rules select "Update existing", but for other objects leave"Create new" and "Delete missing".

      Result a): host prototypes on template are not added, only deleted, but host prototypes on host are added and deleted. Sometimes it deletes only one host prototype from template, sometimes both, sometimes none. Depends on how lucky the query in function selectHostPrototypes() executed and what it returned in results.
      Result b): Invalid parameter "/3": value (hostid)=(10640) already exists. [conf.import.php:167 ? CFrontendApiWrapper->import() ? CApiWrapper->__call() ? CFrontendApiWrapper->callMethod() ? CApiWrapper->callMethod() ? CFrontendApiWrapper->callClientMethod() ? CLocalApiClient->callMethod() ? call_user_func_array() ? CConfiguration->import() ? CConfigurationImport->import() ? CConfigurationImport->processDiscoveryRules() ? CHostPrototype->update() ? CHostPrototype->validateUpdate() ? CApiService::exception() in include\classes\api\services\CHostPrototype.php:333] For some reason it tries to create a host prototype again. Could be of that incorrect reference list. Doesn't return data it should, thus tries to create it as a new host prototype and fails.

      So the function tries to execute a query that looks like this:

      SELECT h.host,h.hostid,hd.parent_itemid,i.hostid AS parent_hostid
      FROM hosts h,host_discovery hd,items i
      WHERE h.hostid=hd.hostid AND hd.parent_itemid=i.itemid
      AND (hd.parent_itemid='76494' AND (h.host IN ('HOST {#HP0}','HOST {#HP2}','HOST {#HP3}'))) 
      OR (hd.parent_itemid='76449' AND (h.host IN ('HOST {#HP0}','HOST {#HP2}','HOST {#HP3}')))
      

      which returns...who knows what. If we would have one host without OR it works fine, but if there's more than one, then results are unpredictable.

      Using LEFT JOIN instead FROM solves this problem of selecting correct host prototypes.

            zabbix.dev Zabbix Development Team
            iivs Ivo Kurzemnieks
            Team B
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: