Está en la página 1de 18

Chng

C s thng tin qun l (MIB)


Cu trc ca MIB version 1 (SMIv1) Cu trc ca MIB version 2 (SMIv2) MIB-2 (RFC1213), mib chun dnh cho cc thit b TCP/IP. Host-resources-mib (RFC2790), mib chun dnh cho host. Thc hin cc phng thc SNMP bng mt chng trnh MIB Browser trn Windows Thc hin cc phng thc SNMP bng netsnmp-utils trn Linux

SNMP ton tp

Chng 3 : Management Information Base

Chng 2 trnh by cch s dng mt s phn mm gim st SNMP ph bin nh PRTG hay Solarwinds. y l cc cng c gim st t ng, chng nh k thc hin qut ly cc thng tin mt lt v hin th ln dng biu thng k theo thi gian. Mi ln qut chng thc hin mt lot cc phng thc SNMP GetRequest/GetNextRequest. Trong chng ny chng ta s kho st cu trc ca mib, mt s mib ph bin v cch dng cc tin ch thc thi cc phng thc SNMP ly cc thng tin m ta mun. Tm hiu chng ny s gip bn : + Hiu c cu trc ca mib v c t cc mib ph bin nh mib-2 hay host-resources-mib. + Hiu c cch cc phn mm gim st SNMP ly thng tin nh th no. + S dng c cc cng c SNMP Browser trn Windows & Linux. + C nn tng h tr cho vic lp trnh phn mm SNMP.

1. SMIv1
MIB l mt cu trc d liu nh ngha cc i tng c qun l, c thit k qun l cc thit b khng ch ring TCP/IP. RFC1155 1 m t cu trc ca mib file, cu trc ny gi l SMI (Structure of Management Information). Sau ny ngi ta m rng thm cu trc ca mib thnh SMI version 2, v phin bn trong RFC1155 c gi l SMIv1. Trc khi i vo tm hiu cu trc ca mib, chng ta phi i s lc qua mt chun gi l ASN.1 : + ASN.1 (Abstract Syntax Notation One) l chun m t cc lut m ha d liu (encoding rules) cho cc h thng truyn thng s. Mt trong 3 h thng lut m ha trong ASN.1 l BER (Basic Encoding Rules). BER c SNMP dng lm phng php m ha d liu. V vy trong cc RFC lin quan n SNMP ta hay bt gp dng ghi ch use of the basic encoding rules of ASN.1. + BER m t nhiu kiu d liu nh : BOOLEAN, INTEGER, ENUMERATED, OCTET STRING, CHOICE, OBJECT IDENTIFIER, NULL, SEQUENCE, . + Chng ta s dnh hn mt chng ni v cc lut m ha ca BER of ASN.1 v cch c bn tin SNMP t vic phn tch cc byte da vo lut BER. Quay li RFC1155, mi i tng bao gm 3 phn : Name, Syntax v Encoding. Name Name l nh danh ca object, c kiu OBJECT IDENTIFIER. OBJECT IDENTIFIER l mt chui th t cc s nguyn biu din cc nt (node) ca mt cy t gc n ngn. Gc (root node) trong mib khng khng c tn. Di root l 3 node con : + ccitt(0) : do CCITT qun l (Consultative Committee for International Telephone and Telegraph). + iso(1) : do t chc ISO qun l (International Organization for Standardization). + joint-iso-ccitt(2) : do c ISO v CCITT qun l. Di node iso(1), t chc ISO thit k 1 node dnh cho cc t chc khc l org(3). Di org(3) c nhiu node con, mt node c dnh ring cho US Department of Defense, dod(6). B Quc phng M c coi l ni sng lp ra mng Internet, di dod(6) ch c 1 node dnh cho cng ng internet ngy nay, l node internet(1). Tt c mi th thuc v cng ng Internet u nm di .iso.org.dod.internet, mi object ca cc thit b TCP/IP u bt u vi prefix .1.3.6.1 (du chm u tin biu din rng .iso l cy con ca root, v root th khng c tn) RFC1155 nh ngha cc cy con nh sau :
internet directory mgmt experimental private enterprises OBJECT OBJECT OBJECT OBJECT OBJECT OBJECT IDENTIFIER IDENTIFIER IDENTIFIER IDENTIFIER IDENTIFIER IDENTIFIER ::= ::= ::= ::= ::= ::= { { { { { { iso org(3) dod(6) 1 } internet 1 } internet 2 } internet 3 } internet 4 } private 1 }

+ directory : dnh ring cho tng lai nu dch v OSI Directory c s dng trn internet.
1

RFC1155 Structure and Identification of Management Information for TCP/IP-based Internets

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

+ mgmt (management) : tt c cc mib chun chnh thc ca internet u nm di mgmt. Mi khi mt RFC mi v mib ra i th t chc IANA (Internet Assigned Numbers Authority) s cp cho mib mt object-identifier nm di mgmt. + experimental : dng cho cc object ang trong qu trnh th nghim, c IANA cp pht. + private : dng cho cc object do ngi dng t nh ngha, tuy nhin cc ch s cng do IANA cp. Tt c cc n v cung cp h thng mng c th ng k object-identifier cho sn phm ca h, chng c cp pht di node private.enterprises.

ccitt (0)

iso (1)

iso-ccitt (2)

org (3)

dod (6)

internet (1)

directory (1) 1.3.6.1.1

mgmt (2) 1.3.6.1.2

experimental (3) 1.3.6.1.3

private (4) 1.3.6.1.4

enterprises (1) 1.3.6.1.4.1 Hnh : SMIv1 (RFC1155)

