SNMP MIB 介紹對MIB檔中一些常見的巨集定義的描述1.DEFINITIONS ::= BEGINSNMP始終使用ASN.1概念中的描述塊(module)來組織ASN.1對象的,ASN.1的描述塊是一些相關描述語句的集合,module的結構如下<<module>> DEFINITIONS ::= BEGIN<<linkage>><<declarations>>END2.<<basetype>> ::= TEXTUAL-CONVENTION定義了對標準資料類型的進行擴展的語法很多MIB定義中都會先定義一些基於標準類型的擴展類型,如:CiFlowDirection ::= TEXTUAL-CONVENTIONSTATUS currentDESCRIPTION"The direction of data flow thru a circuit.transmit(1) - Only transmitted datareceive(2) - Only received databoth(3) - Both transmitted and received data."SYNTAX INTEGER {transmit(1),receive(2),both(3)}CiFlowDirection 是基於INTEGER的枚舉類型3.<<mibname>> MODULE-IDENTITY該定義添加了一個公共的標示段來對整個資訊描述塊進行頂層的文字描述,以加強對管理MIB描述塊的文檔管理和控制,每個MIB定義中都會有該定義。
如:circuitIfMIB MODULE-IDENTITY4.OBJECT-IDENTIFIFIER聲明一個節點如:atmClpTaggingNoScr OBJECT-IDENTITY5.OBJECT-TYPE如:ciCircuitTable OBJECT-TYPESYNTAX SEQUENCE OF CiCircuitEntryMAX-ACCESS not-accessibleSTATUS currentDESCRIPTION"The Circuit Interface Circuit Table."::= { ciObjects 1 }包括了SNMP定義該管理物件的全部資訊,相當於一個範本。
表,實體,葉子都是該類型。
SNMPv2中對SNMP的相容性做了規定,主要是通過引入三個宏:OBJECT-GROUP,MODULE-COMPLIANCE,AGENT-CAPABILITIES.6.OBJECT-GROUP –v2定義相關管理物件集合以及他們彼此關聯的一致性程度。
OBJECT-GROUP聲明的MIB物件是實現該組所必須包括的MIB物件的最小集合。
也就是說,要實現這個組,必須包括這些物件。
7.MODULE-COMPLIANCE–v2通過定義模組內所包含的組來保證模組的相容性。
規定了要實現該模組必須包含的組的最小集合。
其中MANDATORY-GROUPS規定了此模組必須實現的組的名稱。
GROUP子句說明條件必須活條件可選的組。
8.AGENT-CAPABILITIES–v2管理代理實現了模組中的哪些組以及這些組中的MIB物件在實現時和原定義的差別在管理資訊結構中由此巨集定義表示。
此巨集定義在實際應用中很少見。
9.OBJECT-IDENTITY物件標示巨集,此巨集定義用於說明物件標示符(OBJECT-IDENTIFIER),給物件標示符的說明加上附加資訊,包括狀態,文字說明等,可用於對一個表中幾個參數的不同組合的意義的說明。
10.NOTIFICATION-TYPE說明了SNMPv2的trap格式。
定義了通知類型報文中傳輸的資料。
3.1 MIB物件定義格式/thread-1137550-1-1.htmlASN.1是一種用於描述結構化客體的結構和內容的語言,基於編碼規則BER(Basic Encoding Rules)是ASN.1標準定義的一種傳送文法。
每個MIB變數格式是SMI規定的,用ASN.1描述如下:OBJECTNAME BOJECT-TYPEDESCRIPTION:(description)SYNTAX: (syntax)ACCESS: (access)STATUS: (status)::={(Parent)number}OBJECTNAME是被管對象的名字,ASN.1要求所有物件的名字在MIB中必須是唯一的;BOJECT-TYPE 是每一個節點物件所必需的關鍵字;SYNTAX是被管物件類型的關鍵字,隨後跟著的是一個類型(syntax);ACCESS是被管物件的訪問方式關鍵字,在SNMP 第二版中為MAX-ACCESS 關鍵字,(access)是被管物件的訪問方式,可為如下列舉值之一: read-only、read-write、no-accessible, SNMP 第2 版中又增加了read-create;STATUS是被管物件關鍵字,(status)是被管物件的狀態,如必備的、可選的或廢棄的;DESCRIPTION是對被管物件的功能、特徵等進行描述的關鍵字,(description)是被管物件的文本描述,在::={(Parent)number }中,Parent表示位於MIB樹中的父節點,number 表示是第幾個子節點。
-- Some holders from another obsolete mibGeoSuFilterId ::= TEXTUAL-CONVENTIONSTATUS currentDESCRIPTION"Uniquely identifies a GEO su filter"SYNTAX Integer32GeoQuickFilterId ::= TEXTUAL-CONVENTIONSTATUS currentDESCRIPTION"Uniquely identifies a GEO quick filter"SYNTAX Integer323.2 MIB 樹每個MIB物件都用物件識別碼(OID)來唯一的標識,這是用定義在ASN.1語法中的樹型結構來組織的可用資訊,其中每個可用資訊是一個帶標號的節點,每個節點用數位和字元兩種方式顯示,其中物件識別碼OID是由句點隔開的一組整數,也就是從根節點通向它的路徑,它命名節點並指示它在ASN.1樹中的準確位置。
一個帶標號節點可以擁有包含其它帶標號節點為它的子樹,如果沒有子樹它就是葉子節點,它包含一個值並被稱為物件。
圖3是帶有ASN.1編號的MIB樹實例:可以看出MIB-Ⅱ的OID是:1.3.6.1.2.1或者.dod.internet.mgmt.mib2。
在SNMP中,實現應用到的MIB物件都是MIB-Ⅱ的子樹節點。
On the server, the file is /home/geo/spIserver/etc/inet.defs(2) On 12u probes, the file is /inet/spIprobe/basic/arm-xinu/mibs/mib, or/inet/spIprobe/basic/xscale-xinu/mibs/mib. There is also a version for mips-xinu.On 14u probes, the file is /inet/spIprobe/basic/atca-x86-linux/mibs/mib.Step two:How to add a new alarma. modify mib file, for ip application the file is "spidev/spiV4.5/mibs/ipAlarms.my"the definition is the same with phyDeviceStateAlarm.ipInterfaceShteamAlarm NOTIFICATION-TYPE OBJECTS { phyDeviceStateTime, phyDeviceState, ipInterfaceIdForPd } STATUS current DESCRIPTION " Test Alarms " ::= {ipAlarmsMib 5}note. In fact, 5 is the alarmID. It must keep unique in spidev-spiV4.5-mibs-ipAlarms.my. If the last alarmID is 9 then we define the alarmID of ipInterfaceShteamAlarm as 10b. compile mibsc. copy inet.defs to probe /inet/spIprobe/basic/atca-x86-linux/mibs, change name to mib.d. copy inet.defs,inet.alarms.defs and inet.events.defs to server/station :/home/geo/spIserver/site or (etc) for teste. update spidev/spiV4.5/spi/etc/server/defaultSpiProbeAlarmDefn.txtA 2 209 3813 1 0x0006 0x0006 0 "Shteam Test Alarms Device Available"""\\\\\\\\\\\\\\\\\\\\\\\\\\\\\3814 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\"ipInterfaceShteamAlarm 1"A 2 209 3814 1 0x0006 0x0002 0 "Shteam Test Alarms Equipment Down" ""\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"ipInterfaceShteamAlarm 2"defaultBullsEye.txtALARM 10 3813 # Shteam Test Alarms Device AvailableALARM 25 3814 # Shteam Test Alarms Equipment Downf. copy defaultSpiProbeAlarmDefn.txt and defaultBullsEye.txt to server:/home/geo/spIserver/site or (etc) for testg. update spIprobeApps/v4.5/basic/mibs/event, add a lineipInterfaceShteamAlarm initialContextId.198.4.15.2.24copy to probe:/inet/spIprobe/support/site, /inet/spIprobe/basic/atca-x86-linux/mibsh. update spidev/spiV4.5/spi/src/alarms/probe/, h.AlarmWork.h - add one new linestatic const char* const ipInterfaceShteamChanged = "ipInterfaceShteamAlarm"; - we just re-use PhyDeviceStateAlarm functionpProc->name = ipInterfaceShteamChanged; pProc->proc =&AlarmWork::PhyDeviceStateAlarm; pProc->logProc =&AlarmWork::PhyDeviceStateAlarmLogProc; pProc->parm = 0; pProc ; compile it and copy alarmSpiProbe binary execute file to server:/home/geo/spIserver/bin [Q&A]Why sometimes alarmSpiProbe restarts when it receive the alarm of Shteam Test Alarm?Answer: The version of libnwGprsDbExt.so is not compitable to alarmSpiProbe. We have to rebuild spi/api/src/db/nwGprs,then copy libnwGprsDbExt.so to server:/home/geo/spIserver/libi. update spIprobeApps/v4.5/basic/src/ipMon/ipStateMonitor/srcIPStateMonSnmp.h--compare to phyDeviceStateAlarm, only trap name is different,so update phyDeviceStateAlarm to ipInterfaceShteamAlarm.const char* const ipTrapNames\[\] = { "ipInterfaceShteamAlarm", "ipInterfaceStateAlarm" } ; compile it and repleace binary ipStateMonitor in the probe.j. server restartsu - geospiStop(make sure no db process running, "ps -eaf | grep db")spiStartk. re-configure alarmsl. probe restartsu - rootservice spIprobe restart allm. probe side: command: aui ipStateMon1, send i 3, then check the alarm in the GUI IP-ALARMS-MIB DEFINITIONS ::= BEGIN-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --- Copyright (c) 1994-2003 Inet Technologies, Inc.-- All Rights Reserved.-- This product and related documentation is-- protected by copyright and distributed under licenses restricting-- its use, copying, distribution and decompilation.-- No part of this product or related documentation may be reproduced-- in any form by any means without prior written authorization-- of Inet Technologies, Inc. and its licensors, if any.-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EXPORTS;IMPORTSGmtTime,gmtTimeFROM INET-INC-MIBgprsAlarms,gprsPhyDeviceId,gprsIPInterfaceIdFROM GPRS-SURVEILLANCE-MIBphyDeviceStateTime,ipInterfaceState,ipInterfaceStateTime,phyDeviceState,ipInterfaceId,ipInterfaceIdForPdFROM IP-STATUS-MIB ipProbeBandwidthTime,ipProbeMonId,ipProbeBandwidthStateFROM IP-PROBE-STATUS-MIB ipInterfaceAlarmMessageFROM IP-INTERFACE-STATUS-MIB applInfoAlarmType,applInfoAlarmMessage, applInfoAlarmDescriptionFROM APPL-INFO-ALARM-MIBMODULE-IDENTITYFROM SNMPv2-SMITEXTUAL-CONVENTION, DisplayString, gmtTime FROM SNMPv2-TC;ipAlarmsMib MODULE-IDENTITYLAST-UPDATED "0306060000Z" ORGANIZATION "Inet Inc."CONTACT-INFO"Pierce E. BrockmanPostal: Inet Inc.1255 W. 15th St.Suite 600Plano, Tx 75075Tel: 1 214 578 6100Fax: 1 214 578 6113E-mail: peb@"DESCRIPTION"This module defines alarms provided by theGeoProbe in the IP Surveillance Package"::= { gprsAlarms 3 }-------------------------------------------------------------------------- -- The following inform-requests are sent by the agent-- for the IP Surveillance PackagephyDeviceStateAlarm NOTIFICATION-TYPEOBJECTS{phyDeviceStateTime,phyDeviceState,ipInterfaceIdForPdSTATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent whenever the physical device state changes value"::= {ipAlarmsMib 1}ipInterfaceStateAlarm NOTIFICATION-TYPE OBJECTS{ipInterfaceStateTime,ipInterfaceState,ipInterfaceId}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent whenever the physical device state changes value"::= {ipAlarmsMib 2}ipProbeBandwidthAlarm NOTIFICATION-TYPE OBJECTSipProbeMonId,ipProbeBandwidthState,ipProbeBandwidthTime}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent whenever the bandwidth monitoring state changes value "::= {ipAlarmsMib 3} ipInterfaceAddChannelAlarm NOTIFICATION-TYPE OBJECTS{ipInterfaceStateTime,ipInterfaceState,ipInterfaceId,ipInterfaceAlarmMessage}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent when there are AddChannel failures for an IP interface::= {ipAlarmsMib 4}ipApplIdMapConflictAlarm NOTIFICATION-TYPE OBJECTS{gmtTime,applInfoAlarmType,applInfoAlarmMessage,applInfoAlarmDescription}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent when there are informative alarms for a probe"::= {ipAlarmsMib 5} etherealToDiskNoDataAlarm NOTIFICATION-TYPE OBJECTS{gmtTime,applInfoAlarmType,applInfoAlarmMessage,applInfoAlarmDescriptionSTATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent when there are informative alarms for ethereal to disk application "::= {ipAlarmsMib 6}etherealToDiskResumeDataAlarm NOTIFICATION-TYPE OBJECTS{gmtTime,applInfoAlarmType,applInfoAlarmMessage,applInfoAlarmDescription}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent when there are informative alarms for ethereal to disk application "::= {ipAlarmsMib 7} etherealToDiskSessionRebootAlarm NOTIFICATION-TYPEOBJECTS{gmtTime,applInfoAlarmType,applInfoAlarmMessage,applInfoAlarmDescription}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agent when there are informative alarms for ethereal to disk application "::= {ipAlarmsMib 8}etherealToDiskSessionFailureAlarm NOTIFICATION-TYPE OBJECTS{gmtTime,applInfoAlarmType,applInfoAlarmMessage,applInfoAlarmDescription}STATUS currentDESCRIPTION"This Notification is sent as a inform-request from the agentwhen there are informative alarms for ethereal to disk application"::= {ipAlarmsMib 9}ENDAnother example of imports during compilation comes from the BLADETYPE2-TRAP MIB used by the HP ProLiant BL p-Class GbE2 Interconnect Switch:BLADETYPE2-TRAP-MIB DEFINITIONS ::= BEGINIMPORTSTRAP-TYPEFROM RFC-1215sysNameFROM RFC1213-MIBhpSwitchBladeType2-MgmtFROM HP-SWITCH-PL-MIBagSlotNumberFROM BLADETYPE2-SWITCH-MIBipCurCfgGwIndexFROM BLADETYPE2-NETWORK-MIBIn this example,TRAP-TYPE and sysName are readily resolved as in the example above. hpSwitchBladeType2-Mgmt is resolved by mcompile checking HP-SWITCH-PL.MIB. agSlotNumber is resolved from BLADETYPE2-SWITCH.MIBand ipCurCfgGwIndex is resolved from BLADETYPE2-NETWORK.MIB.To illustrate further how imports are resolved—the following procedure shows how mcompile would attempt to resolve the import for hpSwitchBladeType2-Mgmt:1. Look for a file named HP-SWITCH-PL-MIB.mib (module name, uppercase).2. Look for a file named HP-SWITCH-PL.mib (module name without -MIB, uppercase).3. Look for hp-switch-pl.mib (convert name to lowercase for case sensitivity in Linux/HP-UX).4. Look for hp-switch-pl-mib.mib (convert name to lowercase for case sensitivity inLinux/HP-UX).5. Report an error indicating that the imported MIB could not be found.A major consideration when importing MIBs is locating variables from other third-party MIBs. In many cases, MIBs are named to match module names. However, in some circumstances it might be necessary to rename MIB files to match the module names prior to compilation. For example, some vendors might provide MIB files with different extensions such as .my. In this case, before using mcompile, the mibfile.my file needs to be renamed to mibfile.mib.。