本文整理汇总了Java中org.snmp4j.PDU.V1TRAP属性的典型用法代码示例。如果您正苦于以下问题:Java PDU.V1TRAP属性的具体用法?Java PDU.V1TRAP怎么用?Java PDU.V1TRAP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.snmp4j.PDU
的用法示例。
在下文中一共展示了PDU.V1TRAP属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
/**
* Handles the translation of a {@link SnmpMessage} to {@link RawEvent}
*
*/
@Override
public void process(Exchange exchange) throws Exception {
// Extract the SnmpMessage and PDU instances from the Camel Exchange
Message message = exchange.getIn();
SnmpMessage snmpMessage = message.getBody(SnmpMessage.class);
PDU pdu = snmpMessage.getSnmpMessage();
// Create our event so that we can populate with SNMP data.
RawEvent event = new RawEvent();
// Dispatch based on PDU type of the trap
// TBD: Handling of v3 PDU traps
if (pdu.getType() == PDU.V1TRAP) {
processV1Trap(snmpMessage, pdu, event);
}
else {
processV2Trap(snmpMessage, pdu, event);
}
// Dump out the contents of our event for debugging purposes
LOG.debug("RawEvent: " + event);
// Assign the RawEvent to the body
message.setBody(event, RawEvent.class);
}
示例2: processPdu
public void processPdu(CommandResponderEvent event) {
PDU pdu = event.getPDU();
// check PDU not null
if (pdu != null) {
// check for INFORM
// code take from the book "Essential SNMP"
if ((pdu.getType() != PDU.TRAP) && (pdu.getType() != PDU.V1TRAP) && (pdu.getType() != PDU.REPORT)
&& (pdu.getType() != PDU.RESPONSE)) {
// first response the inform-message and then process the
// message
pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = event.getStateReference();
try {
event.getMessageDispatcher().returnResponsePdu(event.getMessageProcessingModel(),
event.getSecurityModel(),
event.getSecurityName(),
event.getSecurityLevel(), pdu,
event.getMaxSizeResponsePDU(), ref,
statusInformation);
if (LOG.isDebugEnabled()) {
LOG.debug("response to INFORM sent");
}
} catch (MessageException ex) {
getExceptionHandler().handleException(ex);
}
}
processPDU(pdu, event);
} else {
LOG.debug("Received invalid trap PDU: " + pdu);
}
}
示例3: newNotification
private Snmp4jNotification newNotification(CommandResponderEvent event,
SnmpTarget target, VarbindCollection varbinds) {
switch (event.getPDU().getType()) {
case PDU.V1TRAP:
Snmp4jV1Trap trap = new Snmp4jV1Trap(target, varbinds);
PDUv1 pdu = (PDUv1) event.getPDU();
trap.setEnterprise(pdu.getEnterprise().toString());
trap.setAgentAddress(pdu.getAgentAddress().toString());
MibTrapV1Support trapSupport = varbindFactory.getMib()
.getV1TrapSupport();
trap.setGenericType(new ImmutableObjectValue(SMIConstants.SYNTAX_INTEGER,
pdu.getGenericTrap(), trapSupport.getGenericTrapFormatter()));
trap.setSpecificType(new ImmutableObjectValue(SMIConstants.SYNTAX_INTEGER,
pdu.getSpecificTrap(), trapSupport.getSpecificTrapFormatter()));
trap.setTimestamp(new ImmutableObjectValue(SMIConstants.SYNTAX_TIMETICKS,
pdu.getTimestamp(), trapSupport.getTimestampFormatter()));
return trap;
case PDU.INFORM:
return new Snmp4jNotification(SnmpNotification.Type.INFORM, target,
varbinds);
case PDU.TRAP:
return new Snmp4jNotification(SnmpNotification.Type.TRAP, target,
varbinds);
default:
throw new IllegalArgumentException("unrecognized PDU type");
}
}
示例4: processPdu
/**
* This method will be called whenever a pdu is received on the given port specified in the listen() method
*/
public synchronized void processPdu(CommandResponderEvent cmdRespEvent)
{
System.out.println("Received PDU...");
PDU pdu = cmdRespEvent.getPDU();
if (pdu != null)
{
System.out.println("Trap Type = " + pdu.getType());
System.out.println("Variable Bindings = " + pdu.getVariableBindings());
int pduType = pdu.getType();
if ((pduType != PDU.TRAP) && (pduType != PDU.V1TRAP) && (pduType != PDU.REPORT)
&& (pduType != PDU.RESPONSE))
{
pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = cmdRespEvent.getStateReference();
try
{
System.out.println(cmdRespEvent.getPDU());
cmdRespEvent.getMessageDispatcher().returnResponsePdu(cmdRespEvent.getMessageProcessingModel(),
cmdRespEvent.getSecurityModel(), cmdRespEvent.getSecurityName(), cmdRespEvent.getSecurityLevel(),
pdu, cmdRespEvent.getMaxSizeResponsePDU(), ref, statusInformation);
}
catch (MessageException ex)
{
System.err.println("Error while sending response: " + ex.getMessage());
LogFactory.getLogger(SnmpRequest.class).error(ex);
}
}
}
}
示例5: isRequestPDU
/**
* @param command
* @return
*/
private boolean isRequestPDU(PDU command) {
return (command.getType() != PDU.TRAP) &&
(command.getType() != PDU.V1TRAP) &&
(command.getType() != PDU.REPORT) &&
(command.getType() != PDU.RESPONSE);
}
示例6: toString
/**
* Converts the given snmp pdu to a String body.
*
* @param pdu the snmp pdu
* @return the text content
*/
@Converter
public static String toString(PDU pdu) {
// the output buffer
StringBuilder sb = new StringBuilder();
// prepare the header
if (pdu.getType() == PDU.V1TRAP) {
sb.append("<" + SNMP_TAG + " messageType=\"v1\">");
} else {
sb.append(SNMP_TAG_OPEN);
}
// Extract SNMPv1 specific variables
if (pdu.getType() == PDU.V1TRAP) {
PDUv1 v1pdu = (PDUv1) pdu;
entryAppend(sb, "enterprise", v1pdu.getEnterprise().toString());
entryAppend(sb, "agent-addr", v1pdu.getAgentAddress().toString());
entryAppend(sb, "generic-trap", Integer.toString(v1pdu.getGenericTrap()));
entryAppend(sb, "specific-trap", Integer.toString(v1pdu.getSpecificTrap()));
entryAppend(sb, "time-stamp", Long.toString(v1pdu.getTimestamp()));
}
// now loop all variables of the response
for (Object o : pdu.getVariableBindings()) {
VariableBinding b = (VariableBinding)o;
sb.append(ENTRY_TAG_OPEN);
sb.append(OID_TAG_OPEN);
sb.append(b.getOid().toString());
sb.append(OID_TAG_CLOSE);
sb.append(VALUE_TAG_OPEN);
sb.append(StringHelper.xmlEncode(b.getVariable().toString()));
sb.append(VALUE_TAG_CLOSE);
sb.append(ENTRY_TAG_CLOSE);
}
// prepare the footer
sb.append(SNMP_TAG_CLOSE);
return sb.toString();
}