snmp4j 代理响应 snmpget 请求,但无法响应 snmpwalk 请求

问题描述 投票:0回答:1

我正在尝试创建一个可以响应 snmp v3 walk (getBulk) 请求的 snmp4j 代理。我设法从 snmp4j 库中运行 SampleAgent 类,并能够响应 snmp get 请求。然而,当涉及到 getBulk 请求时,它只是以错误 oid 进行响应。日志似乎也没有表明任何错误。我对 snmp 很陌生,非常感谢任何帮助。

错误信息:

  VBS[1.3.6.1.2.1.11.32.0 = 1]

这意味着

"The total number of Confirmed Class PDUs
(such as GetRequest-PDUs, GetNextRequest-PDUs,
GetBulkRequest-PDUs, SetRequest-PDUs, and
InformRequest-PDUs) delivered to the SNMP entity which
were silently dropped because the transmission of
the (possibly translated) message to a proxy target
failed in a manner (other than a time-out) such that
no Response Class PDU (such as a Response-PDU) could
be returned."

oid 的配置如下

        OID oid = new OID("1.3.6.1.2.1.2.2.1");
        try{
            MOTableSubIndex[] subIndexes = { v4Agent.getFactory().createSubIndex(null, SMIConstants.SYNTAX_OCTET_STRING, 1, 100)};
            MOTableIndex moTableIndex = new MOTableIndex(subIndexes);
            MOColumn[] moColumns = {
                        v4Agent.getFactory().createColumn(5, SMIConstants.SYNTAX_OCTET_STRING, v4Agent.getFactory().createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY)),
                        v4Agent.getFactory().createColumn(10, SMIConstants.SYNTAX_OCTET_STRING, v4Agent.getFactory().createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY)),
                        v4Agent.getFactory().createColumn(16, SMIConstants.SYNTAX_OCTET_STRING, v4Agent.getFactory().createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY)),
                        v4Agent.getFactory().createColumn(7, SMIConstants.SYNTAX_OCTET_STRING, v4Agent.getFactory().createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY)),
                        v4Agent.getFactory().createColumn(8, SMIConstants.SYNTAX_OCTET_STRING, v4Agent.getFactory().createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY)),
            };

            DefaultMOTable<MOTableRow, MOColumn, MOTableModel<MOTableRow>> table = new DefaultMOTable<>(oid, moTableIndex, moColumns);

            table.setModel(v4Agent.getFactory().createTableModel(oid, moTableIndex, moColumns));

            DefaultMOMutableTableModel model = (DefaultMOMutableTableModel) table.getModel();
            model.setRowFactory((MOTableRowFactory) v4Agent.getFactory());

            addRow(model, String.valueOf(1), new Variable[]{new OctetString("yo"), new OctetString("11"), new Counter32(1), new Counter64(11), new Integer32(1)});
            addRow(model, String.valueOf(2), new Variable[]{new OctetString("howdy"), new OctetString("22"), new Counter32(2), new Counter64(22), new Integer32(2)});
            addRow(model, String.valueOf(3), new Variable[]{new OctetString("wassup"), new OctetString("33"), new Counter32(3), new Counter64(33), new Integer32(3)});

            v4Agent.server.register(table, null);
        } catch (DuplicateRegistrationException e){
            logger.error("duplicated oid ", e);
        }
        //add view to oid
        addView(v4Agent, oid);

        ...
        private static void addRow(DefaultMOMutableTableModel model, String oid, Variable[] value) {
            model.addRow(model.createRow(new OID(oid), value));
        }

和日志

