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

about some questions in lld_remove_lost_items function

    XMLWordPrintable

Details

    • Documentation task
    • Status: Closed
    • Trivial
    • Resolution: Commercial support required
    • 4.0.27rc1
    • None
    • Server (S)
    • None
    • Team A
    • Sprint 74 (Mar 2021)

    Description

      I don't understand the follow red code:

      static void lld_remove_lost_items(const zbx_vector_ptr_t *items, int lifetime, int lastcheck)
      {
      char *sql = NULL;
      size_t sql_alloc = 0, sql_offset = 0;
      zbx_lld_item_t *item;
      zbx_vector_uint64_t del_itemids, lc_itemids, ts_itemids;
      zbx_vector_uint64_pair_t discovery_itemts;
      int i;

      zabbix_log(LOG_LEVEL_DEBUG, "In %s()", _func_);

      if (0 == items->values_num)
      goto out;

      zbx_vector_uint64_create(&del_itemids);
      zbx_vector_uint64_create(&lc_itemids);
      zbx_vector_uint64_create(&ts_itemids);
      zbx_vector_uint64_pair_create(&discovery_itemts);

      for (i = 0; i < items->values_num; i++)
      {
      item = (zbx_lld_item_t *)items->values[i];

      if (0 == item->itemid)
      continue;
       

      ###flags =0 is the plain item,ZBX_FLAG_LLD_ITEM_DISCOVERED is 1,so only when flags =0,the if condition is true and execute the if code?
      if (0 == (item->flags & ZBX_FLAG_LLD_ITEM_DISCOVERED))
      {
      int ts_delete = lld_end_of_life(item->lastcheck, lifetime);

      if (lastcheck > ts_delete)
      {
      zbx_vector_uint64_append(&del_itemids, item->itemid);
      {color:#de350b}}*
      *else if (item->ts_delete != ts_delete)

      {
      zbx_uint64_pair_t itemts;

      itemts.first = item->itemid;
      itemts.second = ts_delete;
      zbx_vector_uint64_pair_append(&discovery_itemts, itemts);
      {color:#de350b}}*
      *}

      else

      { zbx_vector_uint64_append(&lc_itemids, item->itemid); if (0 != item->ts_delete) zbx_vector_uint64_append(&ts_itemids, item->itemid); }

      }

      if (0 == discovery_itemts.values_num && 0 == lc_itemids.values_num && 0 == ts_itemids.values_num &&
      0 == del_itemids.values_num)

      { goto clean; }

      /* update item discovery table */

      DBbegin();

      DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset);

      for (i = 0; i < discovery_itemts.values_num; i++)

      { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update item_discovery" " set ts_delete=%d" " where itemid=" ZBX_FS_UI64 ";\n", (int)discovery_itemts.values[i].second, discovery_itemts.values[i].first); DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset); }

      if (0 != lc_itemids.values_num)

      { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update item_discovery set lastcheck=%d where", lastcheck); DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "itemid", lc_itemids.values, lc_itemids.values_num); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, ";\n"); DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset); }

      if (0 != ts_itemids.values_num)

      { zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "update item_discovery set ts_delete=0 where"); DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "itemid", ts_itemids.values, ts_itemids.values_num); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, ";\n"); DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset); }

      DBend_multiple_update(&sql, &sql_alloc, &sql_offset);

      if (16 < sql_offset) /* in ORACLE always present begin..end; */
      DBexecute("%s", sql);

      zbx_free(sql);

      /* remove 'lost' items */
      if (0 != del_itemids.values_num)

      { zbx_vector_uint64_sort(&del_itemids, ZBX_DEFAULT_UINT64_COMPARE_FUNC); DBdelete_items(&del_itemids); }

      DBcommit();
      clean:
      zbx_vector_uint64_pair_destroy(&discovery_itemts);
      zbx_vector_uint64_destroy(&ts_itemids);
      zbx_vector_uint64_destroy(&lc_itemids);
      zbx_vector_uint64_destroy(&del_itemids);
      out:
      zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", _func_);
      }

      Attachments

        Activity

          People

            vso Vladislavs Sokurenko
            smith2020 smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: