Alejandro Galue avatar Alejandro Galue committed 603f6ad

Fix for Bug NMS-5710

Comments (0)

Files changed (1)


 import java.lang.reflect.UndeclaredThrowableException;
+import java.util.HashMap;
 import java.util.Map;
 import org.apache.log4j.Level;
 import org.opennms.netmgt.poller.DistributionContext;
 import org.opennms.netmgt.poller.MonitoredService;
 import org.opennms.netmgt.poller.NetworkInterface;
+import org.opennms.netmgt.snmp.RowCallback;
 import org.opennms.netmgt.snmp.SnmpAgentConfig;
 import org.opennms.netmgt.snmp.SnmpInstId;
 import org.opennms.netmgt.snmp.SnmpObjId;
+import org.opennms.netmgt.snmp.SnmpRowResult;
 import org.opennms.netmgt.snmp.SnmpUtils;
 import org.opennms.netmgt.snmp.SnmpValue;
+import org.opennms.netmgt.snmp.SnmpWalker;
+import org.opennms.netmgt.snmp.TableTracker;
 import antlr.StringUtils;
  * This does SNMP and therefore relies on the SNMP configuration so it is not distributable.
  * </p>
+ * Feature Added (2013-01-23):
+ *
+ * <p>This class uses TableTracker to request multiple columns at once and avoid possible problems,
+ * if the table is re-indexed at the moment is being collected, which is a problem with volatile
+ * services, or service with several forks like crond.</p>
+ *
  * @author <A HREF="">Tarus Balog </A>
+ * @author <A HREF="">Alejandro Galue </A>
  * @author <A HREF="">OpenNMS </A>
                 return status;
-            // This returns two maps: one of instance and service name, and one of instance and status.
-            Map<SnmpInstId, SnmpValue> nameResults = SnmpUtils.getOidValues(agentConfig, "HostResourceSwRunMonitor", SnmpObjId.get(serviceNameOid));
-            Map<SnmpInstId, SnmpValue> statusResults = SnmpUtils.getOidValues(agentConfig, "HostResourceSwRunMonitor", SnmpObjId.get(serviceStatusOid));
+            // This updates two maps: one of instance and service name, and one of instance and status.
+            final SnmpObjId serviceNameOidId = SnmpObjId.get(serviceNameOid);
+            final SnmpObjId serviceStatusOidId = SnmpObjId.get(serviceStatusOid);
+            final Map<SnmpInstId, SnmpValue> nameResults = new HashMap<SnmpInstId, SnmpValue>();
+            final Map<SnmpInstId, SnmpValue> statusResults = new HashMap<SnmpInstId, SnmpValue>();
+            RowCallback callback = new RowCallback() {
+                @Override
+                public void rowCompleted(SnmpRowResult result) {
+                    nameResults.put(result.getInstance(), result.getValue(serviceNameOidId));
+                    statusResults.put(result.getInstance(), result.getValue(serviceStatusOidId));
+                }
+            };
+            TableTracker tracker = new TableTracker(callback, serviceNameOidId, serviceStatusOidId);
+            SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "HostResourceSwRunMonitor", tracker);
+            walker.start();
+            walker.waitFor();
             // Iterate over the list of running services
             for(SnmpInstId nameInstance : nameResults.keySet()) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.