Syntax Syntax m t kiu ca object l g. Syntax c ly t chun ASN.1 nhng khng phi tt c cc kiu u c h tr. SMIv1 ch h tr 5 kiu nguyn thy (primitive types) ly t ASN.1 v 6 kiu nh ngha thm (defined types). Primitive types : INTEGER, OCTET-STRING, OBJECT-IDENTIFIER, NULL, SEQUENCE. Defined types : + NetworkAddress : kiu a ch internet (ip). + IpAddress : kiu a ch internet 32-bit (ipv4), gm 4 octet lin tc. + Counter : kiu s nguyn khng m 32-bit v tng u, khi s ny tng n gii hn th phi quay li t 0. Gi tr ti a l 232-1 (4294967295). + Gauge : kiu s nguyn khng m 32-bit, c th tng hoc gim nhng khng tng qu gi tr ti a 232-1. + TimeTicks : kiu s nguyn khng m, ch khong thi gian tri qua k t mt thi im no , tnh bng phn trm giy. VD t khi h thng khi ng n hin ti l 1000 giy th gi tr sysUpTime=100000. + Opaque : kiu ny cho php truyn mt gi tr c kiu ty nhng c ng li thnh tng OCTET-STRING theo quy cch ca ASN.1. Encoding C ch Encoding nh ni, l chun BER trong ASN.1 s c trnh by trong chng 5. Cu trc kiu OBJECT-TYPE RFC1155 quy nh cu trc ca mt record nh ngha i tng qun l (a managed object definition), kiu d liu ny gi l OBJECT-TYPE, cc ti liu mib khc khi vit nh ngha cho mt managed object no th phi theo quy nh ca SMI. Mt Managed Object Definition c kiu OBJECT-TYPE bao gm cc trng : 3

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

+ SYNTAX : kiu ca object, l mt trong cc primitive types hoc defined types trn. + ACCESS : mc truy nhp ca object, mang mt trong cc gi tr read-only, read-write, write-only, notaccessible. + STATUS : mang mt trong cc gi tr mandatory (bt buc phi h tr), optional (c th h tr hoc khng), obsolete ( b thay th). Mt agent nu h tr mt chun mib no th bt buc phi h tr tt c cc object c status=mandatory, cn status=optional th c th h tr hoc khng. + DESCRIPTION : dng gii thch cho ngha ca object. V d nh ngha cho object sysUpTime trong RFC1213 :
sysUpTime OBJECT-TYPE SYNTAX TimeTicks ACCESS read-only STATUS mandatory DESCRIPTION "The time (in hundredths of a second) since the network management portion of the system was last re-initialized." ::= { system 3 }

2. Mib-2 (RFC1213)
RFC1155 m t cch trnh by mt mib file nh th no ch khng nh ngha cc object. RFC1213 l mt chun nh ngha nhnh mib nm di iso.org.dod.internet.mgmt.mib-2 (tt nhin phi theo cu trc m RFC1155 quy nh). Chng ta s kho st mt phn RFC1213 hiu ngha ca mt s object trc khi dng cng c c chng. RFC1156 l c t mib chun cho cc thit b TCP/IP, c coi l Internet-Standard Mib (mib version 1). RFC1213 l c t mib chun version 2, thng gi l mib-2. Ch phn bit mib-1 v mib-2 l cc chun c t nh ngha ca cc object, cn SMIv1 v SMIv2 l c t cu trc ca mib file. Mib-1 v mib-2 s dng cu trc ca SMIv1. Mib-2 l mt trong nhng mib c h tr rng ri nht. Nu mt thit b c tuyn b l c h tr SNMP th hng sn xut phi ch ra n h tr cc RFC no, v thng l RFC1213. Nhiu bn ch bit thit b ca mnh c h tr SNMP nhng khng r h tr cc RFC no, v dng phn mm gim st SNMP h tr RFC1213 gim st thit b nhng khng thu c kt qu. L do l phn mm th h tr RFC1213 nhng thit b th khng. V tr ca MIB-2 trong mib nh sau :
... internet (1)

directory (1) 1.3.6.1.1

mgmt (2) 1.3.6.1.2

experimental (3) 1.3.6.1.3

private (4) 1.3.6.1.4

mib-2 (1) 1.3.6.1.2.1

enterprises (1) 1.3.6.1.4.1

system(1)

interfaces(2)

at(3)

ip(4)

icmp(5)

tcp(6)

udp(7)

egp(8)

transmision(10)

snmp(11)

Cc kiu d liu mi c nh ngha trong mib-2 gm : + Display String : k tha t kiu OCTET STRING nhng ch bao gm cc k t in c (printable characters) v di khng qu 255 k t. + Physical Address : ging kiu OCTET STRING, c dng biu din a ch vt l ca thit b.

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

Trong mib-2 c 10 group, ti liu ny ch trnh by nh ngha cc object trong group system v interfaces do chng ta s thc hnh dng cc cng c c mib c cc object ny. c c m t y cc bn hy tham kho RFC1213. Name mib-2(1) system(1) sysDescr(1) DisplayString Dng vn bn m t node hin ang h tr mib ny, c th bao gm tn, version, kiu phn cng, h iu hnh, nh danh c ng k ca hng sn xut h thng. Gi tr ny phi kh nhm ln v miu t c y l loi thit b g Thi gian tnh t khi module qun tr mng ca h thng khi ng li (kiu TimeTicks tnh bng phn trm giy) Dng vn bn ch nh ngi cn lin lc nu c cc vn i vi h thng Tn c gn cho node qun l V tr vt l t node Ch ra node c th hot ng cc layer no ca OSI. Gi tr ca n l tng tt c cc 2(Layer-1) vi Layer l s lp OSI. VD mt router hot ng lp 3 th gi tr ny s l 2(3-1)=4 Tng s giao tip mng hin c trong h thng Danh sch cc thng tin ca tng interface Mt entry cha cc object mang thng tin ca mt interace trong danh sch Gi tr duy nht ca mi interface, gi tr ny chy t 1 n ifNumber, v khng thay i t nht cho n khi h thng khi ng li Dng text mang thng tin ca mt interface Kiu interface, da vo giao thc lp physical/link ca interface. VD : ethernetCsmacd(6), fddi(15), e1(19), atm(37), sonet(39), v35(45), Kch thc ca datagram ln nht c th truyn/nhn trn interface Bng thng hin ti ca interface, tnh bng bit per second a ch vt l ca interface Trng thi mong mun ca interface Trng thi hot ng thc t ca interface Gi tr ca sysUpTime ti thi im interface i vo trng thi hot ng nh hin ti Tng s octet nhn trn interface Syntax Description Internet-standard mib version 2 (RFC1213) OID : .1.3.6.1.2.1

sysObjectID(2)

Object identifier

sysUpTime(3) sysContact(4) sysName(5) sysLocation(6) sysServices(7) interfaces(2) ifNumber(1) ifTable(2) ifEntry(1) ifIndex(1) ifDescr(2) ifType(3)

TimeTicks DisplayString DisplayString DisplayString Integer

Integer Sequence ifEntry Integer DisplayString Integer

ifMtu(4) ifSpeed(5) ifPhysAddress(6) ifAdminStatus(7) ifOperStatus(8) ifLastChange(9) ifInOctets(10)

Integer Gauge PhysicalAddress Integer Integer TimeTicks Counter

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

ifInUcastPkts(11) ifInNUcastPkts(12) ifInDiscards(13) ifInErrors(14) ifInUnknownProtos(15) ifOutOctets(16) ifOutUcastPkts(17)

Counter Counter Counter Counter Counter Counter Counter

S gi unicast c a n giao thc lp cao hn S gi nonunicast c a n giao thc lp cao hn (broadcast, multicast) S gi tin nhn c b hy (k c cc gi khng b li) ngn khng cho chng n tng x l cao hn, vd khi trn b m nhn. S gi tin nhn c c cha li S gi tin nhn c t interface nhng b discard v n thuc giao thc khng c h tr Tng s octet truyn ra interface Tng s gi tin unicast m tng giao thc cao hn yu cu truyn ra (k c cc gi s b discard) Tng s gi tin non-unicast m tng giao thc cao hn yu cu truyn ra (k c cc gi s b discard) S gi tin cn truyn ra b hy (k c cc gi khng b li) ngn khng cho chng n tng x l cao hn, vd khi trn b m pht S gi tin khng th truyn ra do c li di ca hng i bn tin truyn i Tham chiu n nh ngha mib dnh ring cho loi media ca interface. VD nu interface thuc ethernet th gi tr ny ch ra ti liu m t cc object ca ring ethernet. Nu node khng cung cp c thng tin ny th gi tr ca ifSpecific phi l .0.0

ifOutNUcastPkts(18)

Counter

ifOutDiscards(19) ifOutErrors(20) ifOutQLen(21)

Counter Counter Gauge

ifSpecific(22)

Object identifier

Cu trc ca mib l dng cy, xc nh object identifier ca mt object bn phi i t gc n object . V d : bandwidth ca interface th 3 trn thit b th c OID l .1.3.6.1.2.1.2.2.1.5 (.iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifSpeed.3). Ch : mc d mib-2 quy nh index ca tng interface phi lin tc v chy t 1 n ifNumber, nhng trong thc t nhiu thit b khng t index lin tc m t theo cch ring d qun l. Do i vi C2950 th interface th 3 c index l 3, nhng i vi thit b khc th interface th 3 c th c index khc 3, thm ch l s rt ln. Chng hn mt switch c nhiu card, mi card c 12 port th port1-card1 c index l 101, port12-card1 c index l 112, port1-card2 c index l 201.

3. S dng iReasoning MIB Browser trn Windows


iReasoning MIB Browser ly thng tin ca mt object trong mib ta cn c mt phn mm c th thc hin cc phng thc SNMP (Get, GetNext, Set). Cc phn mm ny gi chung l MIB Browser, hin c rt nhiu v hu ht u c phin bn min ph. Mt trong nhng cng c mib browser d s dng l iReasoning MIB Browser. Phn mm ny c vit trn Java nn c th chy trn Windows ln Linux, n cung cp c giao din ha v dng lnh. Phin bn hin ti l Personal Edition 6.33, download ti http://www.ireasoning.com/download.shtml Trong phn ny chng ta s dng iReasoning MIB Browser ly thng tin ca mt switch Cisco Catalyst 2950. Thng tin c ly thuc c t mib-2.

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

Sau khi ci t v khi ng, giao din ca phn mm nh sau

Ly thng tin bng Get/GetNextRequest dng MIB Browser u tin bn khai bo y tnh nng SNMP agent trn C2950 nh chng 2 trnh by. K tip trn iReasoning MIB browser bn khai bo nh sau : nhp IP ca switch vo [Address]; nhn nt [Advanced], nhp cc thng tin Read/Write Community (mc nh l public/private), chn version SNMP l 1 (cc version khc chng ta s thc hin sau), nhn [OK].

Sau , m cy RFC1213.system, chn object sysDescr; bn phi mn hnh chn Operation l GET v nhn nt , MIB Browser s gi bn tin GetRequest c OID l 1.3.6.1.2.1.1.1.0 (sysDescr.0) n thit b, thit b gi li bn tin GetResponse v phn mm hin th thng tin tr li ln mn hnh.

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

