當前位置: 首頁>>代碼示例>>Java>>正文


Java OID類代碼示例

本文整理匯總了Java中org.snmp4j.smi.OID的典型用法代碼示例。如果您正苦於以下問題:Java OID類的具體用法?Java OID怎麽用?Java OID使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OID類屬於org.snmp4j.smi包,在下文中一共展示了OID類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.snmp4j.smi.OID; //導入依賴的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: querySingleSNMPTableByOID

import org.snmp4j.smi.OID; //導入依賴的package包/類
public List<SNMPTriple> querySingleSNMPTableByOID(String oid) throws IOException
{
 if(oid == null || oid.isEmpty())return null;
 if(!oid.startsWith("."))oid = "."+oid;
    TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
    List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID(oid)}, null, null);

 List<SNMPTriple> snmpList = new ArrayList<SNMPTriple>();
    
    for (TableEvent event : events) {
      if(event.isError()) {
     	 logger.warning("SNMP event error: "+event.getErrorMessage());
     	 continue;
           //throw new RuntimeException(event.getErrorMessage());
      }
      for(VariableBinding vb: event.getColumns()) {
   	   String key = vb.getOid().toString();
   	   String value = vb.getVariable().toString();
   	 snmpList.add(new SNMPTriple(key, "", value));
      }
    }
 return snmpList;
}
 
開發者ID:yahoo,項目名稱:mysql_perf_analyzer,代碼行數:24,代碼來源:SNMPClient.java

示例3: snmpGet

import org.snmp4j.smi.OID; //導入依賴的package包/類
/**
 * 獲取指定OID的 get
 *
 * @param snmp
 * @param target
 * @param oid
 * @return
 * @throws IOException
 */
