2014-11-14 63 views

回答

3

這取決於。

例如,從Debian的SNMP軟件包安裝的snmpget工具都以某種方式抱怨缺少OID並且沒有。

舉個例子,一些基本的SNMP的OID:

[email protected]:~# 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會抱怨:

[email protected]:~# 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 

然而,它會返回一個零代碼,信令它是「好的」,它不存在:

[email protected]:~# echo $? 
0 

如果你正在寫g從SNMP讀取自己的工具或腳本,這實際上取決於您知道OID丟失/無效的重要性。 I'd recommend checking out the net-snmp documentation/coding tutorials如果你正在尋找權威的例子。

編輯:這裏有一些的RFC如果這是你的東西排序(鏈接從萊克斯李的回答被盜)

  • RFC 3416, 4.2.1爲SNMP v2c的以上GET請求處理

    4.2.1。 GetRequest-PDU

    GetRequest-PDU是應 應用程序的請求生成和發送的。

    收到GetRequest-PDU後,接收SNMP實體會在變量綁定列表中處理 中的每個變量綁定,以產生一個 Response-PDU。響應PDU的所有字段具有與接收到的請求的相應字段相同的值,除了下面指示的 。每個變量綁定如下處理:

    (1)如果變量綁定的名稱完全匹配一個 變量此請求訪問,則變量 結合的值字段被設置爲指定 變量的值的名稱。 (2)否則,如果變量綁定的名稱沒有與此請求可訪問的任何(潛在)變量的對象IDENTIFIER前綴匹配的OBJECT IDENTIFIER前綴 ,則其值域設置爲「noSuchObject」。

    (3)否則,變量綁定的值字段被設置爲 「noSuchInstance」。

    如果任何變量綁定的處理是有原因的其他 比上面列出,則響應-PDU重新格式化其請求-id和變量綁定字段 相同的值 接收的GetRequest失敗-PDU,其錯誤狀態字段的值設置爲 爲「genErr」,並且其錯誤索引字段的值設置爲失敗變量綁定的 索引。

    否則,Response-PDU的錯誤狀態字段的值將 設置爲「noError」,並且其錯誤索引字段的值爲零。

    然後將生成的Response-PDU封裝到消息中。如果 結果消息的大小小於或等於 本地約束和發起者的最大消息大小,則將其 發送到GetRequest-PDU的發起者。

    否則,會生成一個備用Response-PDU。該備選的 響應PDU在其請求標識字段 中與接收到的GetRequest-PDU格式相同,其錯誤狀態 字段的值設置爲「tooBig」,其錯誤索引字段的值設置爲 零,以及一個空的變量綁定字段。這個備用的 響應PDU然後被封裝到消息中。如果 結果消息的大小小於或等於本地約束 和發起者的最大消息大小,則將其發送到GetRequest-PDU的發起者 。否則,snmpSilentDrops [RFC3418]計數器遞增,結果消息爲 丟棄。

  • RFC 1157, 4.1.2爲SNMP V1 GET請求處理

4.1.2。所述的GetRequest-PDU

  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- PDU的錯誤狀態字段的值爲noError,錯誤索引字段的值爲零。 GetResponse-PDU的request-id字段的值爲 收到的消息的值。

+1

注意的問題說:「怎麼樣是一個SNMP代理應該回應「,但你似乎已經回答」SNMP命令行工具應該如何響應「。萊克斯李的答案是正確的。 – Jolta 2014-11-17 10:33:09

+0

我使用了命令行實用程序,因爲它們實際上是標準的,並且提供了立即可用的響應。編輯帖子以添加RFC。 – 2014-11-20 15:36:31