use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class MockSnmpStrategyTest method testSetSingleValue.
@Test
public void testSetSingleValue() throws Exception {
m_strategy.set(getAgentConfig(), SnmpObjId.get(".1.3.5.1.1.3.0"), m_strategy.getValueFactory().getInt32(4));
final SnmpValue result = m_strategy.get(getAgentConfig(), SnmpObjId.get(".1.3.5.1.1.3.0"));
assertNotNull(result);
assertEquals(4, result.toInt());
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class LocationAwareSnmpClientIT method canGetIpAddressTableEntriesViaCurrentLocation.
/**
* Verifies that SNMP GETs are successful, and return the same results when using
* the LocationAwareSnmpClient.
*/
@Test
public void canGetIpAddressTableEntriesViaCurrentLocation() throws UnknownHostException, InterruptedException, ExecutionException {
SnmpValue result = locationAwareSnmpClient.get(agentConfig, SnmpObjId.get(".1.3.6.1.2.1.4.34.1.3.1.4.127.0.0.1")).execute().get();
assertEquals(1, result.toInt());
result = locationAwareSnmpClient.get(agentConfig, SnmpObjId.get(".1.3.6.1.2.1.4.34.1.3.1.4.172.17.0.1")).execute().get();
assertEquals(7, result.toInt());
result = locationAwareSnmpClient.get(agentConfig, SnmpObjId.get(".1.3.6.1.2.1.4.34.1.5.1.4.127.0.0.1")).execute().get();
assertEquals(SnmpObjId.get(".1.3.6.1.2.1.4.32.1.5.1.1.4.127.0.0.0.8"), result.toSnmpObjId());
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class TcaCollectorIT method testCollector.
/**
* Test collector.
*
* @throws Exception the exception
*/
@Test
public void testCollector() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "default");
// Create Collection Set
TcaCollector collector = new TcaCollector();
collector.setConfigDao(m_configDao);
collector.setResourceStorageDao(m_resourceStorageDao);
collector.setResourceTypesDao(m_resourceTypesDao);
collector.setLocationAwareSnmpClient(m_client);
CollectionSetVisitor persister = m_persisterFactory.createOneToOnePersister(new ServiceParameters(parameters), collector.getRrdRepository("default"), false, false);
// Setup SNMP Value Handling
SnmpValueFactory valFac = SnmpUtils.getValueFactory();
SnmpObjId peer1 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.37.60");
SnmpObjId peer2 = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2.171.19.38.70");
// Collect and Persist Data - Step 1
CollectionSet collectionSet = collector.collect(m_collectionAgent, parameters);
validateCollectionSet(collectionSet);
collectionSet.visit(persister);
// Generate new SNMP Data
StringBuffer sb = new StringBuffer("|25|");
long ts = 1327451787l;
for (int i = 0; i < 25; i++) {
sb.append(ts++);
sb.append(",12,-1,12,-2,1|");
}
// Get Current Values
SnmpValue v1a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
SnmpValue v2a = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
// Set New Values
SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer1, valFac.getOctetString(sb.toString().getBytes()));
SnmpUtils.set(m_collectionAgent.getAgentConfig(), peer2, valFac.getOctetString(sb.toString().getBytes()));
// Validate New Values
SnmpValue v1b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer1);
SnmpValue v2b = SnmpUtils.get(m_collectionAgent.getAgentConfig(), peer2);
Assert.assertFalse(v1a.toDisplayString().equals(v1b.toDisplayString()));
Assert.assertFalse(v2a.toDisplayString().equals(v2b.toDisplayString()));
// Collect and Persist Data - Step 2
collectionSet = collector.collect(m_collectionAgent, parameters);
validateCollectionSet(collectionSet);
collectionSet.visit(persister);
// Validate Persisted Data
Path pathToJrbFile = getSnmpRoot().toPath().resolve(Paths.get("1", TcaCollectionHandler.RESOURCE_TYPE_NAME, "171.19.37.60", TcaCollectionHandler.INBOUND_DELAY + m_rrdStrategy.getDefaultFileExtension()));
RrdDb jrb = new RrdDb(pathToJrbFile.toString());
// According with the Fixed Step
Assert.assertEquals(1, jrb.getArchive(0).getArcStep());
// According with the Sample Data
Assert.assertEquals(ts - 1, jrb.getArchive(0).getEndTime());
Robin inboundDelay = jrb.getArchive(0).getRobin(0);
for (int i = inboundDelay.getSize() - 49; i < inboundDelay.getSize() - 25; i++) {
Assert.assertEquals(new Double(11), Double.valueOf(inboundDelay.getValue(i)));
}
for (int i = inboundDelay.getSize() - 24; i < inboundDelay.getSize(); i++) {
Assert.assertEquals(new Double(12), Double.valueOf(inboundDelay.getValue(i)));
}
}
use of org.opennms.netmgt.snmp.SnmpValue 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<Collectable>();
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;
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SnmpMonitorStrategyTest method testMeetsCriteriaWithString.
@Test
public void testMeetsCriteriaWithString() {
SnmpValue result = octetString("A Test String");
testSyntaxEquals(result, "A Test String", "a test string");
testSyntaxMatches(result, "[tT][eE][sS][tT]", "test");
testSyntaxMatches(result, "^A Test String$", "^A Test$");
}
Aggregations