Khi bn click vo object sysDescr bn s thy cc thng tin nh ngha v object ny hin th panel pha di nh Name, OID, MIB, Syntax, Access, Status. Phn mm MIB Browser bit c cc thng tin ny chnh l nh vo RFC1213, mib file ny c lu ng dn ci t chng trnh ..\ireasoning\mibbrowser\mibs\rfc1213. Kt qu tr li cho sysDescr l Cisco Internetwork Operating System Software , kiu l OctetString. Tip theo bn chn Operation l GetNext, phng thc GetNext ly v thng tin ca object k tip. Lc ny phn mm s gi bn tin GetNextRequest c OID vn l .1.3.6.1.2.1.1.1.0 (sysDescr.0) nhng thit b s gi bn tin tr li GetResponse c OID l .1.3.6.1.2.1.1.2.0 (sysObjectID.0), v sysObjectID l object k tip sysDescr trong mib-2.

Gi tr tr v ln ny l gi tr ca sysObjectID, l .1.3.6.1.4.1.9.1.324, c kiu Object Identifier. Gi tr ny c ngha l .iso.org.dod.internet.private.enterprises.cisco.1.324, trong prefix u l enterprise number ca Cisco (9) cn 1.324 l OID ca thit b switch C2950 do Cisco t nh ngha. Bn c nh trong chng 2, phn mm PRTG khi auto-discover con switch ny pht hin ra n l [Cisco ISO Cisco Switch] hay khng ? PRTG da vo sysObjectID nhn dng ra Cisco Switch, d nhin l n phi c CSDL nhn dng y . Thay i thng tin bng SetRequest dng MIB Browser Trong panel bn tri, nhng object c hnh l read-only, hnh l read-write. Tip theo ta s thc hin phng thc Set thay i thng tin thit b qua SNMP. Bn click chn object sysName v thc hin Get ly thng tin trc khi thay i. Sau bn chn phng thc Set v nhn nt [Go]. Trong hp thoi [SNMP SET] bn nhp gi tr cn thay i vo [Value] v nhn [OK], nu write community l ng th thao tc Set s c thc hin thnh cng.

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

Thc hin li phng thc Get, bn s thy sysName ca thit b mang gi tr mi.

Login vo thit b bn s thy hostname ca switch thay i. Gim st lu lng interface bng MIB Browser By gi chng ta s thc hin cc th tc phc tp hn gim st lu lng interface trn switch, thng tin cn ly bao gm tn interface, description, speed, current status, lu lng truyn/nhn. Mc ny ch nhm gip ngi c hiu cc phn mm gim st lu lng hot ng theo trnh t nh th no, trong thc t khng ai dng MIB Browser gim st lu lng th cng c. u tin bn phi ly s lng interface c trn C2950, chn node interfaces.ifNumber, thc hin GET. C2950 ca tc gi cho bit c 27 interface, switch ca bn c th c s lng khc.

Tip theo bn ly index ca tng interface, vn click vo node ifNumber, chn GetNext, bn s ly c object k tip ca ifNumber, tc l index ca interface u tin, v ifIndex l object accessible k tip ifNumber (ifTable v ifEntry l not-accessible). Trong hnh di bn s thy interface u tin c index l 1 (.1.3.6.1.2.1.2.2.1.ifIndex.1). C th bn s hi ti sao khng s dng GetRequest trc tip trn node ifIndex.1 m phi s dng GetNextRequest trn node nm trc ? Nh pha trn lu , nhiu thit b khng dng ifIndex trong khong t 1 n ifNumber, v index ca interface u tin cha hn l 1, nn nu dng GetRequest ifIndex.1 trn nhiu thit b khc c th s gp li agent not responding.

DIP THANH NGUYN, 2010

Trang|

SNMP ton tp

Chng 3 : Management Information Base

Ln lt thc hin GetNext lin tc n khi no s lng index ca 27 interface. Cui cng bn s c index ca cc interface c nh s t 1 n 27.

Nu tip tc GetNext th bn s ly c cc dng m t ca 27 interface (ifDescr). Lc ny bn c th ly thng tin ca interface bt k v bn bit index ca chng. V d ly description ca interface th 5, bn hy nhp vo hp OID gi tr .1.3.6.1.2.1.2.2.1.2.5 v thc hin Get.

Tip theo bn phi ly bandwidth ca cc interface (ifSpeed), mt s interface c speed l 10Mbps, mt s khc l 100Mbps.

Tip theo na bn phi ly trng thi hot ng ca tng interface bit interface no ang up hay down. Theo RFC1213, ifOperStatus c kiu l INTEGER, c th mang cc gi tr : up(1), down(2), testing(3), unknown(4), dormant(5), notPresent(6), lowerLayerDown(7).

theo di lu lng, bn phi thc hin ly lin tc tng s octet nhn (ifInOctets) v tng s octet truyn (ifOutOctets), tc l thc hin phng php Poll. Tc hin ti c tnh bng ly s octet tng thm gia 2 ln poll chia cho thi gian gia 2 ln poll.

DIP THANH NGUYN, 2010

Trang|

10

SNMP ton tp

Chng 3 : Management Information Base

Hnh sau minh ha kt qu ly ifInOctets ca interface s 18.

