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


Java PDU.setType方法代码示例

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


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

示例1: main

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.listen();

    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(new UdpAddress("23.23.52.11/161"));
    target.setTimeout(3000);    //3s
    target.setRetries(1);

    PDU pdu = new PDU();
    pdu.setType(PDU.GETBULK);
    pdu.setMaxRepetitions(1); 
    pdu.setNonRepeaters(0);
    VariableBinding[] array = {new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3")),
                               new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.7")),
                               new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.10")),
                               new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.19"))};
    pdu.addAll(array);

    //pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3"))); 

    ResponseEvent responseEvent = snmp.send(pdu, target);
    PDU response = responseEvent.getResponse();

    if (response == null) {
	    System.out.println("TimeOut...");
    } else {
	    if (response.getErrorStatus() == PDU.noError) {
               Vector<? extends VariableBinding> vbs = response.getVariableBindings();
               for (VariableBinding vb : vbs) {
                   System.out.println(vb.getVariable().toString());
	        }
	    } else {
	        System.out.println("Error:" + response.getErrorStatusText());
	    }
    }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:40,代码来源:testSNMPGetBulk.java

示例2: sendPDU

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * 向接收器发送Trap 信息
 * 
 * @throws IOException
 */
public void sendPDU() throws IOException {
	PDU pdu = new PDU();
	pdu.add(new VariableBinding(
			new OID(".1.3.6.1.2.1.1.1.0"),
			new OctetString("SNMP Trap Test.see more:http://www.micmiu.com")));
	pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(
			new UnsignedInteger32(System.currentTimeMillis() / 1000)
					.getValue())));
	pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(
			".1.3.6.1.6.3.1.1.4.3")));

	// 向Agent发送PDU
	pdu.setType(PDU.TRAP);
	snmp.send(pdu, target);
	System.out.println("----> Trap Send END <----");
}
 
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:22,代码来源:SnmpTrapSendDemo.java

示例3: get

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * This method is capable of handling multiple OIDs
 * @param oids
 * @return
 * @throws IOException
 */
public Map<OID, String> get(OID oids[]) throws IOException 
{
	PDU pdu = createPDU();
	for (OID oid : oids) {
		pdu.add(new VariableBinding(oid));
	}
	pdu.setType(PDU.GET);
	ResponseEvent event = snmp.send(pdu, getTarget(), null);
	if(event != null) {
		PDU pdu2 = event.getResponse();
		VariableBinding[] binds = pdu2!=null?event.getResponse().toArray():null;
		if(binds!=null)
		{
			Map<OID, String> res = new LinkedHashMap<OID, String>(binds.length);
			for(VariableBinding b: binds)
				res.put(b.getOid(), b.getVariable().toString());
			return res;
		}else return null;
	}
	throw new RuntimeException("GET timed out");
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:28,代码来源:SNMPClient.java

示例4: get

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * Request multiple OIDs
 *
 * @param oids OIDS
 * @return ResponseEvent
 */
public ResponseEvent get(OID oids[]) {

    try {
        PDU pdu = new PDU();
        for (OID oid : oids) {
            pdu.add(new VariableBinding(oid));
        }
        pdu.setType(PDU.GET);
        ResponseEvent event;
        event = snmp.send(pdu, getTarget(), null);
        if (event != null) {
            return event;
        }
        throw new RuntimeException("Timeout");
    } catch (IOException e) {
        throw new RuntimeException("Problem by response the OID");
    }
}
 
开发者ID:lsinfo3,项目名称:ofcprobe,代码行数:25,代码来源:SNMPManager.java

示例5: sendTrapV2

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void sendTrapV2(String port) throws IOException {
    PDU trap = new PDU();
    trap.setType(PDU.TRAP);

    OID oid = new OID("1.2.3.4.5");
    trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
    trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));

    // Add Payload
    Variable var = new OctetString("some string");
    trap.add(new VariableBinding(oid, var));

    // Specify receiver
    Address targetaddress = new UdpAddress("127.0.0.1/" + port);
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(targetaddress);

    // Send
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.send(trap, target, null, null);

    snmp.close();
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:27,代码来源:SNMPUtils.java

示例6: getPDU

import org.snmp4j.PDU; //导入方法依赖的package包/类
private PDU getPDU(OID oids[]) {
    PDU pdu = new PDU();
    for (OID oid : oids) {
        pdu.add(new VariableBinding(oid));
    }

    pdu.setType(PDU.GET);
    return pdu;
}
 
开发者ID:globocom,项目名称:groot,代码行数:10,代码来源:SimpleSnmpClient.java

示例7: 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

示例8: getEvent

