Search in sources :

Example 81 with SnmpValue

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);
}
Also used : NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Example 82 with 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);
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 83 with SnmpValue

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");
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 84 with SnmpValue

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;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue)

Example 85 with SnmpValue

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));
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Aggregations

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)15 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4