Nh vy n y bn bit chng trnh gim st lu lng bng SNMP hot ng nh th no ly c lu lng ca cc interface. Cc operation khc ca iReasoning MIB Browser Ngoi cc opeartion tng ng cc phng thc ca SNMPv1, iReasoning MIB Browser cn c mt s opeartion khc. GetBulk : thc hin phng thc GetBulkRequest. GetBulk l phng thc c t SNMPv2, n c th ly thng tin ca nhiu object cng lc ch bng 1 bn tin; v d thay v bn gi 10 GetRequest th bn ch cn gi 1 GetBulk. Chng ta s thc hin GetBulk sau khi tm hiu v SNMPv2. GetSubTree : thc hin ly tt c cc object nm di mt node. V d bn ang node mib-2.system, khi dng GetSubTree th phn mm s ly tt c cc OID nm di mt cp. Lu GetSubTree khng phi l mt phng thc chun ca SNMP m l tnh nng ca ring phn mm, bn cht ca vic thc hin GetSubTree l thc hin cc GetNextRequest lin tc n khi no nhn c object cng cp vi object khi u.

Walk : thc hin GetNextRequest lin tc n khi ht bng mib. Ch cn mt ln Walk bn c th ly ton b cc object nhng s tn nhiu thi gian. Walk cng khng phi l phng thc chun ca SNMP.

4. SMIv2
SMIv2 (Structure of Management Information version 2) c trnh by trong RFC2578, bao gm nhiu thay i trong cu trc mib file. Phn ny trnh by nhng thay i ch yu nht. Cc kiu d liu mi hoc thay i so vi SMIv1 + INTEGER32 : s nguyn nm trong khong -231 and 231-1 (-2147483648 to 2147483647 decimal). + OCTET STRING : kiu chui k t, di ti a 65535. + OBJECT IDENTIFIER : nh danh ca object, khng qu 128 phn t (sub-identifier), mi phn t l s nguyn khng qu 232-1. + COUNTER32 : kiu s nguyn khng m tng dn, ti a l 232-1, khi vt gi tr ti a th quay li t 0. Counter32 khng bt buc gi tr bt u phi l 0. + GAUGE32 : kiu s nguyn khng m tng hoc gim, gii hn trong khong 0 ~ 232-1, n khng th vt ra gii hn ny. + COUNTER64 : kim s nguyn khng m tng dn, ti a l 264-1 (18446744073709551615).

DIP THANH NGUYN, 2010

Trang|

11

SNMP ton tp + UNSIGNED32 : kiu s nguyn t 0 ~ 232-1. Kiu d liu OBJECT-TYPE

Chng 3 : Management Information Base

Trong SMIv1 kiu OBJECT-TYPE bao gm : SYNTAX, ACCESS, STATUS, DESCRIPTION. Trong SMIv2 kiu OBJECT-TYPE bao gm cc trng : SYNTAX, UNITS, MAX-ACCESS, STATUS, DESCRIPTION, REFERENCE, INDEX, AUGMENTS, DEFVAL. + SYNTAX : kiu d liu ca object, l mt kiu theo chun ASN.1 hoc cc kiu nh ngha ring ca SMIv2. + UNITS : l dng text m t mt unit no gn lin vi object, trng ny khng bt buc phi c. + MAX_ACCESS : c 5 quyn truy xut object c u tin t thp n cao l "not-accessible", "accessiblefor-notify", "read-only", "read-write", "read-create"; MAX_ACCESS quy nh quyn cao nht tc ng n object, quyn cao hn bao gm cc quyn thp hn. VD object c MAX_ACCESS l read-write th c th c c/ghi nhng khng th to. + STATUS : trng thi ca object, mang mt trong cc gi tr current (nh ngha ca object ang c hiu lc v ang c s dng), obsolete (nh ngha ny c v c th b i), depricated (nh ngha ny c v cc chun tip theo c th nh ngha li). + DESCRIPTION : dng text m t thng tin ngha ca object. + REFERENCE : l dng text m t n cc ti liu khc c lin quan n object ny, reference khng bt buc phi c. + INDEX : ch ra trng index ca object hin ti. VD ifDescr c INDEX = ifIndex. + AUGMENTS : tng t nh INDEX v c th dng thay th INDEX, nhng ch mt trong 2 trng INDEX hoc AUGMENTS tn ti, khng th tn ti cng lc c 2. + DEFVAL : gi tr mc nh (default value) ca object khi n c to ra. Kiu d liu NOTIFICATION-TYPE Kiu NOTIFICATION-TYPE c dng m t nhng thng tin qun l mng c truyn khng theo yu cu (v d bn tin TrapPDU hoc InformRequestPDU ca SNMPv2, chng c t ng gi i khi c s kin xy ra m khng cn phi c request t thit b khc). Cc notification phi c nh ngha trong mib, cu trc ca chng bao gm cc mnh sau : + OBJECT : danh sch c th t cc object c lin quan n notification, vd bn tin notification cho 4 interface ca thit b th OBJECT phi cha ifIndex ca 4 interface . + STATUS : mang mt trong 3 gi tr current, obsolete hoc depricated. + DESCRIPTION : dng text m t ngha ca notification. + REFERENCE : m t cc ti liu c lin quan n nh ngha ca notification, REFERENCE khng bt buc phi c. V d : khi cu hnh ca thit b thay i th n s gi bn tin entConfigChange c kiu NOTIFICATIONTYPE, c nh ngha nh sau :
entConfigChange NOTIFICATION-TYPE STATUS current DESCRIPTION "An entConfigChange trap is sent when the value of entLastChangeTime changes. It can be utilized by an NMS to trigger logical/physical entity table maintenance polls. An agent must not generate more than one entConfigChange trap-event in a five second period, where a trapevent is the transmission of a single trap PDU to a list of trap destinations. If additional configuration changes occur within the five second throttling period, then these trap-events should be suppressed by the agent. An NMS should periodically check the value of entLastChangeTime to detect any missed entConfigChange trap-events, e.g. due to throttling or transmission loss." ::= { entityMIBTrapPrefix 1 }

