use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method addAttributeToCollectionResource.
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, BigInteger value) {
MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
SnmpAttributeType objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
SnmpValue snmpValue = SnmpUtils.getValueFactory().getCounter64(value);
resource.setAttributeValue(objectType, snmpValue);
return new SnmpAttribute(resource, objectType, snmpValue);
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class TrapHandlerITCase method testV1EnterpriseIdAndGenericAndSpecificAndMatchWithVarbindsAndTC.
// These exist to provide testing for the new Textual Convention feature
// See EventConfDataTest for the other part of this testing
@Test
@DirtiesContext
public void testV1EnterpriseIdAndGenericAndSpecificAndMatchWithVarbindsAndTC() throws Exception {
SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
varbinds.put(".1.3.6.1.4.1.14179.2.6.2.20.0", valueFactory.getOctetString(new byte[] { (byte) 0x00, (byte) 0x14, (byte) 0xf1, (byte) 0xad, (byte) 0xa7, (byte) 0x50 }));
Collection<Event> events = anticipateAndSend(false, true, "uei.opennms.org/vendor/cisco/bsnAPNoiseProfileUpdatedToPass", "v1", ".1.3.6.1.4.1.14179.2.6.3", 6, 38, varbinds);
boolean foundMacAddress = false;
// Assert that the MAC address varbind has been formatted into a colon-separated octet string
for (Event event : events) {
for (Parm parm : event.getParmCollection()) {
if (".1.3.6.1.4.1.14179.2.6.2.20.0".equals(parm.getParmName())) {
assertEquals("MAC address does not match", "00:14:F1:AD:A7:50", parm.getValue().getContent());
foundMacAddress = true;
}
}
}
assertTrue("Did not find expected MAC address parm", foundMacAddress);
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class TrapHandlerITCase method sendV2Trap.
public void sendV2Trap(String enterprise, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
boolean isGeneric = false;
SnmpObjId trapOID;
if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
isGeneric = true;
trapOID = enterpriseId;
} else {
trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
// XXX or should it be this
// trap OID = enterprise + ".0." + specific;
}
SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
if (isGeneric) {
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
}
for (Map.Entry<String, SnmpValue> entry : varbinds.entrySet()) {
pdu.addVarBind(SnmpObjId.get(entry.getKey()), entry.getValue());
}
pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class MockSnmpStrategy method get.
@Override
public SnmpValue get(final SnmpAgentConfig agentConfig, final SnmpObjId oid) {
final PropertyOidContainer oidContainer = getOidContainer(agentConfig);
if (oidContainer == null)
return null;
SnmpValue val = oidContainer.findValueForOid(oid);
if (val.isNull()) {
return null;
}
return val;
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SingleInstanceTrackerProxyTest method canHandleValidResponses.
@Test
public void canHandleValidResponses() {
// Build a response with the requested OID
SnmpValue value = mock(SnmpValue.class);
SnmpResult result = new SnmpResult(base, instance, value);
WalkResponse response = new WalkResponse(Collections.singletonList(result));
// Resolve the walker
tracker.handleWalkResponses(Collections.singletonList(response));
// We should be finished, and have captured the expected value
assertThat(tracker.isFinished(), equalTo(true));
assertThat(gatherer.getResults(), hasSize(1));
assertThat(gatherer.getResults().get(0).getValue(), equalTo(value));
}
Aggregations