use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpPeerFactoryTest method testGetConfigWithValidLocation.
/**
* Below tests for a valid/invalid location match
*
* @throws UnknownHostException
*/
public void testGetConfigWithValidLocation() throws UnknownHostException {
SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("192.168.0.50"), "MINION");
assertNotNull(agentConfig);
assertEquals(agentConfig.getVersion(), SnmpAgentConfig.VERSION2C);
assertEquals(2500, agentConfig.getTimeout());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class ConfigureSnmpTest method testSnmpEventInfoClassWithRangeSuperSettingDefRanges.
/**
* Tests getting the correct SNMP Peer after merging a new range that super sets a current range.
*
* @throws UnknownHostException
*/
public void testSnmpEventInfoClassWithRangeSuperSettingDefRanges() throws UnknownHostException {
final String addr1 = "192.168.99.1";
final String addr2 = "192.168.108.254";
SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
assertEquals(SnmpAgentConfig.VERSION1, agent.getVersion());
EventBuilder bldr = createConfigureSnmpEventBuilder(addr1, addr2);
SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
info.setReadCommunityString("opennmsrules");
SnmpPeerFactory.getInstance().define(info);
agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
assertEquals(InetAddressUtils.str(agent.getAddress()), addr1);
assertEquals(SnmpAgentConfig.VERSION1, agent.getVersion());
assertEquals(m_startingDefCount, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().size());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class ConfigureSnmpTest method testSnmpEventInfoClassWithRangeReplacingSpecific.
/**
* This test should remove the specific 192.168.0.5 from the first definition and
* replace it with a range 192.168.0.5 - 192.168.0.7.
*
* @throws UnknownHostException
*/
public void testSnmpEventInfoClassWithRangeReplacingSpecific() throws UnknownHostException {
final String addr1 = "192.168.0.5";
final String addr2 = "192.168.0.7";
SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
assertEquals(SnmpAgentConfig.VERSION2C, agent.getVersion());
EventBuilder bldr = createConfigureSnmpEventBuilder(addr1, addr2);
SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
info.setVersion("v2c");
SnmpPeerFactory.getInstance().define(info);
agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
assertEquals(InetAddressUtils.str(agent.getAddress()), addr1);
assertEquals(SnmpAgentConfig.VERSION2C, agent.getVersion());
assertEquals(m_startingDefCount, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().size());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class TcaDataIT method testTracker.
/**
* Test tracker.
*
* @throws Exception the exception
*/
@Test
public void testTracker() throws Exception {
InetAddress localhost = InetAddressUtils.getInetAddress(TEST_IP_ADDRESS);
SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(localhost);
TcaData data = new TcaData(localhost);
try (SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "TcaCollector for " + localhost, data)) {
walker.start();
walker.waitFor();
Assert.assertFalse(walker.failed());
}
Assert.assertFalse(data.isEmpty());
Assert.assertEquals(2, data.getEntries().size());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class TcaProtocolCollector method collect.
@Override
public CollectionJob collect(final CollectionJob collectionJob) {
logger.info("TcaProtocolCollector is collecting collectionJob '{}'", collectionJob);
SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration());
List<Collectable> trackers = new ArrayList<>();
for (final String metricObjId : collectionJob.getAllMetrics()) {
final String keyword = metricObjId.substring(metricObjId.lastIndexOf("_") + 1);
final SnmpObjId requestOid = SnmpObjId.get(metricObjId.substring(0, metricObjId.lastIndexOf("_")));
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 compositeResult = getCompositeValue(keyword, value.toDisplayString());
collectionJob.setMetricValue(metricObjId, "int32", compositeResult);
}
@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);
try (SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker)) {
walker.start();
try {
walker.waitFor();
} catch (InterruptedException e) {
logger.error("Interuppted while waiting for collector. Results may be incomplete.", e);
}
}
return collectionJob;
}
Aggregations