Table iterator

From Net-SNMP Wiki
Jump to: navigation, search
Net-SNMP MIB Helper
Table Iterator
Documentation: doxygen API
Code: agent/helpers/table_iterator.c
Other Helpers: Agent Helpers

Table Iterator Helper


This handler calls user specified functions to iterate over a (generally unsorted) set of data, looking for the data to satisfy an incoming request.

Note: the Table Iterator Helper is a child-helper of the table helper. You might want to read its documentation as well.

Pros and Cons


  • It's very easy to implement a wrapper using it.
  • You don't need to worry about sorting your data properly, the table_itator does this for you.


  • The iterator helper will iterate through all the rows for each individual request which isn't very efficient.

Con Mitigation

  • If your data is sorted properly for SNMP already, set the NETSNMP_ITERATOR_FLAG_SORTED flag in the netsnmp_iterator_info's flags. Also be sure you are looking up the right data point when a hint is passed in your get_first_data_point function.
  • Inject a stash_cache helper, which is extremely efficient and fast at the expense of memory.

Tips and Tricks

Transient Data

If you are concerned that the data you are iterating over will change or vanish between the time the iterator functions are called and the time the handler is called to process a request, but you don't want to cache all your data, then there is an itermediate option.

If you provide a make_data_context function when you register the table, that function will be called with the loop_context for a row each time the agent determines that the current row is the best match. When the agent is done with the row, the free_data_context function will be called to release the data.