Search in sources :

Example 31 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SyntaxToEventTest method testProcessSyntaxWithTerminatingNull.

/**
	 * We are allowing NULL in the last position of the string in case there
	 * are any SNMP agents sending OctetString values in this format.
	 * 
	 * @see SnmpUtils#allBytesDisplayable()
	 */
@Test
public void testProcessSyntaxWithTerminatingNull() {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    assertNotNull(valueFactory);
    byte[] macAddr = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x00 };
    SnmpValue octetString = valueFactory.getOctetString(macAddr);
    Parm parm = SyntaxToEvent.processSyntax("Test", octetString);
    assertEquals("Test", parm.getParmName());
    assertEquals(EventConstants.XML_ENCODING_TEXT, parm.getValue().getEncoding());
    // I'm not sure what is converting the NULL char to a "."...
    assertEquals("UUUUU.", parm.getValue().getContent());
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Parm(org.opennms.netmgt.xml.event.Parm) Test(org.junit.Test)

Example 32 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class TrapHandlerITCase method testV2EnterpriseIdAndGenericAndSpecificAndMatchWithVarbinds.

@Test
@DirtiesContext
public void testV2EnterpriseIdAndGenericAndSpecificAndMatchWithVarbinds() throws Exception {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
    varbinds.put(".1.3.6.1.4.1.11.2.14.11.1.7.2.1.4.2404", valueFactory.getInt32(3));
    varbinds.put(".1.3.6.1.4.1.11.2.14.11.1.7.2.1.5.2404", valueFactory.getInt32(2));
    varbinds.put(".1.3.6.1.4.1.11.2.14.11.1.7.2.1.6.2404", valueFactory.getInt32(5));
    varbinds.put(".1.3.6.1.4.1.11.2.14.11.1.7.3.0.2404", valueFactory.getOctetString("http://a.b.c.d/cgi/fDetail?index=2404".getBytes()));
    anticipateAndSend(false, true, "uei.opennms.org/vendor/HP/traps/hpicfFaultFinderTrap", "v2c", ".1.3.6.1.4.1.11.2.14.12.1", 6, 5, varbinds);
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 33 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class TrapHandlerITCase method testV1TrapOIDWildCardMatch.

@Test
@DirtiesContext
public void testV1TrapOIDWildCardMatch() throws Exception {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
    varbinds.put(".1.3.6.1.4.1.32473.42.42.42", valueFactory.getInt32(42));
    anticipateAndSend(false, true, "uei.opennms.org/IANA/Example/traps/exampleEnterpriseTrap", "v1", ".1.3.6.1.4.1.32473.42", 6, 5, varbinds);
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 34 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class TrapHandlerITCase method sendV1Trap.

public void sendV1Trap(String enterprise, int generic, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
    SnmpV1TrapBuilder pdu = SnmpUtils.getV1TrapBuilder();
    pdu.setEnterprise(SnmpObjId.get(enterprise));
    pdu.setGeneric(generic);
    pdu.setSpecific(specific);
    pdu.setTimeStamp(0);
    pdu.setAgentAddress(m_ip);
    Iterator<Map.Entry<String, SnmpValue>> it = varbinds.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, SnmpValue> pairs = it.next();
        pdu.addVarBind(SnmpObjId.get(pairs.getKey()), pairs.getValue());
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpV1TrapBuilder(org.opennms.netmgt.snmp.SnmpV1TrapBuilder) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 35 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class TrapUtils method getTrapData.

/**
     * Gets the trap identity.
     *
     * @param trapNotification the trap notification
     * @return the identity
     */
public static TrapData getTrapData(TrapInformation trapNotification) {
    if (trapNotification instanceof Snmp4JV1TrapInformation) {
        Snmp4JV1TrapInformation info = (Snmp4JV1TrapInformation) trapNotification;
        TrapIdentity identity = info.getTrapIdentity();
        TrapData data = new TrapData(identity.getEnterpriseId(), identity.getGeneric(), identity.getSpecific());
        for (int i = 0; i < info.getPduLength(); i++) {
            VariableBinding v = info.getVarBindAt(i);
            SnmpValue value = new Snmp4JValue(v.getVariable());
            data.addParameter("." + v.getOid().toString(), value.toDisplayString());
        }
        return data;
    } else if (trapNotification instanceof Snmp4JV2TrapInformation) {
        Snmp4JV2TrapInformation info = (Snmp4JV2TrapInformation) trapNotification;
        TrapIdentity identity = info.getTrapIdentity();
        TrapData data = new TrapData(identity.getEnterpriseId(), identity.getGeneric(), identity.getSpecific());
        for (int i = 0; i < info.getPduLength(); i++) {
            VariableBinding v = info.getVarBindAt(i);
            SnmpValue value = new Snmp4JValue(v.getVariable());
            data.addParameter("." + v.getOid().toString(), value.toDisplayString());
        }
        return data;
    }
    return null;
}
Also used : Snmp4JV2TrapInformation(org.opennms.netmgt.snmp.snmp4j.Snmp4JTrapNotifier.Snmp4JV2TrapInformation) TrapIdentity(org.opennms.netmgt.snmp.TrapIdentity) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Snmp4JV1TrapInformation(org.opennms.netmgt.snmp.snmp4j.Snmp4JTrapNotifier.Snmp4JV1TrapInformation) VariableBinding(org.snmp4j.smi.VariableBinding) TrapData(org.opennms.netmgt.alarmd.northbounder.snmptrap.TrapData)

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)14 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