DIP THANH NGUYN, 2010

Trang|

12

SNMP ton tp

Chng 3 : Management Information Base

5. Host-Resources-Mib (RFC2790)
RFC2790 l mib dng cho host, n cung cp nh ngha nhiu object nh thng tin h thng, lu tr, device, software, performance. Dch v SNMP agent trn Windows v Linux u h tr RFC2790. V tr ca Host-mib trong mib nh sau :
host OBJECT IDENTIFIER ::= { mib-2 25 }

Tc l .iso.org.dod.internet.mgmt.mib-2.host hay .1.3.6.1.2.1.25.


... internet (1)

directory (1) 1.3.6.1.1

mgmt (2) 1.3.6.1.2

experimental (3) 1.3.6.1.3

private (4) 1.3.6.1.4

mib-2 (1) 1.3.6.1.2.1

enterprises (1) 1.3.6.1.4.1

host (25) 1.3.6.1.2.1.25

Cc kiu d liu mi c nh ngha trong host-mib gm : + Kbytes : kiu INTEGER32, th hin kch thc ca thit b lu tr, n v tnh l 1024 Bytes. + ProductID : xc nh nh sn xut, model, phin bn ca phn cng hay phn mm. + AutonomousType : kiu gi tr nh danh c th m rng c lp, v d n c th ch ra mt cy mib con no c nh ngha bi mt ti liu khc. + DateAndTime : kiu ngy v gi, nh dng nh sau : year-mon-day,hour:min:sec.centiSec,HourFromUCT:MinFromUTC. V d 15/01/2010 1:30:15 PM, GMT+7 c biu din l 2010-01-15,13:30:15.0,+7:0 Mc ny trch nh ngha mt s object quan trng trong cng tc gim st server nh tnh trng h thng, tnh trng lu tr ( cng), t l s dng cpu & b nh ca tng process, danh sch cc phn mm ci t; do chng ta s thc hnh dng cc cng c c mib c cc object ny. c c m t y cc bn hy tham kho RFC2790. Name host-mib(25) hrSystem(1) hrSystemUptime(1) hrSystemDate(2) hrSystemInitialLoadDevice(3) hrSystemInitialLoadParamete rs(4) hrSystemNumUsers(5) hrSystemProcesses(6) TimeTicks DateAndTime Integer32 DisplayString Gauge32 Gauge32 Thi gian tri qua k t khi host khi ng,tnh bng phn trm giy Ngy gi local ca host Index ca thit b m host c cu hnh load h iu hnh (danh sch thit b v index nm trong hrDeviceEntry) Chui tham s cung cp cho thit b cha HH khi khi ng S lng session ca cc user ang log vo host S lng process ang chy trn host Syntax Description Host-Recources-Mib (RFC2790) OID : .1.3.6.1.2.1.25

DIP THANH NGUYN, 2010

Trang|

13

SNMP ton tp

Chng 3 : Management Information Base

hrSystemMaxProcesses(7) hrStorage(2) hrStorageTypes(1) hrMemorySize(2) hrStorageTable(3) hrStorageEntry(1) hrStorageIndex(1) hrStorageType(2) hrStorageDescr(3) hrStorageAllocationUni ts(4) hrStorageSize(5) hrStorageUsed(6) hrStorageAllocationFail ures(7) hrDevice(3) hrProcessorTable(3) hrProcessorEntry(1) hrProcessorFrwID(1) hrProcessorLoad(2) hrSWRunPerf(5) hrSWRunPerfTable(1) hrSWRunPerfEntry(1) hrSWRunPerfCPU(1) hrSWRunPerfMem(2) hrSWInstalled(6) hrSWInstalledLastChange(1) hrSWInstalledLastUpdateTim e(2) hrSWInstalledTable(3) hrSWInstalledEntry(1) hrSWInstalledIndex(1) hrSWInstalledName(2) hrSWInstalledID(3)

Integer32

S lng process ti a m h thng c th h tr, nu h thng khng gii hn s process th object ny = 0 (cha c nh ngha)

KBytes Sequence hrStorageEntry Integer32 AutonomousTyp e DisplayString Integer32 Integer32 Integer32 Counter32

Dung lng b nh vt l chnh ca host, thng l RAM Bng cha cc vng lu tr logic trn host Gi tr duy nht ca mi thit b lu tr vt l trn host Kiu thit b lu tr M t thit b lu tr Kch thc tnh bng byte ca mt n v lu tr d liu, vd trn windows ntfs mc nh mi block l 4KB Kch thc ca thit b lu tr, dn v tnh l hrStorageAllocationUnits Dung lng s dng, tnh bng hrStorageAllocationUnits S ln cc yu cu lu tr b t chi do khng cn dung lng trng Bng cha thng tin v b x l ca host

ProductID Integer

M sn phm ca b x l T l phn trm thi gian bn ca cpu, tnh trung bnh trong 1 pht va qua Bng cha cc kt qu o hiu sut chim dng cpu & ram ca tng process Thi gian chim dng cpu ca cc process chy trn my, tnh bng centi-second Lng b nh c cp pht cho process Gi tr ca sysUpTime t khi c mt phn mm no c ci, thay i hay g b Gi tr ca sysUpTime t khi hrSWInstalledTable c cp nht hon ton ln gn nht Danh sch cc phn mm c ci trn host Gi tr duy nht ca tng phn mm trn host Tn ca tng phn mm trn host, c th bao gm c tn nh sn xut, version. M sn phm ca phn mm

Integer32 KBytes

