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());
}
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);
}
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);
}
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");
}
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;
}
Aggregations