本文整理汇总了Java中org.snmp4j.CommandResponderEvent.getPeerAddress方法的典型用法代码示例。如果您正苦于以下问题:Java CommandResponderEvent.getPeerAddress方法的具体用法?Java CommandResponderEvent.getPeerAddress怎么用?Java CommandResponderEvent.getPeerAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.snmp4j.CommandResponderEvent
的用法示例。
在下文中一共展示了CommandResponderEvent.getPeerAddress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processPdu
import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
/**
* Will be called whenever a {@link PDU} is received on the given port
* specified in the listen() method. It extracts a {@link Variable}
* according to the configured OID prefix and sends its value to the event
* bus.
*/
public void processPdu(CommandResponderEvent event) {
Address addr = event.getPeerAddress();
if (addr == null) {
return;
}
String s = addr.toString().split("/")[0];
if (s == null) {
logger.error("TRAP: failed to translate address {}", addr);
dispatchPdu(addr, event.getPDU());
} else {
// Need to change the port to 161, which is what the bindings are configured for since
// at least some SNMP devices send traps from a random port number. Otherwise the trap
// won't be found as the address check will fail. It feels like there should be a better
// way to do this!!!
Address address = GenericAddress.parse("udp:" + s + "/161");
dispatchPdu(address, event.getPDU());
}
}
示例2: processPdu
import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
/**
* Will be called whenever a {@link PDU} is received on the given port
* specified in the listen() method. It extracts a {@link Variable}
* according to the configured OID prefix and sends its value to the event
* bus.
*/
@Override
public void processPdu(CommandResponderEvent event) {
Address addr = event.getPeerAddress();
if (addr == null) {
return;
}
String s = addr.toString().split("/")[0];
if (s == null) {
logger.error("TRAP: failed to translate address {}", addr);
dispatchPdu(addr, event.getPDU());
} else {
// Need to change the port to 161, which is what the bindings are configured for since
// at least some SNMP devices send traps from a random port number. Otherwise the trap
// won't be found as the address check will fail. It feels like there should be a better
// way to do this!!!
Address address = GenericAddress.parse("udp:" + s + "/161");
dispatchPdu(address, event.getPDU());
}
}
示例3: newTarget
import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
private SnmpTarget newTarget(CommandResponderEvent event) {
SnmpTargetBase target = newTarget(event.getMessageProcessingModel());
Address address = event.getPeerAddress();
String uri = address.toString();
int i = uri.indexOf('/');
if (i == -1) i = uri.length();
target.setAddress(uri.substring(0, i));
return target;
}
示例4: processPdu
import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
@Override
public void processPdu(CommandResponderEvent e) {
PDU command = new PDU(e.getPDU());
IpAddress addr = ((IpAddress)e.getPeerAddress());
if (command != null) {
if (command.getType() == PDU.INFORM) {
PDU response = new PDU(command);
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
try {
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
e.getSecurityModel(),
e.getSecurityName(),
e.getSecurityLevel(),
response,
e.getMaxSizeResponsePDU(),
ref,
statusInformation);
if (log().isDebugEnabled()) {
log().debug("Sent RESPONSE PDU to peer " + addr + " acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
} catch (MessageException ex) {
log().error("Error while sending RESPONSE PDU to peer " + addr + ": " + ex.getMessage() + "acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
}
}
if (e.getPDU() instanceof PDUv1) {
m_listener.trapReceived(new Snmp4JV1TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), (PDUv1)e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
} else {
m_listener.trapReceived(new Snmp4JV2TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
}
}
示例5: processPdu
import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
public void processPdu(CommandResponderEvent e) {
PDU command = new PDU(e.getPDU());
IpAddress addr = ((IpAddress)e.getPeerAddress());
if (command != null) {
if (command.getType() == PDU.INFORM) {
PDU response = new PDU(command);
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
try {
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
e.getSecurityModel(),
e.getSecurityName(),
e.getSecurityLevel(),
response,
e.getMaxSizeResponsePDU(),
ref,
statusInformation);
if (log().isDebugEnabled()) {
log().debug("Sent RESPONSE PDU to peer " + addr + " acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
} catch (MessageException ex) {
log().error("Error while sending RESPONSE PDU to peer " + addr + ": " + ex.getMessage() + "acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
}
}
if (e.getPDU() instanceof PDUv1) {
m_listener.trapReceived(new Snmp4JV1TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), (PDUv1)e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
} else {
m_listener.trapReceived(new Snmp4JV2TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
}
}