+static int snmp_agent_fill_index_list(table_definition_t const *td,
+ value_list_t const *vl) {
+ int ret;
+ netsnmp_variable_list *key = td->index_list_cont;
+
+ for (int i = 0; i < td->indexes_len; i++) {
+ /* var should never be NULL */
+ assert(key != NULL);
+ /* Generating list filled with all data necessary to generate an OID */
+ switch (td->indexes[i]) {
+ case INDEX_HOST:
+ ret = snmp_set_var_value(key, vl->host, strlen(vl->host));
+ break;
+ case INDEX_PLUGIN:
+ ret = snmp_set_var_value(key, vl->plugin, strlen(vl->plugin));
+ break;
+ case INDEX_PLUGIN_INSTANCE:
+ ret = snmp_set_var_value(key, vl->plugin_instance,
+ strlen(vl->plugin_instance));
+ break;
+ case INDEX_TYPE:
+ ret = snmp_set_var_value(key, vl->type, strlen(vl->type));
+ break;
+ case INDEX_TYPE_INSTANCE:
+ ret =
+ snmp_set_var_value(key, vl->type_instance, strlen(vl->type_instance));
+ break;
+ default:
+ ERROR(PLUGIN_NAME ": Unknown index key type provided");
+ return -EINVAL;
+ }
+ if (ret != 0)
+ return -EINVAL;
+ key = key->next_variable;
+ }
+ return 0;
+}
+
+static int snmp_agent_prep_index_list(table_definition_t const *td,
+ netsnmp_variable_list **index_list) {
+ /* Generating list having only the structure (with no values) letting us
+ * know how to parse an OID */
+ for (int i = 0; i < td->indexes_len; i++) {
+ switch (td->indexes[i]) {
+ case INDEX_HOST:
+ case INDEX_PLUGIN:
+ case INDEX_PLUGIN_INSTANCE:
+ case INDEX_TYPE:
+ case INDEX_TYPE_INSTANCE:
+ snmp_varlist_add_variable(index_list, NULL, 0, ASN_OCTET_STR, NULL, 0);
+ break;
+ default:
+ ERROR(PLUGIN_NAME ": Unknown index key type provided");
+ return -EINVAL;
+ }
+ }
+ return 0;
+}
+
+static int snmp_agent_generate_index(table_definition_t const *td,
+ value_list_t const *vl, oid_t *index_oid) {
+
+ /* According to given information by indexes list
+ * index OID is going to be built
+ */
+ int ret = snmp_agent_fill_index_list(td, vl);
+ if (ret != 0)
+ return -EINVAL;