SNMP代理如何响应对其没有价值的OID的get请求?

SNMP代理如何响应对其没有价值的OID的get请求?,snmp,Snmp,是否有响应表明该OID没有值,或者它应该什么也不返回?这取决于具体情况 例如,从Debian上的SNMP包安装的snmpget工具都会抱怨缺少OID,但在某种程度上没有 例如,一些基本的SNMP OID: root@debian:~# snmpwalk -v2c -cpublic localhost ... iso.3.6.1.2.1.1.5.0 = STRING: "debian" iso.3.6.1.2.1.1.6.0 = STRING: "Sitting on the Dock of th

是否有响应表明该OID没有值,或者它应该什么也不返回?

这取决于具体情况

例如,从Debian上的SNMP包安装的
snmpget
工具都会抱怨缺少OID,但在某种程度上没有

例如,一些基本的SNMP OID:

root@debian:~# snmpwalk -v2c -cpublic localhost
...
iso.3.6.1.2.1.1.5.0 = STRING: "debian"
iso.3.6.1.2.1.1.6.0 = STRING: "Sitting on the Dock of the Bay"
使用
snmpget
会在您向其提供缺少的OID时进行投诉:

root@debian:~# snmpget -v2c -cpublic localhost iso.3.6.1.2.1.1.6.1
iso.3.6.1.2.1.1.6.1 = No Such Instance currently exists at this OID
但是,它将返回一个零代码,表示它“可以”不存在:

root@debian:~# echo $?
0
如果您正在编写自己的从SNMP读取的工具或脚本,那么这实际上取决于您知道OID丢失/无效的重要性。如果你在寻找权威的例子

编辑:这里有一些RFC,如果你喜欢的话(从Lex Li的答案中盗取的链接)

  • 对于SNMP v2c及以上版本,获取请求处理

    4.2.1。getRequestPDU

             The form of the GetRequest-PDU is:
                  GetRequest-PDU ::=
                      [0]
                          IMPLICIT SEQUENCE {
                              request-id
                                  RequestID,
    
                              error-status        -- always 0
                                  ErrorStatus,
    
                              error-index         -- always 0
                                  ErrorIndex,
    
                              variable-bindings
                                  VarBindList
                          }
    
    一个GetRequest PDU在用户的请求下生成和传输 应用程序

    收到GetRequest PDU后,接收SNMP实体将处理 变量绑定列表中的每个变量绑定以生成 响应PDU。响应PDU的所有字段的值与 接收到的请求的相应字段,除非另有说明 在下面每个变量绑定的处理如下:

    (1) 如果变量绑定的名称与 此请求可访问的变量,然后 绑定的值字段设置为指定 变量 (2) 否则,如果变量绑定的名称没有 与对象完全匹配的对象标识符前缀 可由访问的任何(潜在)变量的标识符前缀 此请求,则其值字段设置为“noSuchObject”

    (3) 否则,变量绑定的值字段设置为 “noSuchInstance”

    如果任何变量绑定的处理因其他原因失败 然后使用 其请求id和变量绑定字段中的值与 已接收GetRequest PDU,其错误状态字段的值已设置 设置为“genErr”,其错误索引字段的值设置为 失败的变量绑定的索引

    否则,将设置响应PDU的错误状态字段的值 到“noError”,其错误索引字段的值为零

    然后将生成的响应PDU封装到消息中。如果 结果消息的大小小于或等于 本地约束和发起者的最大消息大小 发送给GetRequest PDU的发起人

    否则,将生成备用响应PDU。这个候补的 响应PDU在其请求id字段中使用相同的值进行格式化 作为接收到的GetRequest PDU,具有其错误状态的值 字段设置为“tooBig”,其错误索引字段的值设置为 零,以及一个空的变量绑定字段。这个候补的 然后将响应PDU封装到消息中。如果 结果消息小于或等于本地约束 以及发送到的发起者的最大消息大小 GetRequest PDU的发起人。否则,snmpsilent将下降 [RFC3418]计数器递增,结果消息为 丢弃

  • 对于SNMP v1获取请求处理

4.1.2。getRequestPDU

         The form of the GetRequest-PDU is:
              GetRequest-PDU ::=
                  [0]
                      IMPLICIT SEQUENCE {
                          request-id
                              RequestID,

                          error-status        -- always 0
                              ErrorStatus,

                          error-index         -- always 0
                              ErrorIndex,

                          variable-bindings
                              VarBindList
                      }
GetRequest PDU仅由协议实体在 其SNMP应用程序实体的请求

收到GetRequest PDU后,接收协议实体 根据以下列表中的任何适用规则进行响应:

    (1)  If, for any object named in the variable-bindings field,
         the object's name does not exactly match the name of some
         object available for get operations in the relevant MIB
         view, then the receiving entity sends to the originator
         of the received message the GetResponse-PDU of identical
         form, except that the value of the error-status field is
         noSuchName, and the value of the error-index field is the
         index of said object name component in the received
         message.

    (2)  If, for any object named in the variable-bindings field,
         the object is an aggregate type (as defined in the SMI),
         then the receiving entity sends to the originator of the
         received message the GetResponse-PDU of identical form,
         except that the value of the error-status field is
         noSuchName, and the value of the error-index field is the
         index of said object name component in the received
         message.

    (3)  If the size of the GetResponse-PDU generated as described
         below would exceed a local limitation, then the receiving
         entity sends to the originator of the received message
         the GetResponse-PDU of identical form, except that the
         value of the error-status field is tooBig, and the value
         of the error-index field is zero.

    (4)  If, for any object named in the variable-bindings field,
         the value of the object cannot be retrieved for reasons
         not covered by any of the foregoing rules, then the
         receiving entity sends to the originator of the received
         message the GetResponse-PDU of identical form, except
         that the value of the error-status field is genErr and
         the value of the error-index field is the index of said
         object name component in the received message.
如果上述规则均不适用,则接收协议 实体向接收到的消息的发起人发送 GetResponse PDU,这样,对于变量中命名的每个对象- 收到消息的绑定字段,对应的组件 GetResponse PDU的名称和值 变量GetResponse的error-status字段的值- PDU为无错误,错误索引字段的值为零。这个 GetResponse PDU的请求id字段的值是
收到消息。

行为遵循标准RFC文档,如

  • 对于SNMP v2c及以上版本,获取请求处理
  • 对于SNMP v1获取请求处理

请注意,问题是“SNMP代理应该如何响应”,但您似乎回答了“SNMP命令行工具应该如何响应”。Lex Li的答案是正确的。我使用了命令行实用程序,因为它们实际上是标准的,并且它提供了一个立即可用的响应。编辑帖子以添加RFC。