SNMP、MIB、OID概念的理解
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
1.1. SNMP概覽
SNMP的基本知識介紹
簡單網(wǎng)絡(luò)管理協(xié)議(SNMP-Simple Network Management Protocol) 是一個與網(wǎng)絡(luò)設(shè)備交互的簡單方法。該規(guī)范是由IETF在1990年五月發(fā)布的RFC 1157中定義的。SNMP通常被認為相當難懂,并且過于復(fù)雜,其可用的API似乎在本來非常簡單的東西外面封裝了大量的東西。現(xiàn)在關(guān)于SNMP的書籍又 往往只是把它更加復(fù)雜化了,而沒有解釋清楚。
SNMP對于任何程序設(shè)計人員來說是特別易于理解的。總體的簡化能夠很好地把這個系統(tǒng)簡化。一個網(wǎng)絡(luò)設(shè)備以守護進程的方式運行SNMP代理,該守護進程能夠響應(yīng)來自網(wǎng)絡(luò)的各種請求信息。該SNMP代理提供大量的對象標識符(OID-Object Identifiers)。一個OID是一個唯一的鍵值對。該代理存放這些值并讓它們可用。一個SNMP管理器(客戶)可以向代理查詢鍵值對中的特定信息。從程序員的角度看,這和導(dǎo)入大量的全局變量沒有多少區(qū)別。SNMP的OID是可讀或可寫的。盡管向一個SNMP設(shè)備寫入信息的情況非常少,但它是各種管理應(yīng)用程序用來控制設(shè)備的方法(例如針對交換機的可管理GUI)。SNMP中有一個基本的認證框架,能夠讓管理員發(fā)送公共名來對OID讀取或?qū)懭氲恼J證。絕大多數(shù)的設(shè)備使用不安全的公共名 "public" 。 SNMP協(xié)議通過UDP端口161和162進行通信的。
注意,我還沒有提到MIB!MIB的重要性被大大地夸大了。剛開始時,MIB顯得非常復(fù)雜,但是它們其實非常簡單。OID是數(shù)字的和全局的鍵值對。一個OID看起來和一個IPv6的地址很象,并且不同的廠商有不同的前綴等信息。OID都非常長,使得人們難以記住,或者對他非常感冒。因此,人們就設(shè)計了一種將數(shù)字OID翻譯為人們可讀的格式。這種翻譯映射被保存在一個被稱為 “管理信息基礎(chǔ)"(Management Infomation Base) 或MIB的、可傳遞的無格式文本文件里。使用SNMP或者向SNMP設(shè)備查詢,你不需要使用MIB,但是,如果沒有MIB,你就得猜測你正在查看的數(shù)據(jù)是 什么。某些情況下,不使用MIB也非常簡單,例如查看主機名、磁盤使用率數(shù)字,或者端口狀態(tài)信息。其他情況下,就非常困難了,這個時候使用MIB就非常有 幫助。對于準備編寫的應(yīng)用程序來說,為了讓用戶避免妥當安裝MIB帶來的麻煩,而嚴格使用數(shù)字OID是并不是很少見的。安裝一個MIB的動作,只是將他放置到你的SNMP客戶端應(yīng)用軟件能夠搜索到并進行上述翻譯映射工作的某個位置而已。
SNMP 可以按照兩種方式來使用:輪詢和陷阱。輪詢就是說你編寫一個應(yīng)用程序能夠設(shè)置一個發(fā)送給一個SNMP代理查看某些值的SNMP GET請求。這種方法非常有用,因為如果該設(shè)備響應(yīng)了請求,你就得到了你需要的信息,如果該設(shè)備沒有響應(yīng)請求,你就能夠知道存在某些問題。輪詢是網(wǎng)絡(luò)監(jiān)控 的一種主動形式。另一方面,SNMP陷阱能夠被用來進行被動形式的網(wǎng)絡(luò)監(jiān)控。SNMP陷阱是通過配置SNMP設(shè)備的代理,讓他在某些動作發(fā)生時聯(lián)系另一個SNMP代理來實現(xiàn)的。
備,可以配置為在某些事件發(fā)生時發(fā)送SNMP陷阱。例如,你可以配置Cisco的IOS在某個獨立事件(例如鏈路斷開)發(fā)生時,或者在任何定義的陷阱事件發(fā)生時,發(fā)送SNMP陷阱。(IOS:snmp 服務(wù)器開啟了鏈路斷開的snmp陷阱)。當陷阱事件發(fā)生時,設(shè)備中的snmp代理會發(fā)送該陷阱到一個預(yù)先配置好的通常成為陷阱主機的目標上。陷阱主機會運 行有自己的SNMP代理,該代理能夠接受并處理傳入的陷阱。這些陷阱的處理由陷阱處理器來完成。陷阱處理器可以用任何語言編寫,并且可以通過 STDIN(標準輸入)傳入的來自發(fā)送陷阱的信息。該處理器之后可以根據(jù)陷阱進行任何想作的事情,例如發(fā)送郵件或者你想要的任何事情。
SNMP被廣泛應(yīng)用在NMS網(wǎng)絡(luò)管理系統(tǒng)中(Network Management System)。知名的NMS包括BMC的Patrol、CA的Unicenter、Sun Mangegement控制臺、IBM的Tivoli Netview、以及全球著名的HP Openview。 NMS的目標是提供一個監(jiān)控和管理所有開啟SNMP功能的設(shè)備的單一入口。通過配置你的設(shè)備代理來接受寫訪問,你可以從一個應(yīng)用程序中處理你的網(wǎng)絡(luò)環(huán)境。 如果你的整個環(huán)境圍攏NMS解決方案架構(gòu)你的環(huán)境,你就能無限制地控制、查看你的整個網(wǎng)絡(luò)。盡管Net-SNMP提供了可用來構(gòu)建你自己的NMS網(wǎng)管系統(tǒng) 的所有工具,我們不會再進一步討論關(guān)于NMS的話題。不過請記住,如果你認為你的SNMP設(shè)備廠商沒有提供SNMP代理方面的詳細信息,很可能是因為他們 希望你購買他們的NMS網(wǎng)絡(luò)管理系統(tǒng),或者購買能夠在另一個NMS平臺上使用的插件。
1.2. SNMP的三大版本
SNMP的常用版本有三個:SNMPv1、SNMPv2、SNMPv3
Three different version of SNMP exist: SNMPv1 (RFC’s 1155, 1157, and 1212), SNMPv2c (RFC’s 1901 through 1908), and SNMPv3 (RFC’s 3411 though 3418). The co-existence of all three versions are detailed in RFC 3584.SNMP有三個不同的版本:SNMPv1(RFC 1155、RFC 1157、RFC 1212),SNMPv2c (RFC 1901、1908)以及 SNMPv3 (RFC 3411 - 3418). RFC 3584中詳細說明了這三種版本同時共存方面的信息。
SNMPv1 is the original standard for community based management. SNMPv2 was derived from the SNMPv1 framework but had no message definition, which was later revamped aa SNMPv2c, a community based version of SNMPv2 with a message format similar to SNMPv1. SNMPv2 added several new datatypes (Counter32, Counter64, Gauge32, UInteger32, NsapAdress, and BIT STRING), as well as enhancements to OID tables and the setting of OID values. SNMPv3 is an extensable SNMPv2 framework with a new message format, ACL and security abilities, and remote configuration of SNMP parameters.
SNMPv1是為基于公共管理的初始標準。SNMPv2是SNMPv1框架下衍生出來的,但是沒有定義信息,其后修訂為SNMPv2c,一個帶有于SNMPv1類似信息格式的給予公共管理的版本。SNMPv2添加了幾個新的數(shù)據(jù)類型(Counter32、Counter64、Gauge32、UInteger32、NsapAdress 以及BIT STRING),以及對OID表和OID值的設(shè)置的增強。SNMPv3是一個帶有新的信息格式、ACL、安全功能和遠處SNMP參數(shù)配置的、擴展了SNMPv2框架的版本。
SNMP is based on several other standards including the Abstract Syntax Notation 1 Basic Encoding Rules (ASN.1 BER) which defines the SNMP used Datatypes and the Structure of Management Information (SMI) which details the grammar used by SNMP MIBs. SMI comes in two varieties: SMIv1 (RFC 1155) and SMIv2 (RFC 2578). SMIv1 is now obsolete and should not be used. If you choose to modify MIBs at some point you’ll need to learn SMIv2 and ASN.1 syntax, but otherwise they are interesting but unnecessary to learn.
SNMP是基于幾個其他規(guī)范的,包括定義給予SNMP的數(shù)據(jù)類型的ASN.1 BER(Abstract Syntax Notation 1 Basic Encoding Rules), 以及詳細描述有SNMP MIB使用的語法的管理信息結(jié)構(gòu)(SMI)。SMIv1目前被獨立出來,不應(yīng)當再被使用。如果你選擇修改MIB的某些東西,你需要學(xué)習(xí)SMIv2和ASN.1語法,不過其他情況下你只需要在興趣時看看他,而不必學(xué)習(xí)他。
To this day, SNMPv1 and SNMPv2c are the most commonly used, however due to the insecurity inherent to these protocols read-only access is typical. In general, don’t bother with SNMPv3 unless you really need the added security features.
現(xiàn)在,SNMPv1和SNMPv2被廣泛應(yīng)用,但是由于這些協(xié)議的不安全特性,通常只使用只讀訪問。通常,除非你確實需要附加安全特性,否則你不需要過多地關(guān)注SNMPv3。SNMPv3是具有安全性的通信協(xié)議。
1.3. 本文不涉及的話題
本文中不會涉及如何編寫代理、MIB模塊等方面的話題。
There are several subject we will not be discussing in this paper. These topics include writing agents or sub-agents, writing MIB modules, trap generation and trap sending, synchronous vs asynchronous SNMP coding, and MIB parsing.
本文中,有幾個主題我們不會討論。這些主題包括編寫代理或子代理,編寫MIB模塊、陷阱生成以及陷阱發(fā)送、同步和一步SNMP代碼編寫,以及MIB解釋器。
Something that scares new or inexperienced coders away from the Net-SNMP documentation is the seemingly constant reference to synchronous and asynchronous applications. Don’t be afraid, thats referring to applications that can’t afford to sit and wait for a response. If your application needs a non-blocking method of handling SNMP traffic, use the asynchronous interface (eg: GUIs, Threads, Forking, etc). Otherwise, just stick with the synchronous interfaces for typical use.
Net-SNMP中關(guān)于同步和異步應(yīng)用程序的文檔,常常會把沒有經(jīng)驗的編碼新手給嚇唬住。別擔(dān)心,那只是指無法坐等響應(yīng)的應(yīng)用程序。如果你的應(yīng)用程序需要以非阻塞方式處理SNMP數(shù)據(jù)流,就使用一步接口(例如GUI、線程、forking等)。否則,只需要使用同步接口就可以了。
Lastly, this document addresses the use of Net-SNMP on UNIX systems only. Please refer to the Net-SNMP website for information regarding development on Win32.
本文中的后面會針對Unix系統(tǒng)中使用的問題,請參考Net-SNMP網(wǎng)站了解關(guān)于在Win32中開發(fā)的信息。
2. MIB和OID
OID(對象標識符),是SNMP代理提供的具有唯一標識的鍵值。MIB(管理信息基)提供數(shù)字化OID到可讀文本的映射。
2.1. OID
OID的編寫規(guī)則和習(xí)慣
SNMP OIDs are laid out in a hierarchy forming unique addresses into a tree similar to the DNS hierarchy. Like many other forms of addressing, OIDs can be used in 2 forms: fully qualified and relative (sometimes called ”relevant”).
SNMP OID是用一種按照層次化格式組織的、樹狀結(jié)構(gòu)中的唯一地址來表示的,它與DNS層次相似。與其他格式的尋址方式類型,OID以兩種格式加以應(yīng)用:全名和先對名(有時稱為“相關(guān)”)
The fully qualified form starts from the root and moves outward to the individual value on a device. An example of a fully qualified address is:
完全驗證格式從root根開始,并且向外移到某個設(shè)備的獨立的質(zhì)上。例如一個完整驗證的地址為:
This OID could be rewritten in human readable form as:
該OID可用人們可讀的方式重寫為:
All fully qualified OIDs will begin with .iso.org.dod.internet.private represented numerically as .1.3.6.1.4. Almost all OIDs will then be followed by enterprises (.1) and a unique number for the vendor as assigned by the Internet Assigned Numbers Authority (IANA). In the example OID 789 represents the vendor ID for the Network Appliance Corporation (NetApp). Everything beyond the vendor ID is based on the vendors implementation and may vary between implementations. Please note the prefixing dot before iso. Similar to the trailing dot in DNS, properly qualified IODs begin with a dot representing the root.
所有完全驗證OID都有 .iso.org.dod.internet.private 開始,數(shù)字表達為: .1.3.6.4. 。幾乎所有的OID都會跟上企業(yè)(.1)和由IANA(互聯(lián)網(wǎng)編號分配中心分配的)唯一的廠商標號。例如OID 789表示Network Appliance格式的廠商編號( NetApp )。廠商編號后面的是基于廠商實現(xiàn)的功能,并且各不相同。請注意,在iso.前面的 . ` ,與DNS中的后點相似,正確驗證的OID是有一個表示根的前綴 `. 開始的。
The complete list of enterprise assignments can be found at the IANA website: http://www.iana.org/assignments/enterprise-numbers
IANA網(wǎng)站上找到企業(yè)分配完整的清單 : http://www.iana.org/assignmenets/enterprise-numbers
The relative form of an OID, on the other hand, begins from the enterprises value and leaves all the implied addressing off. So we can use the relative form of the above OID as enterprises.netapp.netapp1.raid.diskSummary.diskSpareCount.0 or numerically as .1.789.1.6.4.8.0 .
OID的相對格式,從企業(yè)值開始,略過所有的隱含地址。因此,我們可以用相對地址 enterprises.netapp.netappl.raid.diskSUmmary.diskSpaceCount.0 來表示上述的OID,或者用數(shù)字格式 .1.789.6.4.8.0 .
A common form of writing OIDs is by the name of the MIB and a unique key defined within the MIB. For instance, we could rewrite the above OID into the condensed form NETWORK-APPLIANCE-MIB::diskSpareCount.0 . This condensed form follows the convention of MIB Name::Unique Key.instance. Some keys, while unique, can be represented by multiple instances of that key, and thus all OIDs end with an instance value. This is why you’ll notice that most OIDs end with a .0 .
寫OID的常用格式是用MIB名稱和在MIB中定義的唯一鍵值。例如,我們可以用簡寫的格式重寫上述OID:
NETWORK-APPLIANCE-MIB::diskSpareCount.0
MIB中OID的書寫格式規(guī)則為::MIB Name::唯一鍵值.instance.
某些唯一鍵值,可用多個實例表示,這樣所有的OID都以實例值結(jié)尾。這就是為什么你得注意到大多數(shù)OID都是以一個 .0 結(jié)尾的。
2.2. MIB
MIB介紹
The structure of a MIBs internals are a little strange and foreign at first, but it’s structured well enough that you can poke through it pretty intelligently without really knowing what your doing. The structure of a MIB comes from the Structure of Management Information (SMI) standard detailed in IETF RFC 1155 and 2578. If you choose to modify or write your own MIBs you’ll benefit from understanding SMI before hacking much on MIBs.
MIB的內(nèi)部結(jié)構(gòu)剛開始時會讓人感覺有些奇怪和不好理解,不過它的結(jié)構(gòu)非常好,你可以在不懂的情況下一個一個看進去。MIB的結(jié)構(gòu)來源于IETF RFC1155和2578定義的管理信息結(jié)構(gòu)。如果你想要修改或編寫自己的MIB,在動手前理解SMI非常有幫助。
Lets look at the header of a MIB to get a better idea of how they work:
為了更好地理解他們是怎樣工作的,我們先來看看MIB的頭:
-- PowerNet-MIB {iso org(3) dod(6) internet(1) private(4)
-- enterprises(1) apc(318) }
PowerNet-MIB DEFINITIONS ::= BEGIN
IMPORTS
enterprises, IpAddress, Gauge, TimeTicks FROM RFC1155-SMI
DisplayString FROM RFC1213-MIB
OBJECT-TYPE FROM RFC-1212
TRAP-TYPE FROM RFC-1215;
apc OBJECT IDENTIFIER ::= { enterprises 318 }
products OBJECT IDENTIFIER ::= { apc 1 }
apcmgmt OBJECT IDENTIFIER ::= { apc 2 }
Comments can be inserted into a MIB by prepending them with two dashes. In the header the declaration BEGIN starts off the MIB. Imports can be used to pull information from other MIBs, typically those mandated by the MIB-II standard.
可以用行開頭為 -- 的方法在MIB中加入注釋。
在頭部用 BEGIN`聲明來開始MIB的定義。
`Imports 可用來從其他MIB中提取信息,通常用它來提取MIB-II規(guī)范要求的內(nèi)容。
The MIB lays out the structure of OID addresses starting from the enterprises value. Here the enterprise value 318 maps to ”apc” (relative address .1.318). Typically then several categories are defined. Here we see 2 categories: products (.1.318.1) and apcmgmt (.1.318.2). Notice that in the curly braces two values are specified, its parent address followed by its address. So the products identifier is parented by the apc identifier which is parented by the enterprises identifier, so on and so forth. This type of categorization and subcategorizing will typically continue on in the header of the MIB for awhile segmenting the available keys into tight subgroupings. By segmenting values out in this way it makes the available keys easier to navigate.
MIB放置從enterprise值開始的OID地 址的結(jié)構(gòu)。在此,enterprise值是318, 對應(yīng) "apc" (相對地址為 .1.318)。 通常之后會定義幾個類別。注意在花括號間定義的兩個值,其父地址后面跟一個它自己的地址。因此產(chǎn)品標識符有apc標識符表示,其父為enterprise 標識符,以此類推。類別和自類別的類型通常跟在MIB頭的后面,并且把有用的鍵值分割為子組。通過分段,各種值分別被列出,這樣可用的值更容易瀏覽。
The real meat of the MIB is in the description of object types. Here’s an example of a integer key:
MIB的真正好處在于對象類型的描述。以下是一個整形鍵值的例子:
upsBasicOutputStatus OBJECT-TYPE
SYNTAX INTEGER {
? ?unknown(1),
? ?onLine(2),
? ?onBattery(3),
? ?onSmartBoost(4),
? ?timedSleeping(5),
? ?softwareBypass(6),
? ?off(7),
? ?rebooting(8),
? ?switchedBypass(9),
? ?hardwareFailureBypass(10),
? ?sleepingUntilPowerReturn(11),
? ?onSmartTrim(12)
}
ACCESS read-only
STATUS mandatory
DESCRIPTION
? ?"The current state of the UPS. If the UPS is unable
? ? to determine the state of the UPS this variable is set
? ? to unknown(1)."
::= { upsBasicOutput 1 }
復(fù)制代碼
Here is defined the upsBasicOutputStatus key with a return type of INTEGER. The returned integer maps to one of 12 different return values as listed. Notice that in the MIB a description of the key is provided. These descriptions can be extremely useful in determining which objects can best provide the data you want, especially if you don’t have MIB documentation supplied by the vendor.
在此定義了一個具有整型返回值的upsBasicOutputStatus鍵值。返回的整型對應(yīng)到列出的12個不同的數(shù)值中的一個。注意在MIB中,提供了該鍵值的描述。在確定那個對象能夠提供最好地你需要的數(shù)據(jù)時,特別有幫助,特別是當廠商沒有提供MIB文檔的情況下。
Notice also that the last line of the object type description includes the numeric value 1 with upsBasicOutput as the parent. If we follow this parenting backwards in the MIB we’d find that upsBasicOutput has the value 1 and is parented by upsOutput which has the value 4 and is parented by ups which has a value of 1, which is parented by hardware which has a value of 1, which is parented by products with a value of 1 which is parented by apc with a value of 318, which is parented by enterprises with a value of 1. So, if we put all that mapping together we get a relative address for the key upsBasicOutputStatus of .1.318.1.1.1.4.1.1.0. Remember that the trailing .0 represents the first instance of the key. Applications called MIB Browsers can easily parse a MIB and make navigation much quicker than flipping through the file in vim, but don’t be fooled into thinking it’s difficult without such a tool.
注意對象類型描述的最后一行包括有數(shù)值1,其父為數(shù)字為1的upsBasicOutput。如果我們按照這個父節(jié)點返推,我們會發(fā)現(xiàn)upsBasicOutput的值為1,并且其父節(jié)點是值為4的upsOutput, upsOutput的父節(jié)點是值為1的ups,upsOutput的父節(jié)點是值為1的hardware, hardware的父節(jié)點是值為1的products,products的父節(jié)點是值為318的apc,apc的父節(jié)點的是值為1的enterprise。因此,如果我們我們把所有的對應(yīng)關(guān)系合起來,我們就得到 .1.319.1.1.1.4.1.1.0的upsBasicOutputStatus鍵值的相對地址。記住末尾的.0表示該鍵值的第一個實例。MIB瀏覽器這樣的應(yīng)用程序可以簡化MIB解析,它能夠比通過vim瀏覽文件的方式更加快捷地瀏覽,不過不要以為沒有這樣的工具就非常困難了。
So, whats really important to notice here is that the MIB is really just providing us with a road map of the OIDs available on the agent we wish to get values from. A MIB describes both where to find a value and what it returns. We can still interface with a device without the MIB, it’s just much easier when you get a return of ”Up” instead of ”1”. By leveraging the options of the Net- SNMP CLI tools you can decide just how you wish to return output which will be different if your just using the tool from the command line (where ”Up” is preferable) or if your calling the tool from a script (where ”1” is preferable).
因此,在這里真正需要注意的是,MIB其實只是提供給我們一張我們想從某個SNMP代理中獲得的可用OID的 各種值的地圖。一個MIB描述了在哪里找某個值、以及返回結(jié)果是什么。我們可以不用MIB與設(shè)備進行交互,只不過在理獲得'Up'的返回值,要比‘1’的 返回值要簡單的多。通過利用Net-SNMP命令行工具,你可以決定你希望返回結(jié)果的輸出樣式(這種方式下使用“Up"這樣的格式更好),或者你用腳本調(diào) 用工具時(這種方式下使用”1“的格式就更好)。
2.3. OID數(shù)據(jù)類型
SMI定義的OID返回值的數(shù)據(jù)類型。
SMI defines a fixed number of datatypes which are returned by OIDs. These datatypes include:
SMI定義了一定數(shù)量的OID返回的數(shù)據(jù)類型。這些數(shù)據(jù)類型包括:
Integer 整型
Signed 32bit Integer (values between -2147483648 and 2147483647). 有符號32位整數(shù)(值范圍: -2147483648 - +2147483648)
Integer32
Same as Integer. 與Integer相同。
UInteger32
Unsigned 32bit Integer (values between 0 and 4294967295). 無符號32位整數(shù)(值范圍:0-4294967295).
Octet String
Arbitrary binary or textual data, typically limited to 255 characters in length. 任意二進制或文本數(shù)據(jù),通常長度限制在255個字符內(nèi)。
Object Identifier
An OID. 一個OID。
Bit String
Represents an enumeration of named bits. This is an unsigned datatype. 表示取名的位的枚舉。這是一個無符號的數(shù)據(jù)類型。
IpAddress
An IP address. 一個IP地址。
Counter32
Represents a non-negative integer which monotonically increases until it reaches a maximum value of 32bits-1 (4294967295 dec), when it wraps around and starts increasing again from zero. 表示一個非負的整數(shù)(可遞增到32位最大值-1),然后恢復(fù)并從0開始遞增。
Counter64
Same as Counter32 but has a maximum value of 64bits-1. 與Counter32相同,最大值為64位的最大值-1。
Gauge32
Represents an unsigned integer, which may increase or decrease, but shall never exceed a maximum value. 表示無符號整數(shù),可增加或減少,但是不超過最大值。
TimeTicks
Represents an unsigned integer which represents the time, modulo 2?32 (4294967296 dec), in hundredths of a second between two epochs. 表示代表數(shù)據(jù)的一個無符號整數(shù),2^32取模(4294967296),兩個值之間為百分之一秒。
Opaque
Provided solely for backward-compatibility, its no longer used. 提供向下兼容,不再使用的數(shù)據(jù)類型
NsapAddress
Represents an OSI address as a variable-length OCTET STRING. 表示一個用變長八進制字符窗表示的OSI地址。
Net-SNMP tools will report the datatype when returning an OID unless you otherwise disregard it. As an example of that you’ll see:
Net-SNMP工具在返回一個OID時會包括其數(shù)據(jù)類型,除非你不想要他。以下是一個例子:
SNMPv2-MIB::sysContact.0 = STRING: Ben Rockwood
IF-MIB::ifPhysAddress.1 = STRING: 0:c0:b7:63:ca:4c
SNMPv2-MIB::sysUpTime.0 = Timeticks: (47372422) 5 days, 11:35:24.22
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.318.1.3.7
RFC1213-MIB::atPhysAddress.1.1.10.10.1.1 = Hex-STRING: 00 50 73 28 47 A0
RFC1213-MIB::atNetAddress.1.1.10.10.1.1 = Network Address: 0A:0A:01:01
IF-MIB::ifSpeed.1 = Gauge32: 10000000
SNMPv2-MIB::snmpInPkts.0 = Counter32: 316
SNMPv2-MIB::snmpOutPkts.0 = Counter32: 314
This is a fairly typical spread of datatypes returned by Net-SNMP tools. Notice that some values are being automatically interpreted by Net-SNMP, such as the sysUpTime and ifAdminStatus. The MIB was used when these values were returned and Net-SNMP was nice enough to find the return value in the MIB and give us the textual representation of the value.
這是一個相當?shù)湫偷挠蒒et-SNMP工具返回的數(shù)據(jù)類型表單。注意有些值已經(jīng)由Net-SNMP自動解釋了,比如sysUpTime和ifAdminStatus。這些值返回時使用到MIB,Net-SNMP會在MIBzhong找到返回值,并且為我們提供該值的文本表示。
2.4. MIB II
MIB II
IETF RFC 1213 ”defines the second version of the Management Information Base (MIB-II) for use with network management protocols in TCP/IP-based internets.” All SNMP agent and tool distributions should include MIBs that will comply with MIB-II and all devices should at the very least return values that comply with the MIB-II standard.
Within the MIB-II standard several OID groups are defined, including:
The System Group
Basic system identification and information OIDs such as sysDescr, sysContact, sysName, SysLocation, etc. (Reported by Net-SNMP in SNMPv2-MIB)
The Interfaces Group
Network Interface information such as ifDescr, ifType,ifSpeed, ifAdminStatus, etc. (Reported by Net-SNMP in IF-MIB)
The Address Translation Group
Address Translation (AT) information mapping Physical to Logical addressing such as atNetAddress, atPhysAddress,etc. (Reported by Net-SNMP in RFC1213-MIB)
The IP Group
IP stats and settings such as ipInReceives, ipForwarding, ip-InAddrErrors, etc. (Reported by Net-SNMP in IP-MIB)
The ICMP Group
ICMP stats and settings such as icmpInMsgs, icmpIn-Errors, icmpInRedirects, etc. (Reported by Net-SNMP in IP-MIB)
The TCP Group
TCP stats and settings such as tcpActiveOpens, tcpPassiveOpens,tcpInErrs, etc. (Reported by Net-SNMP in TCP-MIB)
The UDP Group
UDP stats and settings such as udpInDatagrams, udpIn-Errors, etc. (Reported by Net-SNMP in UDP-MIB)
The EGP Group
EGP stats and settings (if the device support EGP) such as egpNeighAs, egpNeighMode, etc (Reported by Net-SNMP in RFC1213-MIB)
The Transmission Group
Device specific media transmition stats and settings(Reported by Net-SNMP in RFC1213-MIB or your vendor MIB)
The SNMP Group
SNMP stats and settings such as snmpInPkts, snmp-InASNParseErrs, snmpInTraps, etc. (Reported by Net-SNMP in SNMPv2-MIB)
If you do a default walk of an SNMP device the MIB-II data should be returned. All data with the exception of the EGP and Transmission groups are requirements of the standard. For most networking devices such as routers this information is usually sufficient to provide most of the information you could want.
2.5. 為Net-SNMP添加MIB
如何為Net-SNMP添加MIB信息
Additional MIBs can be added to your Net-SNMP installation by simply copying them into the $(PREFIX)/share/snmp/mibs directory. MIBs should be (re)named to follow the convention (MIB NAME).txt for clarity. You can find the MIBs proper name on the first uncommented line of the MIB (eg: Name- MIB DEFINITIONS ::= BEGIN).
For example, if you downloaded MIB for the JetDirect Management Card found on HP LaserJet printers it might have been named something like ”hpjetdirect. mib”. The header of the MIB looks like the following:
-- (C) COPYRIGHT HEWLETT-PACKARD COMPANY 1997.
-- LaserJet 5Si Printer Model Specific MIB.
--
LaserJet5Si-MIB DEFINITIONS ::= BEGIN
This MIB should be renamed to ”LaserJet5Si-MIB.txt” and copied into the Net-SNMP mibs/ directory.
By following this convention it assures greater clarity when utilizing the various MIBs and a consistency with all other installed MIBs.
MIBs can be specified by a command line tool using the -m argument or the MIBS environmental variable for libsnmp applications including the PERL module. MIBs can be referenced locally by supplying a proper path (ie: - m ”./MY MIB.txt”) or globally by supplying the MIB name without the .txt suffix (ie: -m ”MY MIB”) if it’s located in the Net-SNMP MIBs directory.
轉(zhuǎn)載于:https://my.oschina.net/yjwxh/blog/476454
總結(jié)
以上是生活随笔為你收集整理的SNMP、MIB、OID概念的理解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动负载均衡技术(MBL)
- 下一篇: 实现mysql按月统计的教程