当前位置: 首页>>代码示例>>Java>>正文


Java PDU.getType方法代码示例

本文整理汇总了Java中org.snmp4j.PDU.getType方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.getType方法的具体用法?Java PDU.getType怎么用?Java PDU.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.snmp4j.PDU的用法示例。


在下文中一共展示了PDU.getType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processResponse

import org.snmp4j.PDU; //导入方法依赖的package包/类
private void processResponse(PDU response) {
    try {
        if (log().isDebugEnabled()) {
            log().debug("Received a tracker PDU of type "+PDU.getTypeString(response.getType())+" from "+getAddress()+" of size "+response.size()+", errorStatus = "+response.getErrorStatus()+", errorStatusText = "+response.getErrorStatusText()+", errorIndex = "+response.getErrorIndex());
        }
        if (response.getType() == PDU.REPORT) {
            handleAuthError("A REPORT PDU was returned from the agent.  This is most likely an authentication problem.  Please check the config");
        } else {
            if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) {
                if (response.size() == 0) { // NMS-6484
                    handleError("A PDU with no errors and 0 varbinds was returned from the agent at " + getAddress() + ". This seems to be related with a broken SNMP agent.");
                } else {
                    for (int i = 0; i < response.size(); i++) {
                        VariableBinding vb = response.get(i);
                        SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue());
                        SnmpValue val = new Snmp4JValue(vb.getVariable());
                        Snmp4JWalker.this.processResponse(receivedOid, val);
                    }
                }
            }
            buildAndSendNextPdu();
        }
    } catch (Throwable e) {
        handleFatalError(e);
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:27,代码来源:Snmp4JWalker.java

示例2: process

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:30,代码来源:SnmpToEventProcessor.java

示例3: processRequest

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * @param request
 * @return
 */
private PDU processRequest(PDU request) {
    if (!isRequestPDU(request)) return null;
    
    switch(request.getType()) {
    case PDU.GET:
        return processGet(request);
    case PDU.GETNEXT:
        return processGetNext(request);
    case PDU.GETBULK:
        return processGetBulk(request);
    case PDU.SET:
        return processSet(request);
    case PDU.INFORM:
        return processInform(request);
    default:
        return processUnhandled(request);
    }
    
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:24,代码来源:MockProxy.java

示例4: processPdu

import org.snmp4j.PDU; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:SnmpTrapConsumer.java

示例5: processPdu

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * 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);
      }
    }
  }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:37,代码来源:testSNMPTrap.java

示例6: processPdu

import org.snmp4j.PDU; //导入方法依赖的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()));
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:38,代码来源:Snmp4JTrapNotifier.java

示例7: isRequestPDU

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * @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);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:11,代码来源:MockProxy.java

示例8: processPdu

import org.snmp4j.PDU; //导入方法依赖的package包/类
@Override
public void processPdu(CommandResponderEvent event) {
	PDU pdu = event.getPDU();
	if(PDU.TRAP == pdu.getType()){
		operate(pdu);
	}else{
		log.info("pdu method is:" + pdu.getType() + " not a trap");
	}
	
}
 
开发者ID:wangzijian777,项目名称:snmpTool,代码行数:11,代码来源:CommandResponderImpl.java

示例9: toString

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:48,代码来源:SnmpConverters.java


注:本文中的org.snmp4j.PDU.getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。