TimeTicks TimeTicks Sequence Integer32 DisplayString ProductID

DIP THANH NGUYN, 2010

Trang|

14

SNMP ton tp

Chng 3 : Management Information Base

hrSWInstalledType(4)

Integer

Kiu phn mm, gm : unknown(1), operatingSystem(2), deviceDriver(3), application(4) Thi im thay i gn nht trong cy th mc ca phn mm. Nu host khng bit thng tin ny th object ny phi mang gi tr 0000-0101,0:0:0,+0:0

hrSWInstalledDate(5)

DateAndTime

6. S dng net-snmp-utils trn Linux


Phn trn bn s dng mt cng c mib browser trn Windows, phn ny chng ta s thc hnh cch ly th cng cc thng tin ca my ch, bng cch dng cc lnh command-line trong b cng c netsnmp-utils lm vic vi host-recources-mib. H iu hnh c chn minh ha vn l CentOS 5, tuy nhin snmp agent trn CentOS 5 li khng h tr y mib ny nn chng ta s dng cc lnh trn CentOS gim st mt server Windows. dng c cc lnh snmp dng command line trn CentOS, bn phi ci t package net-snmp-utils. Chng 2 c phn hng dn cch ci v khi ng package net-snmp-utils trn CentOS v cch cu hnh dch v SNMP trn Windows. Cc v d trong phn ny s thc hin vi snmp version = 1, read-community = public, write-community = private, host = 192.168.1.100 (IP ca server Windows cn gim st). GetRequest C php :
% snmpget -v version -c read-community host object-id

Trong : + version : phin bn snmp, bao gm : 1, 2c, 3. + read-community : chui community dng ly thng tin. + host : domainname hoc IP ca thit b cn qun l. + object-id : nh danh ca object cn ly.
V d : ly thi gian tri qua k t lc khi ng my ch.

+ OID cn ly l host-resources-mib.hrSystemUptime.0 (.1.3.6.1.2.1.25.1.1.0)


# snmpget -v 1 -c public 192.168.1.100 .1.3.6.1.2.1.25.1.1.0 HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (16363328) 1 day, 21:27:13.28

+ Gi tr ly c l 16363328, cn c vo nh ngha ca host-resources-mib th hrSysUptime c tnh bng phn trm giy, do CentOS hin th lun gi tr c chuyn i thnh gi:pht:giy.miligiy. Trong cc cu lnh snmp, ngoi vic dng object-id dng s th ta cng c th nhp dng ch, vd :
# snmpget -v 1 -c public 192.168.1.100 HOST-RESOURCES-MIB::hrSystemUptime.0 HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (16363328) 1 day, 21:27:13.28

GetNextRequest C php :
% snmpgetnext -v version -c read-community host object-id V d : ly t l chim dng CPU.

+ OID cn ly l host-recources-mib.hrDevice.hrProcessorTable.hrProcessorEntry.hrProcessorLoad (.1.3.6.1.2.1.25.3.3.1.2). Mt host c th c nhiu processor nn thng tin ca mi processor l mt entry trong bng hrProcessorTable, nu mun ly thng tin ca processor x th OID cn ly phi c dng
DIP THANH NGUYN, 2010 Trang|

15

SNMP ton tp

Chng 3 : Management Information Base

hrProcessorLoad.x (.1.3.6.1.2.1.25.3.3.1.2.x) vi x l index ca processor . Cc OID hrProcessorLoad.x nm sau hrProcessorLoad, tuy nhin ta cha bit s x ny bt u t my nn ta phi thc hin GetNext trn OID hrProcessorLoad ly c ti ca cpu th nht. Sau thc hin GetNext trn OID ca cpu th nht th ta s ly c ti ca cpu th hai.
# snmpgetnext -v 1 -c public 192.168.1.100 .1.3.6.1.2.1.25.3.3.1.2 HOST-RESOURCES-MIB::hrProcessorLoad.3 = INTEGER: 3 # snmpgetnext -v 1 -c public 192.168.1.100 .1.3.6.1.2.1.25.3.3.1.2.3 HOST-RESOURCES-MIB::hrProcessorLoad.4 = INTEGER: 3

+ Ta thy sau khi GetNext OID hrProcessorLoad th ta c OID hrProcessorLoad.3 vi gi tr kiu INTEGER l 3. Ngha l cpu th nht c id l 3 trong agent ca host ang c gim st, v t l chim dng cpu trung bnh trong 1 pht va qua l 3%. CPU th hai c id l 4 v t l chim dng cng l 3%. + Bng cch ly gi tr hrProcessorLoad u n, phn mm gim st SNMP c th v c biu hot ng ca cpu trn host c gim st. Lu hrProcessorLoad c agent cp nht mi pht mt ln. SetRequest C php :
% snmpset -v version -c write-community host object-id type value

Trong : version : phin bn snmp, bao gm : 1, 2c, 3. write-community : chui community dng thit lp thng tin. host : domainname hoc IP ca thit b cn qun l. object-id : nh danh ca object cn set. type : kiu ca d liu s c set, l mt trong cc gi tr i, u, t, a, o, s, x, d, b, U, I, F, D (i: Integer, u: Unsigned Integer; t: TimeTicks; a: IPAddress; o: Object Identifier; s: String; x: Hex String; d: Decimal String; b: Bits; U: Unsigned Int64; I: Signed Int64; F: Float; D: Double) + value : gi tr c set. V d : t li tn my tnh. + Tn ca host khng thuc host-resources-mib m thuc v mib-2, OID l mib-2.system.sysName. Do host ch c mt tn nn tn ca host l sysName.0 (.1.3.6.1.2.1.1.5.0). sysName c kiu l OctetString nn tham s type trong lnh snmpset s l s. Ta thc hin ly tn trc v sau khi set thy s thay i.
# snmpget -v 1 -c public 192.168.1.100 .1.3.6.1.2.1.1.5.0 SNMPv2-MIB::sysName.0 = STRING: NguyenDiepPC # # snmpset -v 1 -c private 192.168.1.100 .1.3.6.1.2.1.1.5.0 s NewComputer SNMPv2-MIB::sysName.0 = STRING: NewComputer # # snmpget -v 1 -c public 192.168.1.100 .1.3.6.1.2.1.1.5.0 SNMPv2-MIB::sysName.0 = STRING: NewComputer