2024-02-29 16:06:20.785 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG Received message from /127.0.0.1/51996 with length 138: 30:81:87:02:01:03:30:10:02:03:00:95:67:02:03:00:ff:ff:04:01:07:02:01:03:04:36:30:34:04:0d:80:00:13:70:01:c0:a8:79:00:71:af:e2:79:02:01:01:02:02:0d:99:04:04:75:73:65:72:04:0c:43:21:8a:83:3e:09:bf:55:ff:63:5f:a2:04:08:00:00:00:01:29:13:98:26:04:38:ce:88:5e:f0:17:f0:36:a9:53:00:93:55:d0:67:21:5b:19:4a:26:cb:35:a2:f0:20:8f:a2:00:8c:9d:ea:4e:5f:1d:07:65:d9:71:45:96:80:20:34:be:7b:2d:ed:24:18:5e:2b:c3:37:00:c3:93:ba
2024-02-29 16:06:20.785 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG SNMPv3 header decoded: msgId=38247, msgMaxSize=65535, msgFlags=07, secModel=3
2024-02-29 16:06:20.785 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG PduHandle for messageID 38247 not found in MPv3.Cache
2024-02-29 16:06:20.785 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG getUser(engineID=80:00:13:70:01:c0:a8:79:00:71:af:e2:79, securityName=user)
2024-02-29 16:06:20.786 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG CheckTime: time ok (authoritative)
2024-02-29 16:06:20.786 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG RFC3412 ��7.2.10 - Received PDU is NOT a response or internal class message -> unchanged PduHandle = PduHandle[872645]
2024-02-29 16:06:20.786 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG Adding cache entry: StateReference[msgID=38247,pduHandle=PduHandle[872645],securityEngineID=80:00:13:70:01:c0:a8:79:00:71:af:e2:79,securityModel=org.snmp4j.security.USM@694abbdc,securityName=user,securityLevel=3,contextEngineID=0002651100[02],contextName=,retryMsgIDs=null]
2024-02-29 16:06:20.786 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG Fire process PDU event: CommandResponderEvent[securityModel=3, securityLevel=3, maxSizeResponsePDU=65353, pduHandle=PduHandle[872645], stateReference=StateReference[msgID=38247,pduHandle=null,securityEngineID=80:00:13:70:01:c0:a8:79:00:71:af:e2:79,securityModel=org.snmp4j.security.USM@694abbdc,securityName=user,securityLevel=3,contextEngineID=0002651100[02],contextName=,retryMsgIDs=null], pdu=GETBULK[{contextEngineID=0002651100[02], contextName=}, requestID=872645, errorStatus=0, errorIndex=10, VBS[1.3.6.1.2.1.2.2.1.5 = Null]], messageProcessingModel=3, securityName=user, processed=false, peerAddress=127.0.0.1/51996, transportMapping=org.snmp4j.transport.DefaultUdpTransportMapping@527740a2, tmStateReference=TransportStateReference[transport=org.snmp4j.transport.DefaultUdpTransportMapping@527740a2, address=127.0.0.1/161, securityName=null, requestedSecurityLevel=undefined, transportSecurityLevel=undefined, sameSecurity=false, sessionID=java.net.DatagramSocket@73af1184, target=null]]
2024-02-29 16:06:20.787 DefaultUDPTransportMapping_127.0.0.1/161 DEBUG Processing proxy request with proxy forwarder org.snmp4j.agent.mo.snmp.ProxyForwarderImpl@63801ac3
2024-02-29 16:06:20.787 SampleAgent.0 INFO No matching proxy entry found for contextEngineID=0002651100[02], context= and request=org.snmp4j.agent.ProxyForwardRequest[coexistenceInfo=CoexistenceInfo[securityName=user,contextEngineID=0002651100[02],contextName=,transportTag=null],proxyType=1,commandEvent=CommandResponderEvent[securityModel=3, securityLevel=3, maxSizeResponsePDU=65353, pduHandle=PduHandle[872645], stateReference=StateReference[msgID=38247,pduHandle=null,securityEngineID=80:00:13:70:01:c0:a8:79:00:71:af:e2:79,securityModel=org.snmp4j.security.USM@694abbdc,securityName=user,securityLevel=3,contextEngineID=0002651100[02],contextName=,retryMsgIDs=null], pdu=GETBULK[{contextEngineID=0002651100[02], contextName=}, requestID=872645, errorStatus=0, errorIndex=10, VBS[1.3.6.1.2.1.2.2.1.5 = Null]], messageProcessingModel=3, securityName=user, processed=false, peerAddress=127.0.0.1/51996, transportMapping=org.snmp4j.transport.DefaultUdpTransportMapping@527740a2, tmStateReference=TransportStateReference[transport=org.snmp4j.transport.DefaultUdpTransportMapping@527740a2, address=127.0.0.1/161, securityName=null, requestedSecurityLevel=undefined, transportSecurityLevel=undefined, sameSecurity=false, sessionID=java.net.DatagramSocket@73af1184, target=null]]]
2024-02-29 16:06:20.787 SampleAgent.0 DEBUG Removed msgId retry cache sub-entry: 38247 from msgIdToPduHandleMapping: PduHandle[872645]
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Removed cache entry: StateReference[msgID=38247,pduHandle=null,securityEngineID=80:00:13:70:01:c0:a8:79:00:71:af:e2:79,securityModel=org.snmp4j.security.USM@694abbdc,securityName=user,securityLevel=3,contextEngineID=0002651100[02],contextName=,retryMsgIDs=null] for PduHandle[872645]
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Removed cache entry on getEntry: StateReference[msgID=38247,pduHandle=PduHandle[872645],securityEngineID=80:00:13:70:01:c0:a8:79:00:71:af:e2:79,securityModel=org.snmp4j.security.USM@694abbdc,securityName=user,securityLevel=3,contextEngineID=0002651100[02],contextName=,retryMsgIDs=null] for msgID 38247
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG RFC3414 ��3.1.4.a Outgoing message needs to be encrypted
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Preparing decrypt_params.
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Preparing iv for encryption.
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Encryption finished.
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Sending message to 127.0.0.1/51996 from 127.0.0.1/161 with length 129: 30:7f:02:01:03:30:10:02:03:00:95:67:02:03:00:ff:ff:04:01:03:02:01:03:04:36:30:34:04:0d:80:00:13:70:01:c0:a8:79:00:71:af:e2:79:02:01:01:02:02:0d:99:04:04:75:73:65:72:04:0c:18:c1:52:a5:62:cc:88:fa:03:3c:d5:b5:04:08:00:00:00:01:d4:92:15:49:04:30:51:3c:5d:46:07:b1:1d:b9:67:62:b0:af:85:fa:24:2c:8e:3e:88:d1:7d:8c:5e:e1:d7:3d:77:da:f7:d0:c8:b4:59:ef:04:54:48:d2:d2:a5:0d:f7:9f:d0:06:d7:6d:70
2024-02-29 16:06:20.788 SampleAgent.0 DEBUG Sending packet to 127.0.0.1/51996
java snmp snmp4j snmpwalk
1个回答
0
投票

问题解决了。

事实证明经纪人没问题,问题出在经理身上。

经理在行走时在 pdu 中设置上下文引擎 id,这导致代理寻找不存在的代理...

删除它,一切正常

© www.soinside.com 2019 - 2024. All rights reserved.