@Test public void testCollect() { collectionJob.setService("SNMP"); collectionJob.setNodeId(1); collectionJob.setNetInterface(localhost.getHostAddress()); collectionJob.addMetric(testMetric, destinations, "OnmsLocicMetricId"); collectionJob.setId("testing"); CollectionJob result = protocolCollector.collect(collectionJob); Assert.assertEquals(result.getService(), "SNMP"); Assert.assertEquals(result.getMetricValue(testMetric), testMetricValue); }
@Override public CollectionJob collect(final CollectionJob collectionJob) { logger.info("SnmpProtocolCollector is collecting collectionJob '{}'", collectionJob.getId()); SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration()); List<Collectable> trackers = new ArrayList<Collectable>(); for (final String metricObjId : collectionJob.getAllMetrics()) { SnmpObjId requestOid = SnmpObjId.get(metricObjId); SnmpObjId base = requestOid.getPrefix(requestOid.length()-1); int lastId = requestOid.getLastSubId(); SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) { @Override protected void storeResult(SnmpResult result) { logger.trace("Collected SnmpValue '{}'", result); SnmpValue value = result.getValue(); String metricType = value == null ? "unknown" : typeToString(value.getType()); collectionJob.setMetricValue(metricObjId, metricType, value == null ? null : value.toDisplayString()); } @Override public void setFailed(boolean failed) { super.setFailed(failed); logger.trace("Collection Failed for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } @Override public void setTimedOut(boolean timedOut) { super.setTimedOut(timedOut); logger.trace("Collection timedOut for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } }; trackers.add(instanceTracker); } CollectionTracker tracker = new AggregateTracker(trackers); SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker); walker.start(); try { walker.waitFor(); } catch (InterruptedException e) { } return collectionJob; }
SnmpProtocolCollector implements ProtocolCollector { @Override public CollectionJob collect(final CollectionJob collectionJob) { logger.info("SnmpProtocolCollector is collecting collectionJob '{}'", collectionJob.getId()); SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration()); List<Collectable> trackers = new ArrayList<Collectable>(); for (final String metricObjId : collectionJob.getAllMetrics()) { SnmpObjId requestOid = SnmpObjId.get(metricObjId); SnmpObjId base = requestOid.getPrefix(requestOid.length()-1); int lastId = requestOid.getLastSubId(); SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) { @Override protected void storeResult(SnmpResult result) { logger.trace("Collected SnmpValue '{}'", result); SnmpValue value = result.getValue(); String metricType = value == null ? "unknown" : typeToString(value.getType()); collectionJob.setMetricValue(metricObjId, metricType, value == null ? null : value.toDisplayString()); } @Override public void setFailed(boolean failed) { super.setFailed(failed); logger.trace("Collection Failed for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } @Override public void setTimedOut(boolean timedOut) { super.setTimedOut(timedOut); logger.trace("Collection timedOut for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } }; trackers.add(instanceTracker); } CollectionTracker tracker = new AggregateTracker(trackers); SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker); walker.start(); try { walker.waitFor(); } catch (InterruptedException e) { } return collectionJob; } }
SnmpProtocolCollector implements ProtocolCollector { @Override public CollectionJob collect(final CollectionJob collectionJob) { logger.info("SnmpProtocolCollector is collecting collectionJob '{}'", collectionJob.getId()); SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration()); List<Collectable> trackers = new ArrayList<Collectable>(); for (final String metricObjId : collectionJob.getAllMetrics()) { SnmpObjId requestOid = SnmpObjId.get(metricObjId); SnmpObjId base = requestOid.getPrefix(requestOid.length()-1); int lastId = requestOid.getLastSubId(); SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) { @Override protected void storeResult(SnmpResult result) { logger.trace("Collected SnmpValue '{}'", result); SnmpValue value = result.getValue(); String metricType = value == null ? "unknown" : typeToString(value.getType()); collectionJob.setMetricValue(metricObjId, metricType, value == null ? null : value.toDisplayString()); } @Override public void setFailed(boolean failed) { super.setFailed(failed); logger.trace("Collection Failed for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } @Override public void setTimedOut(boolean timedOut) { super.setTimedOut(timedOut); logger.trace("Collection timedOut for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } }; trackers.add(instanceTracker); } CollectionTracker tracker = new AggregateTracker(trackers); SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker); walker.start(); try { walker.waitFor(); } catch (InterruptedException e) { } return collectionJob; }  }
SnmpProtocolCollector implements ProtocolCollector { @Override public CollectionJob collect(final CollectionJob collectionJob) { logger.info("SnmpProtocolCollector is collecting collectionJob '{}'", collectionJob.getId()); SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration()); List<Collectable> trackers = new ArrayList<Collectable>(); for (final String metricObjId : collectionJob.getAllMetrics()) { SnmpObjId requestOid = SnmpObjId.get(metricObjId); SnmpObjId base = requestOid.getPrefix(requestOid.length()-1); int lastId = requestOid.getLastSubId(); SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) { @Override protected void storeResult(SnmpResult result) { logger.trace("Collected SnmpValue '{}'", result); SnmpValue value = result.getValue(); String metricType = value == null ? "unknown" : typeToString(value.getType()); collectionJob.setMetricValue(metricObjId, metricType, value == null ? null : value.toDisplayString()); } @Override public void setFailed(boolean failed) { super.setFailed(failed); logger.trace("Collection Failed for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } @Override public void setTimedOut(boolean timedOut) { super.setTimedOut(timedOut); logger.trace("Collection timedOut for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } }; trackers.add(instanceTracker); } CollectionTracker tracker = new AggregateTracker(trackers); SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker); walker.start(); try { walker.waitFor(); } catch (InterruptedException e) { } return collectionJob; }  SnmpStrategy getSnmpStrategy(); void setSnmpStrategy(SnmpStrategy snmpStrategy); @Override CollectionJob collect(final CollectionJob collectionJob); @Override String getProtcol(); }
SnmpProtocolCollector implements ProtocolCollector { @Override public CollectionJob collect(final CollectionJob collectionJob) { logger.info("SnmpProtocolCollector is collecting collectionJob '{}'", collectionJob.getId()); SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration()); List<Collectable> trackers = new ArrayList<Collectable>(); for (final String metricObjId : collectionJob.getAllMetrics()) { SnmpObjId requestOid = SnmpObjId.get(metricObjId); SnmpObjId base = requestOid.getPrefix(requestOid.length()-1); int lastId = requestOid.getLastSubId(); SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) { @Override protected void storeResult(SnmpResult result) { logger.trace("Collected SnmpValue '{}'", result); SnmpValue value = result.getValue(); String metricType = value == null ? "unknown" : typeToString(value.getType()); collectionJob.setMetricValue(metricObjId, metricType, value == null ? null : value.toDisplayString()); } @Override public void setFailed(boolean failed) { super.setFailed(failed); logger.trace("Collection Failed for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } @Override public void setTimedOut(boolean timedOut) { super.setTimedOut(timedOut); logger.trace("Collection timedOut for metricObjId '{}'", metricObjId); collectionJob.setMetricValue(metricObjId, "unknown", null); } }; trackers.add(instanceTracker); } CollectionTracker tracker = new AggregateTracker(trackers); SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker); walker.start(); try { walker.waitFor(); } catch (InterruptedException e) { } return collectionJob; }  SnmpStrategy getSnmpStrategy(); void setSnmpStrategy(SnmpStrategy snmpStrategy); @Override CollectionJob collect(final CollectionJob collectionJob); @Override String getProtcol();  }