Java Code Examples for org.snmp4j.PDU#get()

The following examples show how to use org.snmp4j.PDU#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwitchMemoryStatCollect.java    From SuitAgent with Apache License 2.0 6 votes vote down vote up
private static CollectObject getCisco_IOS_XR_Mem(SNMPV3Session session, String oid) throws IOException {
    CollectObject collectObject = new CollectObject();
    collectObject.setMetrics(metricsName);
    collectObject.setSession(session);
    collectObject.setTime(new Date());

    String cpuIndex = "1.3.6.1.4.1.9.9.109.1.1.1.1.2";
    PDU cpuIndexPDU = session.getNext(cpuIndex);
    if(cpuIndexPDU.get(0) != null){
        int index  = Integer.parseInt(SNMPHelper.getValueFromPDU(cpuIndexPDU));
        String memUsedOid = "1.3.6.1.4.1.9.9.221.1.1.1.1.18." + index + ".1";
        String memFreeOid = "1.3.6.1.4.1.9.9.221.1.1.1.1.20." + index + ".1";
        PDU memUsedPDU = session.get(memUsedOid);
        PDU memFreePDU = session.get(memFreeOid);
        setRatioValueHelper(memUsedPDU,memFreePDU,collectObject);
    }

    return collectObject;
}
 
Example 2
Source File: SwitchMemoryStatCollect.java    From OpenFalcon-SuitAgent with Apache License 2.0 6 votes vote down vote up
private static CollectObject getCisco_IOS_XR_Mem(SNMPV3Session session, String oid) throws IOException {
    CollectObject collectObject = new CollectObject();
    collectObject.setMetrics(metricsName);
    collectObject.setSession(session);
    collectObject.setTime(new Date());

    String cpuIndex = "1.3.6.1.4.1.9.9.109.1.1.1.1.2";
    PDU cpuIndexPDU = session.getNext(cpuIndex);
    if(cpuIndexPDU.get(0) != null){
        int index  = Integer.parseInt(SNMPHelper.getValueFromPDU(cpuIndexPDU));
        String memUsedOid = "1.3.6.1.4.1.9.9.221.1.1.1.1.18." + index + ".1";
        String memFreeOid = "1.3.6.1.4.1.9.9.221.1.1.1.1.20." + index + ".1";
        PDU memUsedPDU = session.get(memUsedOid);
        PDU memFreePDU = session.get(memFreeOid);
        setRatioValueHelper(memUsedPDU,memFreePDU,collectObject);
    }

    return collectObject;
}
 
Example 3
Source File: SNMPHelper.java    From SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 判断传入的PDU是否带有可用的监控数据(PDU携带的第一个VariableBinding对象)
 * @param pdu
 * @return
 * true : 可用
 * false : 不可用
 */
public static boolean isValidPDU(PDU pdu){
    if(pdu == null){
        return false;
    }
    VariableBinding vb = pdu.get(0);
    if(vb == null){
        return false;
    }
    String vbResult = vb.toString();
    return !"noSuchInstance".equalsIgnoreCase(vbResult) &&
            !"noSuchObject".equalsIgnoreCase(vbResult) &&
            !"noNextInstance".equalsIgnoreCase(vbResult) &&
            !"endOfView".equalsIgnoreCase(vbResult);
}
 
Example 4
Source File: SNMPHelper.java    From SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 判断传入的PDU是否带有可用的监控数据
 * @param pdu
 * @param index
 * 指定的索引的VariableBinding对象
 * @return
 * true : 可用
 * false : 不可用
 */
public static boolean isValidPDU(PDU pdu,int index){
    if(pdu == null){
        return false;
    }
    VariableBinding vb = pdu.get(index);
    if(vb == null){
        return false;
    }
    String vbResult = vb.toString();
    return !"noSuchInstance".equalsIgnoreCase(vbResult) &&
            !"noSuchObject".equalsIgnoreCase(vbResult) &&
            !"noNextInstance".equalsIgnoreCase(vbResult) &&
            !"endOfView".equalsIgnoreCase(vbResult);
}
 
Example 5
Source File: SNMPHelper.java    From OpenFalcon-SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 判断传入的PDU是否带有可用的监控数据(PDU携带的第一个VariableBinding对象)
 * @param pdu
 * @return
 * true : 可用
 * false : 不可用
 */
public static boolean isValidPDU(PDU pdu){
    if(pdu == null){
        return false;
    }
    VariableBinding vb = pdu.get(0);
    if(vb == null){
        return false;
    }
    String vbResult = vb.toString();
    return !"noSuchInstance".equalsIgnoreCase(vbResult) &&
            !"noSuchObject".equalsIgnoreCase(vbResult) &&
            !"noNextInstance".equalsIgnoreCase(vbResult) &&
            !"endOfView".equalsIgnoreCase(vbResult);
}
 
Example 6
Source File: SNMPHelper.java    From OpenFalcon-SuitAgent with Apache License 2.0 5 votes vote down vote up
/**
 * 判断传入的PDU是否带有可用的监控数据
 * @param pdu
 * @param index
 * 指定的索引的VariableBinding对象
 * @return
 * true : 可用
 * false : 不可用
 */
public static boolean isValidPDU(PDU pdu,int index){
    if(pdu == null){
        return false;
    }
    VariableBinding vb = pdu.get(index);
    if(vb == null){
        return false;
    }
    String vbResult = vb.toString();
    return !"noSuchInstance".equalsIgnoreCase(vbResult) &&
            !"noSuchObject".equalsIgnoreCase(vbResult) &&
            !"noNextInstance".equalsIgnoreCase(vbResult) &&
            !"endOfView".equalsIgnoreCase(vbResult);
}
 
Example 7
Source File: SNMPHelper.java    From SuitAgent with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: SNMPHelper.java    From OpenFalcon-SuitAgent with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}