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


Java PDU.get方法代码示例

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


在下文中一共展示了PDU.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getCisco_IOS_XR_Mem

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

示例3: snmpWalk

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

示例4: testPreparePduWithNoValues

import org.snmp4j.PDU; //导入方法依赖的package包/类
@Test
public void testPreparePduWithNoValues() throws Exception {
    SnmpObjId[] oids = new SnmpObjId[] {
            SnmpObjId.get(".1.3.5.1.1.3.0"),
            SnmpObjId.get(".1.3.5.1.1.4.0"),
    };
    
    SnmpValue[] values = null;
    
    PDU pdu = m_strategy.buildPdu(new Snmp4JAgentConfig(getAgentConfig()), PDU.SET, oids, values);
    assertNotNull("PDU should not be null", pdu);
    
    assertEquals("PDU variable bindings size", oids.length, pdu.getVariableBindings().size());
    
    for (int i = 0; i < oids.length; i++) {
        VariableBinding vb = pdu.get(i);
        assertEquals("PDU variable binding " + i + " OID", oids[i].toString(), "." + vb.getOid().toString());
        assertEquals("PDU variable binding " + i + " syntax", vb.getSyntax(), SMIConstants.SYNTAX_NULL);
        assertEquals("PDU variable binding " + i + " variable syntax", vb.getVariable().getSyntax(), SMIConstants.SYNTAX_NULL);
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:22,代码来源:Snmp4JStrategyTest.java

示例5: testPreparePduWithValues

import org.snmp4j.PDU; //导入方法依赖的package包/类
@Test
public void testPreparePduWithValues() throws Exception {
    SnmpObjId[] oids = new SnmpObjId[] {
            SnmpObjId.get(".1.3.5.1.1.3.0"),
            SnmpObjId.get(".1.3.5.1.1.4.0"),
    };
    
    SnmpValue[] values = new SnmpValue[] {
            snmpValue("foo"),
            snmpValue("bar")
    };
    
    PDU pdu = m_strategy.buildPdu(new Snmp4JAgentConfig(getAgentConfig()), PDU.SET, oids, values);
    assertNotNull("PDU should not be null", pdu);
    
    assertEquals("PDU variable bindings size", oids.length, pdu.getVariableBindings().size());
    
    for (int i = 0; i < oids.length; i++) {
        VariableBinding vb = pdu.get(i);
        assertEquals("PDU variable binding " + i + " OID", oids[i].toString(), "." + vb.getOid().toString());
        assertEquals("PDU variable binding " + i + " syntax", vb.getSyntax(), SMIConstants.SYNTAX_OCTET_STRING);
        assertEquals("PDU variable binding " + i + " variable syntax", vb.getVariable().getSyntax(), SMIConstants.SYNTAX_OCTET_STRING);
        assertEquals("PDU variable binding " + i + " variable value", vb.getVariable().toString(), values[i].toString());
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:Snmp4JStrategyTest.java

示例6: isValidPDU

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * 判断传入的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);
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:22,代码来源:SNMPHelper.java

示例7: getIpOfGateway

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static String getIpOfGateway(){  
    String gatewayIpString=null; //网关ip地址是这个字符串的子串  
    String gatewayIp=null;  // 这是代表网关ip  
    try {  
         
        /** 
         * Set properties of target 
         */  
        CommunityTarget localhost = new CommunityTarget();  
        Address address = GenericAddress.parse("udp:127.0.0.1/161");  
        localhost.setAddress(address);  
        localhost.setCommunity(new OctetString("public"));    
        localhost.setRetries(2);   
        localhost.setTimeout(5*60);   
        localhost.setVersion(SnmpConstants.version2c);  
        /** 
         * Set protocols of UDP and SNMP 
         */  
        TransportMapping transport = new DefaultUdpTransportMapping();   
        transport.listen();  
        Snmp protocol = new Snmp(transport);  
        /** 
         * OID binding 
         */  
        PDU requestPDU = new PDU();  
        requestPDU.add(new VariableBinding(new OID("1.3.6.1.2.1.4.21.1.7")));//ipRouteNextHop  
        requestPDU.setType(PDU.GETNEXT);  
        /** 
         * 
         */  
        ResponseEvent responseEvent = protocol.send(requestPDU, localhost);  
        PDU responsePDU=responseEvent.getResponse();  
        if(responsePDU!=null){  
            VariableBinding getIp=responsePDU.get(0);  
            gatewayIpString=getIp.toString();  
        }  
    } catch (IOException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    }  
    gatewayIp=gatewayIpString.substring(31);  
    return gatewayIp;  
     
}
 
开发者ID:waylau,项目名称:snmp4j-demos,代码行数:45,代码来源:Snmp4jData.java

示例8: walk

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static List<VariableBinding> walk(Target target, OID oid) {
    List<VariableBinding> ret = new ArrayList<VariableBinding>();

    PDU requestPDU = new PDU();
    requestPDU.add(new VariableBinding(oid));
    requestPDU.setType(PDU.GETNEXT);
    boolean finished = false;
    try{
        while (!finished) {
            VariableBinding vb = null;

            ResponseEvent respEvt = snmp.send(requestPDU, target);
            PDU responsePDU = respEvt.getResponse();
            if (responsePDU != null) {
                vb = responsePDU.get(0);
            }

            if (responsePDU == null) {
                finished = true;
            } else if (responsePDU.getErrorStatus() != 0) {
                finished = true;
            } else if (vb.getOid() == null) {
                finished = true;
            } else if (vb.getOid().size() < oid.size()) {
                finished = true;
            } else if (oid.leftMostCompare(oid.size(), vb.getOid()) != 0) {
                finished = true;
            } else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
                finished = true;
            } else if (vb.getOid().compareTo(oid) <= 0) {
                finished = true;
            } else {
                ret.add(vb);

                // Set up the variable binding for the next entry.
                requestPDU.setRequestID(new Integer32(0));
                requestPDU.set(0, vb);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return ret;
}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:45,代码来源:SNMPUtil.java


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