use of org.snmp4j.MessageDispatcherImpl in project LogHub by fbacchella.
the class TestTrap method testtrapv1Specific.
@Ignore
@Test
public void testtrapv1Specific() throws InterruptedException, IOException {
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(2);
SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testbig", null));
r.setPort(0);
Map<String, Object> props = new HashMap<>();
props.put("mibdirs", new String[] { "/usr/share/snmp/mibs", "/tmp/mibs" });
Assert.assertTrue(r.configure(new Properties(props)));
r.start();
CommandResponderEvent trapEvent = new CommandResponderEvent(new MessageDispatcherImpl(), new DefaultUdpTransportMapping(), TransportIpAddress.parse("127.0.0.1/162"), 0, 0, null, 0, null, null, 0, null);
PDUv1 pdu = new PDUv1();
pdu.setEnterprise(new OID("1.3.6.1.4.1.232"));
pdu.setAgentAddress(new IpAddress());
pdu.setGenericTrap(6);
pdu.setSpecificTrap(6013);
pdu.setTimestamp(10);
trapEvent.setPDU(pdu);
r.processPdu(trapEvent);
Event e = receiver.poll();
Assert.assertEquals(0.1, (Double) e.get("time_stamp"), 1e-10);
Assert.assertEquals(null, e.get("generic_trap"));
Assert.assertEquals("compaq", e.get("enterprise"));
Assert.assertEquals("cpqHePostError", e.get("specific_trap"));
Assert.assertEquals(InetAddress.getByName("0.0.0.0"), e.get("agent_addr"));
r.interrupt();
}
use of org.snmp4j.MessageDispatcherImpl in project LogHub by fbacchella.
the class SnmpTrap method configure.
@Override
public boolean configure(Properties properties) {
decoder = Receiver.NULLDECODER;
if (!reconfigured && properties.containsKey("mibdirs")) {
reconfigured = true;
String[] mibdirs = null;
try {
mibdirs = Arrays.stream((Object[]) properties.get("mibdirs")).map(i -> i.toString()).toArray(String[]::new);
formatter = OIDFormatter.register(mibdirs);
} catch (ClassCastException e) {
logger.error("mibdirs property is not a string array");
logger.catching(Level.DEBUG, e.getCause());
return false;
}
} else {
formatter = OIDFormatter.register();
}
threadPool = ThreadPool.create("Trap", 2);
MultiThreadedMessageDispatcher dispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
dispatcher.addCommandResponder(this);
dispatcher.addMessageProcessingModel(new MPv1());
dispatcher.addMessageProcessingModel(new MPv2c());
Address listenAddress = GenericAddress.parse(protocol + ":" + listen + "/" + port);
TransportMapping<?> transport;
try {
transport = new DefaultUdpTransportMapping((UdpAddress) listenAddress);
} catch (IOException e) {
logger.error("can't bind to {}: {}", listenAddress, e.getMessage());
return false;
}
snmp = new Snmp(dispatcher, transport);
try {
snmp.listen();
} catch (IOException e) {
logger.error("can't listen: {}", e.getMessage());
}
return super.configure(properties);
}
Aggregations