SNMP Agent plugin: Fix - not every OID is unregistered from snmp table
authorMozejko, MarcinX <marcinx.mozejko@intel.com>
Tue, 27 Feb 2018 09:54:13 +0000 (09:54 +0000)
committerMozejko, MarcinX <marcinx.mozejko@intel.com>
Mon, 4 Jun 2018 15:14:47 +0000 (08:14 -0700)
Problem occures when a metric has more than one OID assigned. Then,
during the table unregistration, plugin thinks that there are some OIDs
left in the table and keeps index keys also registered. It's because
plugin registers all the OIDs for the particular metric, but unregisters only
the first one which is wrong.

Change-Id: I6daae1ceeebf30b98f22075940b29936ee3d110d
Signed-off-by: Mozejko, MarcinX <marcinx.mozejko@intel.com>
src/snmp_agent.c

index bbc4dcd..8f556d8 100644 (file)
@@ -671,15 +671,20 @@ static void snmp_agent_table_data_remove(data_definition_t *dd,
 
   pthread_mutex_lock(&g_agent->agentx_lock);
 
 
   pthread_mutex_lock(&g_agent->agentx_lock);
 
+  int reg_oids = -1; /* Number of registered oids for given instance */
+
   for (size_t i = 0; i < dd->oids_len; i++) {
     if (td->index_oid.oid_len)
       snmp_agent_unregister_oid_index(&dd->oids[i], *index);
     else
       snmp_agent_unregister_oid_string(&dd->oids[i], index_oid);
   for (size_t i = 0; i < dd->oids_len; i++) {
     if (td->index_oid.oid_len)
       snmp_agent_unregister_oid_index(&dd->oids[i], *index);
     else
       snmp_agent_unregister_oid_string(&dd->oids[i], index_oid);
+
+    reg_oids =
+        snmp_agent_update_instance_oids(td->instance_oids, index_oid, -1);
   }
 
   /* Checking if any metrics are left registered */
   }
 
   /* Checking if any metrics are left registered */
-  if (snmp_agent_update_instance_oids(td->instance_oids, index_oid, -1) > 0) {
+  if (reg_oids != 0) {
     pthread_mutex_unlock(&g_agent->agentx_lock);
     return;
   }
     pthread_mutex_unlock(&g_agent->agentx_lock);
     return;
   }