+ + + + +

Trap Cu lnh gi trap so vi cc lnh khc th phc tp hn do c nhiu tham s. Trong chng 1 c trnh by cu trc ca bn tin trap SNMPv1,bao gm cc trng enterpriseId, agent, genericTrap, specificTrap, timeStamp v variableBindings; lnh gi trap cng phi ch ra y cc trng ny. C php :
% snmptrap -v version -c trap-community host enterprise agent generic specific timestamp object-id type value

Trong : + version : phin bn snmp, bao gm : 1, 2c, 3.


DIP THANH NGUYN, 2010 Trang|

16

SNMP ton tp

Chng 3 : Management Information Base

+ trap-community : chui community dng gi trap. + host : domainname hoc IP ca my tnh nhn trap. + enterprise : id ca doanh nghip, dng nhn dng thit b gi trap l ca hng no, model g. + agent : domainname hoc IP ca thit b cn qun l, tham s agent ny c th khng cn ch ra trong dng lnh h thng t ng chn IP vo. + generic : loi trap generic (t 0 n 6), nu l trap ring th generic = 6 (enterprise-specific trap). + specific : loi trap specific. + timestamp : thi im xy ra s kin lm cho h thng gi trap, thng thng h thng gi trap ngay khi s kin xy ra nn timestamp bng vi thi im gi trap; tham s ny cng c th khng cn ch ra. + object-id : nh danh ca object c lin quan n s kin. + type : kiu gi tr ca object. + value : gi tr hin ti ca object. V d : thc hin gi trap thng bo rng tn ca h thng b thay i. + Bn hy dng phn mm Trap Viewer trong b phn mm Solarwinds xem trap. Ta s gi lp gi mt trap t mt switch Cisco Catalyst 2950 thng bo rng hostname ca n b thay i thnh Noname, mc d ni gi trap l my tnh chy CentOS. + Cisco c enterprise number l 9, v dng sn phm C2950 c id l .1.324 nn enterprise = .iso.org.dod.internet.private.enterprise.Cisco.1.324. Trap ny l loi t nh ngha nn generic = 6, v ta cho specific l bt k. object-id l sysName.0 v s kin ny lin quan n tn ca h thng. Cn value chnh l tn mi ca h thng, kiu ca sysName l OctetString nn type = s.
# snmptrap v 1 c public 192.168.1.100 .1.3.6.1.4.1.9.1.324 6 10 sysName.0 s Noname

+ Quan st trn Trap Viewer bn s thy mt trap hin ra.

Walk Walk khng phi l mt phng thc trong SNMP (khng c bn tin walk) m l tin ch ca net-snmputils. Walk cho php ly tt c object l con chu nm di mt object no nhng khng ly ht bng mib. Trong khi cng c iReasoning Mib Browser khi thc hin Walk th n s ly tt c object t v sau cho n ht bng mib. C php :
% snmpwalk -v version -c read-community host root-object-id

Trong : + version : phin bn snmp, bao gm : 1, 2c, 3. + read-community : chui community dng ly thng tin. + host : domainname hoc IP ca thit b cn qun l. + root-object-id : nh danh ca object c ly lm gc.

DIP THANH NGUYN, 2010

Trang|

17

SNMP ton tp

Chng 3 : Management Information Base

V d : Ly tt c thng tin nm di mib-2.system. # snmpwalk -v 1 -c public 192.168.1.100 system SNMPv2-MIB::sysDescr.0 = STRING: Hardware: x86 Family 15 Model 107 Stepping 2 AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build 3790 Multiprocessor Free) SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.311.1.1.3.1.2 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2366393) 6:34:23.93 SNMPv2-MIB::sysContact.0 = STRING: NguyenDiep SNMPv2-MIB::sysName.0 = STRING: NewComputer SNMPv2-MIB::sysLocation.0 = STRING: HCM SNMPv2-MIB::sysServices.0 = INTEGER: 79

Tm tt
+ MIB l mt cu trc d liu c thit k qun l cc thit b, l mt tp hp nh danh i tng c qun l. + SMI l chun quy nh cc cu trc d liu v thuc tnh ca tng i tng c qun l. + Theo SMIv1, mt i tng c qun l c kiu OBJECT-TYPE bao gm cc thuc tnh : SYNTAX (kiu d liu), ACCESS (quyn truy xut), STATUS (bc buc, ty chn), DESCRIPTION (m t ngha). Trong SMIv2 th kiu OBJECTTYPE bao gm cc thuc tnh : SYNTAX, MAX-ACCESS, UNITS, STATUS, DESCRIPTION, REFERENCE, INDEX, AUGMENT, DEFVAL. + mib-2 l mt chun mib ca cc thit b chy trn nn TCP/IP. + host-resources-mib l chun mib dng cho host. + thc hin cc phng thc SNMP bn c th dng cng c iReasoning Mib Browser trn Windows hoc netsnmp-utils trn Linux.

DIP THANH NGUYN, 2010

Trang|

18