public static PDU snmpGet(Snmp snmp, Target target, String oid) throws IOException {
    ScopedPDU pdu = new ScopedPDU();
    pdu.setType(PDU.GET);
    pdu.add(new VariableBinding(new OID(oid)));

    ResponseEvent responseEvent = snmp.send(pdu, target);
    PDU response = responseEvent.getResponse();
    if(response == null){
        log.warn("response null - error:{} peerAddress:{} source:{} request:{}",
                responseEvent.getError(),
                responseEvent.getPeerAddress(),
                responseEvent.getSource(),
                responseEvent.getRequest());
    }
    return response;
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:26,代碼來源:SNMPHelper.java

示例4: snmpWalk

import org.snmp4j.smi.OID; //導入依賴的package包/類
/**
 * walk方式獲取指定的oid value
 *
 * @param snmp
 * @param target
 * @param oid
 * @return
 * @throws IOException
 */
public static List<PDU> snmpWalk(Snmp snmp, Target target, String oid) throws IOException {
    List<PDU> pduList = new ArrayList<>();

    ScopedPDU pdu = new ScopedPDU();
    OID targetOID = new OID(oid);
    pdu.add(new VariableBinding(targetOID));

    boolean finished = false;
    while (!finished) {
        VariableBinding vb = null;
        ResponseEvent respEvent = snmp.getNext(pdu, target);

        PDU response = respEvent.getResponse();

        if (null == response) {
            break;
        } else {
            vb = response.get(0);
        }
        // check finish
        finished = checkWalkFinished(targetOID, pdu, vb);
        if (!finished) {
            pduList.add(response);

            // Set up the variable binding for the next entry.
            pdu.setRequestID(new Integer32(0));
            pdu.set(0, vb);
        }
    }

    return pduList;
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:42,代碼來源:SNMPHelper.java

示例5: checkWalkFinished

import org.snmp4j.smi.OID; //導入依賴的package包/類
private static boolean checkWalkFinished(OID targetOID, PDU pdu, VariableBinding vb) {
    boolean finished = false;
    if (pdu.getErrorStatus() != 0) {
        finished = true;
    } else if (vb.getOid() == null) {
        finished = true;
    } else if (vb.getOid().size() < targetOID.size()) {
        finished = true;
    } else if (targetOID.leftMostCompare(targetOID.size(), vb.getOid()) != 0) {
        finished = true;
    } else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
        finished = true;
    } else if (vb.getOid().compareTo(targetOID) <= 0) {
        finished = true;
    }
    return finished;

}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:19,代碼來源:SNMPHelper.java

示例6: getAddDropPort

import org.snmp4j.smi.OID; //導入依賴的package包/類
private PortNumber getAddDropPort(int channel, boolean isAddPort) {
    OID oid = new OID(CTRL_CHANNEL_ADD_DROP_PORT_INDEX + (isAddPort ? "1" : "2"));

    for (TreeEvent event : snmp.get(oid)) {
        if (event == null) {
            return null;
        }

        VariableBinding[] varBindings = event.getVariableBindings();

        for (VariableBinding varBinding : varBindings) {
            if (varBinding.getOid().last() == channel) {
                int port = varBinding.getVariable().toInt();
                if (!isAddPort) {
                    port += DROP_PORT_OFFSET;
                }
                return PortNumber.portNumber(port);

            }
        }

    }

    return null;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:26,代碼來源:LumentumFlowRuleProgrammable.java

示例7: poll

import org.snmp4j.smi.OID; //導入依賴的package包/類
@Override
protected int poll() throws Exception {
    this.pdu.clear();
    
    int type = this.getPduType(this.endpoint.getType());
    
    this.pdu.setType(type);

    // prepare the request items
    for (OID oid : this.endpoint.getOids()) {
        this.pdu.add(new VariableBinding(oid));
    }

    // send the request
    snmp.send(pdu, target, null, this);

    return 1;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:SnmpOIDPoller.java

示例8: convertPrivacyProtocol

import org.snmp4j.smi.OID; //導入依賴的package包/類
private OID convertPrivacyProtocol(String privacyProtocol) {
    if (privacyProtocol == null) {
        return null;
    }    
    if ("DES".equals(privacyProtocol)) {
        return PrivDES.ID;
    } else if ("TRIDES".equals(privacyProtocol)) {
        return Priv3DES.ID;
    } else if ("AES128".equals(privacyProtocol)) {
        return PrivAES128.ID;
    } else if ("AES192".equals(privacyProtocol)) {
        return PrivAES192.ID;
    } else if ("AES256".equals(privacyProtocol)) {
        return PrivAES256.ID;
    } else {
        throw new IllegalArgumentException("Unknown privacy protocol: " + privacyProtocol);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:SnmpOIDPoller.java

示例9: endOfTable

import org.snmp4j.smi.OID; //導入依賴的package包/類
private boolean endOfTable(int offset) {
  if (response == null) {
    throw new WouldBlockException();
  }
  int i = 0;
  while (offset + i < response.size() && i < repeaters) {
    OID oid = response.get(offset + i).getOid();
    if (!oid.startsWith(requestedVarbinds[nonRepeaters + i].getOid())) {
      return true;
    }
    i++;
  }
  if (i < repeaters) {
    setNextOids(offset - repeaters);
    throw new WouldBlockException();
  }
  return false;
}
 
開發者ID:soulwing,項目名稱:tnm4j,代碼行數:19,代碼來源:AbstractAsyncWalker.java

示例10: privType

import org.snmp4j.smi.OID; //導入依賴的package包/類
private OID privType(SnmpV3Target v3Target) {
  switch (v3Target.getPrivType()) {
    case DES:
      return PrivDES.ID;
    case DES3:
      return Priv3DES.ID;
    case AES128:
      return PrivAES128.ID;
    case AES192:
      return PrivAES192.ID;
    case AES256:
      return PrivAES256.ID;
    default:
      throw new IllegalArgumentException("unrecognized privacy type");
  }
}
 
開發者ID:soulwing,項目名稱:tnm4j,代碼行數:17,代碼來源:UserTargetStrategy.java

示例11: getIndexes

import org.snmp4j.smi.OID; //導入依賴的package包/類
@Override
public Varbind[] getIndexes() {
  if (indexExtractor == null) {
    return new Varbind[0];
  }
  IndexDescriptor[] descriptors = indexExtractor.extractIndexes(getOid());
  Varbind[] varbinds = new Varbind[descriptors.length];
  for (int i = 0; i < descriptors.length; i++) {
    IndexDescriptor descriptor = descriptors[i];
    Variable variable = AbstractVariable.createFromSyntax(
        descriptor.getSyntax());
    variable.fromSubIndex(new OID(descriptor.getEncoded()), 
        descriptor.isImplied());
    VariableBinding vb = new VariableBinding(new OID(descriptor.getOid()), 
        variable);
    varbinds[i] = varbindFactory.newVarbind(vb);
  }
  return varbinds;
}
 
開發者ID:soulwing,項目名稱:tnm4j,代碼行數:20,代碼來源:Snmp4jVarbind.java

示例12: querySysData

import org.snmp4j.smi.OID; //導入依賴的package包/類
/**
 * Retrieve common system SNMP data
 * @return
 * @throws IOException
 */
public Map<String, String> querySysData() throws IOException 
{
	logger.fine("Query snmp for "+address);
	Map<String, String> resMap = null;
	 resMap = new java.util.LinkedHashMap<String, String>();
	 Map<OID, String> res = get(COMMON_SYS_OIDS);
	 if(res!=null)
	 {
		 for(Map.Entry<OID, String> e: res.entrySet())
		 {
			 if("noSuchObject".equalsIgnoreCase(e.getValue()))continue;
			 resMap.put(OID_NAME_MAP.get("."+e.getKey().toString()), e.getValue());
		 }
	 }
	 return resMap;
}
 
開發者ID:yahoo,項目名稱:mysql_perf_analyzer,代碼行數:22,代碼來源:SNMPClient.java

示例13: querySysData3

import org.snmp4j.smi.OID; //導入依賴的package包/類
/**
 * 
 * @return
 * @throws IOException
 */
public List<SNMPTriple> querySysData3() throws IOException 
{
	logger.fine("Query snmp system data for "+address);
	List<SNMPTriple> snmpList = new ArrayList<SNMPTriple>();
	 Map<OID, String> res = get(COMMON_SYS_OIDS);
	 if(res!=null)
	 {
		 for(Map.Entry<OID, String> e: res.entrySet())
		 {
			 if("noSuchObject".equalsIgnoreCase(e.getValue()))continue;
			 snmpList.add(new SNMPTriple(e.getKey().toString(), OID_NAME_MAP.get("."+e.getKey().toString()), e.getValue()));
		 }
	 }
	 return snmpList;
}
 
開發者ID:yahoo,項目名稱:mysql_perf_analyzer,代碼行數:21,代碼來源:SNMPClient.java

示例14: get

import org.snmp4j.smi.OID; //導入依賴的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

示例15: getTargetV3

import org.snmp4j.smi.OID; //導入依賴的package包/類
private Target getTargetV3() {
	//logger.info("Use SNMP v3, "+this.privacyprotocol +"="+this.password+", "+this.privacyprotocol+"="+this.privacypassphrase);
	OID authOID = AuthMD5.ID;
	if("SHA".equals(this.authprotocol))
		authOID = AuthSHA.ID;
	OID privOID = PrivDES.ID;
	if(this.privacyprotocol == null || this.privacyprotocol.isEmpty())
		privOID = null;
	UsmUser user = new UsmUser(new OctetString(this.username),  
			authOID, new OctetString(this.password),  //auth
			privOID, this.privacypassphrase!=null?new OctetString(this.privacypassphrase):null); //enc
	snmp.getUSM().addUser(new OctetString(this.username), user);  
	Address targetAddress = GenericAddress.parse(address);
	UserTarget target = new UserTarget();
	target.setAddress(targetAddress);
	target.setRetries(2);
	target.setTimeout(1500);
	target.setVersion(this.getVersionInt());
	if(privOID != null)
		target.setSecurityLevel(SecurityLevel.AUTH_PRIV);  
	else
		target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV); 
	target.setSecurityName(new OctetString(this.username));
	return target;
}
 
開發者ID:yahoo,項目名稱:mysql_perf_analyzer,代碼行數:26,代碼來源:SNMPClient.java


注:本文中的org.snmp4j.smi.OID類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。