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


Java CommandResponderEvent类代码示例

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


CommandResponderEvent类属于org.snmp4j包,在下文中一共展示了CommandResponderEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:SnmpBinding.java

示例2: sendTest

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
public void sendTest(String agentAddress, int port, String community, PDU pdu) {
    for (RegistrationInfo info : s_registrations.values()) {
        if (port == info.getPort()) {
            Snmp snmp = info.getSession();
            MessageDispatcher dispatcher = snmp.getMessageDispatcher();
            TransportMapping transport = info.getTransportMapping();
            
            int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
            int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
            CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel, 
                                                                securityModel, community.getBytes(), 
                                                                SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);

            info.getHandler().processPdu(e);
        }
    }

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:19,代码来源:Snmp4JStrategy.java

示例3: 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());
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:27,代码来源:SnmpBinding.java

示例4: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的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.CommandResponderEvent; //导入依赖的package包/类
public void processPDU(PDU pdu, CommandResponderEvent event) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Received trap event for {} : {}", this.endpoint.getAddress(), pdu);
    }
    Exchange exchange = endpoint.createExchange(pdu, event);
    try {
        getProcessor().process(exchange);
    } catch (Exception e) {
        getExceptionHandler().handleException(e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:SnmpTrapConsumer.java

示例6: newNotification

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
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");
  }
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:28,代码来源:Snmp4jNotificationEventFactory.java

示例7: 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;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:10,代码来源:Snmp4jNotificationEventFactory.java

示例8: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
@Override
public void processPdu(CommandResponderEvent ev) {
  if (closed) return;
  if (logger.isTraceEnabled()) {
    logger.trace("listener {} received event: {}", this, ev);
  }
  try {
    notifyHandlers(eventFactory.newEvent(this, ev));
  }
  catch (RuntimeException ex) {
    logger.warn("listener exception: {}", ex.toString(), ex);
  }
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:14,代码来源:Snmp4jListener.java

示例9: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void processPdu(CommandResponderEvent event) {
	System.out.println("----> 开始解析ResponderEvent: <----");
	if (event == null || event.getPDU() == null) {
		System.out.println("[Warn] ResponderEvent or PDU is null");
		return;
	}
	Vector<VariableBinding> vbVect = event.getPDU().getVariableBindings();
	for (VariableBinding vb : vbVect) {
		System.out.println(vb.getOid() + " = " + vb.getVariable());
	}
	System.out.println("---->  本次ResponderEvent 解析结束 <----");
}
 
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:14,代码来源:SnmpTrapMultiThreadReceiver.java

示例10: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的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

示例11: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
public synchronized void processPdu(CommandResponderEvent cmdRespEvent) {
    PDU pdu = cmdRespEvent.getPDU();
    System.out.println("Received PDU... " + pdu);
    if (pdu != null) {
        System.out.println(pdu.getClass().getName());
        System.out.println("trapType = " + pdu.getType());
        System.out.println("isPDUv1 = " + (pdu instanceof PDUv1));
        System.out.println("isTrap = " + (pdu.getType() == PDU.TRAP));
        System.out.println("isInform = " + (pdu.getType() == PDU.INFORM));
        System.out.println("variableBindings = " + pdu.getVariableBindings());
        trapCount++;
    } else {
        System.err.println("ERROR: Can't create PDU");
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:16,代码来源:Snmp4jTrapReceiverTest.java

示例12: 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()));
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:38,代码来源:Snmp4JTrapNotifier.java

示例13: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
public void processPdu(CommandResponderEvent e) {
    PDU command = e.getPDU();
    if (command == null) return;
 
    PDU response = processRequest(command);
      if (response == null) return;
      
      StatusInformation statusInformation = new StatusInformation();
      StateReference ref = e.getStateReference();
      try {
          Logger.getLogger(MockProxy.class).debug("Replying with: "+command);
          e.setProcessed(true);
          e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
                                                     e.getSecurityModel(),
                                                     e.getSecurityName(),
                                                     e.getSecurityLevel(),
                                                     command,
                                                     e.getMaxSizeResponsePDU(),
                                                     ref,
                                                     statusInformation);
      }
      catch (MessageException ex) {
          System.err.println("Error while sending response: "+ex.getMessage());
          Logger.getLogger(MockProxy.class).error(ex);
      }
      
    
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:29,代码来源:MockProxy.java

示例14: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的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

示例15: processPdu

import org.snmp4j.CommandResponderEvent; //导入依赖的package包/类
public void processPdu(CommandResponderEvent event) {
	if (start < 0) {
		start = System.currentTimeMillis() - 1;
	}
	logger.info("TRAP received >> " + event.getPDU().toString());
	n++;
	if ((n % 100 == 1)) {
		logger.info("Some statistics, processing  "
				+ (n / (double) (System.currentTimeMillis() - start))
				* 1000 + " trap/s, total " + n);
	}
}
 
开发者ID:ccascone,项目名称:JNetMan,代码行数:13,代码来源:SnmpTrapReceiver.java


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