import org.snmp4j.PDU; //导入方法依赖的package包/类
public ResponseEvent getEvent(OID oids[]) throws IOException 
{
	PDU pdu = createPDU();
	for (OID oid : oids) {
		pdu.add(new VariableBinding(oid));
	}
	pdu.setType(PDU.GET);
	ResponseEvent event = snmp.send(pdu, getTarget(), null);
	if(event != null) {
		return event;
	}
	throw new RuntimeException("GET timed out");
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:14,代码来源:SNMPClient.java

示例9: getDiskData

import org.snmp4j.PDU; //导入方法依赖的package包/类
public List<SNMPTriple> getDiskData(String device) throws IOException {

int index = this.getDiskIndex(device);
if(index<0)
{
	return new ArrayList<SNMPTriple>();
}
logger.fine("Query disk stats for "+index);
PDU pdu = createPDU();
for ( int i=1; i< DISK_TABLE_ENTRIES.length; i++) {
	if(DISK_TABLE_ENTRIES[i].length()==0)continue;
	pdu.add(new VariableBinding(new OID("."+DISK_TABLE_OID+"."+i+"."+index)));
}
pdu.setType(PDU.GET);
Map<String, String> res = new HashMap<String, String>(13);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) {
	VariableBinding[] binds = event.getResponse().toArray();
	for(VariableBinding b: binds)
		res.put(b.getOid().toString(), b.getVariable().toString());
	//logger.info(res.toString());
}		
      List<SNMPTriple> resList = new ArrayList<SNMPTriple>(res.size());
      for(int i=1;i<DISK_TABLE_ENTRIES.length; i++) {
	if(DISK_TABLE_ENTRIES[i].length()==0)continue;
	resList.add(new SNMPTriple("."+DISK_TABLE_OID+"."+i+"."+index, DISK_TABLE_ENTRIES[i], res.get(DISK_TABLE_OID+"."+i+"."+index)));
      }
       return resList;
 }
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:30,代码来源:SNMPClient.java

示例10: get

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* This method is capable of handling multiple OIDs
* @param oids
* @return
* @throws IOException
*/
public ResponseEvent get(OID oids[]) throws IOException {
PDU pdu = new PDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) {
return event;
}
throw new RuntimeException("GET timed out");
}
 
开发者ID:rhamnett,项目名称:dazzl,代码行数:19,代码来源:SnmpTest.java

示例11: get

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static ResponseEvent get(Target target, PDU pdu) throws IOException {
	ResponseEvent retVal = null;
	if(pdu != null){
	 	pdu.setType(PDU.GET);
	 	retVal = snmp.send(pdu, target, null);
		if(retVal == null) {
			throw new RuntimeException("GET timed out");
		}
	}
	return retVal;	
}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:12,代码来源:SNMPUtil.java

示例12: send

import org.snmp4j.PDU; //导入方法依赖的package包/类
public void send() throws IOException {
	// Create PDU
	PDU trap = new PDU();
	trap.setType(PDU.TRAP);
	
	if (this.varBinds.size() == 0) {
		addDefaultTrap();
	}
	
	// Add the varbinds to the trap
	for (VariableBinding vb : this.varBinds) {
		trap.add(vb);
	}
	// Set our target
	Address targetaddress = new UdpAddress(getTargetAddress());
	CommunityTarget target = new CommunityTarget();
	// Set the community read string
	target.setCommunity(new OctetString(this.community));
	// Set the version of the trap
	target.setVersion(version.version);
	target.setAddress(targetaddress);
	LOG.info("trap: {}",trap);

	// Send the trap
	Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
	snmp.send(trap, target, null, null);
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:28,代码来源:SendTrap.java

示例13: get

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * This method is capable of handling multiple OIDs
 * @param oids
 * @return
 * @throws IOException
 */
public ResponseEvent get(OID oids[]) throws IOException {
	PDU pdu = new PDU();
	for (OID oid : oids) {
		pdu.add(new VariableBinding(oid));
	}
	pdu.setType(PDU.GET);
	ResponseEvent event = snmp.getNext(pdu, getTarget());
	if(event != null) {
		return event;
	}
	throw new RuntimeException("GET timed out");
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:19,代码来源:testSNMPQuery2.java

示例14: 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

示例15: get

import org.snmp4j.PDU; //导入方法依赖的package包/类
public Map<OID, Variable> get(Collection<OID> oids) throws IOException {
    Map<OID, Variable> map = new LinkedHashMap<OID, Variable>();
    PDU request = createPDU();
    request.setType(PDU.GET);
    request.setVariableBindings(wrap(oids));
    boolean debug = log.isDebugEnabled();
    if (debug)
        log.debug("request " + request);
    ResponseEvent re = snmp.send(request, this.target);
    PDU response = re.getResponse();
    if (debug)
        log.debug("response " + response);
    if (response == null) {
        throw new NoResponseException("no response querying " + oids);
    }
    if (re.getError() != null)
        throw new IOException(re.getError());
    Vector<? extends VariableBinding> vbs = response.getVariableBindings();
    if (vbs.size() == 1) {
        String error = Errors.get(vbs.get(0).getOid());
        if (error != null)
            throw new IOException("got SNMP error " + error);
    }
    for (VariableBinding vb : vbs) {
        OID oid = vb.getOid();
        map.put(oid, vb.getVariable());
    }
    return map;
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:30,代码来源:SnmpComponent.java


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