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

Aggregate item. Each key parameter require * character for filtering

XMLWordPrintable

      In documentation we have Example #2 for formula:

      sum(last_foreach(/host/net.if.in[*]))
      

      https://www.zabbix.com/documentation/6.0/en/manual/config/items/itemtypes/calculated/aggregate

      But we do not show what searched item key it will match.
      Yes, the "net.if.in" requires one key mandatory parameter, which would work in this case. But if 2nd key parameter (optional) will be used - it will cause that the aggregated key will fail.

      Examples.
      Using formula for aggregated item:

      avg(last_foreach(/*/test.item[*]))
      

      Sending a value and debug log:

      # zabbix_sender -vv -z 127.0.0.1 -p 10051 -k 'test.item[some,foo]' -s it0 -o 555
      
      641103:20230811:144621.365 zbx_expression_eval_execute() expression:'avg(last_foreach(0))'
      641103:20230811:144621.365 In expression_init_query_many() /*/test.item[*]?[]
      641103:20230811:144621.365 query [txnlev:0] [select i.itemid,i.hostid,i.key_ from items i where i.key_ like 'test.item[%]']
      641103:20230811:144621.365 End of expression_init_query_many() items:0
      641103:20230811:144621.365 In expression_eval_history() function:last_foreach
      641103:20230811:144621.365 In expression_eval_many() last_foreach(/*/test.item[*]?[],...)
      641103:20230811:144621.365 End of expression_eval_many():SUCCEED value:double vector[0:0] flags:double vector
      641103:20230811:144621.365 End of expression_eval_history():SUCCEED error:
      641103:20230811:144621.365 End of zbx_expression_eval_execute():FAIL value: error:Cannot evaluate expression: no input data for function at "avg(last_foreach(/*/test.item[*]))"
      641103:20230811:144621.365 get_value_calculated() error:Cannot evaluate expression: no input data for function at "avg(last_foreach(/*/test.item[*]))"
      641103:20230811:144621.365 End of get_value_calculated():NOTSUPPORTED
      641103:20230811:144621.365 Item [it0:caclagrr] error: Cannot evaluate expression: no input data for function at "avg(last_foreach(/*/test.item[*]))"
      641103:20230811:144621.365 End of get_value():NOTSUPPORTED
      

      so, it failed, while actually the SQL really gets the searched item from DB!, while it's actually not visible in the debug:

      mysql> select i.itemid,i.hostid,i.key_ from items i where i.key_ like 'test.item[%]';
      +--------+--------+---------------------+
      | itemid | hostid | key_                |
      +--------+--------+---------------------+
      |  42741 |  10516 | test.item[some,foo] |
      +--------+--------+---------------------+
      

      Changing formula to (we do not have such doc examples!):
      Using formula for aggregated item:

      avg(last_foreach(/*/test.item[*,*]))
      

      result:

      # zabbix_sender -vv -z 127.0.0.1 -p 10051 -k 'test.item[some,foo]' -s it0 -o 555
      
      641103:20230811:144941.524 zbx_expression_eval_execute() expression:'avg(last_foreach(0))'
      641103:20230811:144941.524 In expression_init_query_many() /*/test.item[*,*]?[]
      641103:20230811:144941.524 query [txnlev:0] [select i.itemid,i.hostid,i.key_ from items i where i.key_ like 'test.item[%,%]']
      641103:20230811:144941.524 expression_init_query_many() itemid:42741
      641103:20230811:144941.524 End of expression_init_query_many() items:1
      641103:20230811:144941.524 In expression_eval_history() function:last_foreach
      641103:20230811:144941.524 In expression_eval_many() last_foreach(/*/test.item[*,*]?[],...)
      641103:20230811:144941.524 In zbx_vc_get_values() itemid:42741 value_type:3 count:1 period:0 end_timestamp '2023.08.11 14:49:41.524161779'
      641103:20230811:144941.524 End of zbx_vc_get_values():SUCCEED count:1 cached:1
      641103:20230811:144941.524 End of expression_eval_many():SUCCEED value:double vector[0:1] flags:double vector
      641103:20230811:144941.524 End of expression_eval_history():SUCCEED error:
      641103:20230811:144941.524 End of zbx_expression_eval_execute():SUCCEED value:555 error:
      641103:20230811:144941.524 get_value_calculated() value:555
      641103:20230811:144941.524 End of get_value_calculated():SUCCEED
      641103:20230811:144941.524 End of get_value():SUCCEED
      

      we see SQLs is slightly different (not a key point) but now C code in functions expression_init_query_many and/or expression_get_item_candidates handles it correctly and works!

      Conclusion:
      If we do not want to fix that in C code, we have to adjust our documentation plus provide such example.

      In doc state cleanly that:
      1. Each item key parameter requires its own wildcard character *, separated by comma, as in searched original key.
      2. Wildcard character * works only for whole key parameter, not for its part.

      p.s. I've tried to do it for part of key parameter - it fails, because prepared SQL is not correct to find such item:

      641103:20230811:145751.944 In get_value_calculated() key:'caclagrr' expression:'avg(last_foreach(/*/test.item[packetloss,isp*]))'
      641103:20230811:145751.944 In zbx_expression_eval_init()
      641103:20230811:145751.944 End of zbx_expression_eval_init()
      641103:20230811:145751.944 In substitute_simple_macros_impl() data:EMPTY
      641103:20230811:145751.944 In zbx_expression_eval_execute()
      641103:20230811:145751.944 zbx_expression_eval_execute() expression:'avg(last_foreach(0))'
      641103:20230811:145751.944 In expression_init_query_many() /*/test.item[packetloss,isp*]?[]
      641103:20230811:145751.944 query [txnlev:0] [select i.itemid,i.hostid from items i where i.key_='test.item[packetloss,isp*]']
      641103:20230811:145751.944 End of expression_init_query_many() items:0
      641103:20230811:145751.944 In expression_eval_history() function:last_foreach
      641103:20230811:145751.944 In expression_eval_many() last_foreach(/*/test.item[packetloss,isp*]?[],...)
      641103:20230811:145751.944 End of expression_eval_many():SUCCEED value:double vector[0:0] flags:double vector
      641103:20230811:145751.944 End of expression_eval_history():SUCCEED error:
      641103:20230811:145751.944 End of zbx_expression_eval_execute():FAIL value: error:Cannot evaluate expression: no input data for function at "avg(last_foreach(/*/test.item[packetloss,isp*]))"
      641103:20230811:145751.944 get_value_calculated() error:Cannot evaluate expression: no input data for function at "avg(last_foreach(/*/test.item[packetloss,isp*]))"
      641103:20230811:145751.944 End of get_value_calculated():NOTSUPPORTED
      641103:20230811:145751.944 Item [it0:caclagrr] error: Cannot evaluate expression: no input data for function at "avg(last_foreach(/*/test.item[packetloss,isp*]))"
      641103:20230811:145751.944 End of get_value():NOTSUPPORTED
      

            zabbix.dev Zabbix Development Team
            zalex_ua Oleksii Zagorskyi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: