Snmp4j上的时间窗问题

时间:2017-12-20 09:58:09

标签: java snmp snmp4j

我需要SNMP4J中的时间戳问题的解决方案。如何在不重启Java虚拟机的情况下解决此问题?我们因这个问题而陷入困境。 如果您有任何想法,请提出建议。

以下是我的示例代码:

        {
        **TransportMapping<?> transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);

        //target Creations:
        Target target = null;
        InetAddress inetAddress = InetAddress.getByName(ipAddress);
        target = new UserTarget();
        target.setAddress(new UdpAddress(inetAddress, port));
        target.setRetries(2);
        target.setTimeout(2500);
        target.setVersion(snmpVersion);
        target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
        target.setSecurityName(new OctetString("name1"));


        //Usm Obj Creations:
        byte[] engineId1=MPv3.createLocalEngineID();
        USM usm = new USM(SecurityProtocols.getInstance(),new OctetString(engineId1), 0);
        snmp.listen();


        byte[] engineId=snmp.discoverAuthoritativeEngineID(target.getAddress(), 2500);
        usm=new USM(SecurityProtocols.getInstance(),new OctetString(engineId), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        snmp.getUSM().addUser(new OctetString("name1"), new OctetString(engineId),new UsmUser(new OctetString("name1"), AuthMD5.ID,new OctetString("*123"), PrivDES.ID, new OctetString("Y:123"))));
        PDU pdu = new PDU();
            pdu = new ScopedPDU();
        pdu.add(new VariableBinding(new OID(oidValue)));
        pdu.setType(PDU.GETNEXT);
        pdu.setRequestID(new Integer32(1));
        out.println("Sending Request to Agent...");
        ResponseEvent response1 = snmp.getNext(pdu, target);
        // Process Agent Response
        if (response1 != null) {
            out.println("Got Response from Agent");
            PDU responsePDU = response1.getResponse();
            if (responsePDU != null) {
                int errorStatus = responsePDU.getErrorStatus();
                int errorIndex = responsePDU.getErrorIndex();
                String errorStatusText = responsePDU.getErrorStatusText();
                if (errorStatus == PDU.noError) {
                    out.println("Snmp Get Response = " + responsePDU.getVariableBindings());
                } else {
                    out.println("Error: Request Failed");
                    out.println("Error Status = " + `enter code here`errorStatus);
                    out.println("Error Index = " + errorIndex);
                    out.println("Error Status Text = " + errorStatusText);
                }
            } else {
                out.println("Error: Response PDU is null");
            }
        } else {
            out.println("Error: Agent Timeout... ");
        }
        snmp.close();**
    }

使用上面的代码,我可以发现一个新的engine_id,但我无法使用它。如果我使用engineId,则会引发usmUnknownEngineId错误。

0 个答案:

没有答案