使用 SNMP 查詢 ADSL Router (ATU-R) 狀態
補充說明:
- 一個使用 SNMP 查詢網路設備狀態的範例
- 與 ADSL 相關的 MIB 參考:ADSL-LINE-MIB
由於在系統中裝了 snmpd 服務,加上知道 Alcatel SPEEDTOUCH 340 也有提供 SNMP 代理服務 (必須使用 telnet 設定方式才能看到,若用 Web 設定界面是看不到的 ),所以就試著透過 SNMP 來看看這顆 ATU-R 有啥特殊資訊。
確認主機與 ATU-R 同網段
除非使用的是固定多 IP 制的連線模式,否則 ATU-R 會使用 bridge 模式來代轉使用者的網路連線。這通常給使用者一個 ATU-R 本身沒有 IP 的假象。
只要是網路設備必然會有一個 IP 來代表( HUB沒有就是了 :p),ATU-R 也不例外。它的預設 IP 是 192.168.1.1,只要系統能有一個 IP 與 ATU-R 的預設 IP 同一網段時即可存取 ATU-R 上的資訊,至少我們可以透過 telnet , web 或者是 snmp 方式向 ATU-R 進行存取作業。
我的系統中內建有 5 個網路界面,因此指定其中一個網路界面的 IP 為 192.168.1.2,當然你也可以透過 alias IP 的方式讓同一張網卡擁有兩個以上的 IP ,設定完畢後先 ping ping 看是否可以連上 ATU-R。
確認已安裝 snmp utility
在 Linux 環境下,只要安裝 net-snmp 套件後即可;若是 Windows 系統則請自己看著辦。
Gentoo Linux 中可以使用以下方式檢查是否安裝 net-snmp 套件。
www tmp # emerge -s net-snmp Searching… [ Results for search key : net-snmp ] [ Applications found : 2 ]* dev-perl/Net-SNMP Latest version available: 4.1.2 Latest version installed: [ Not Installed ] Size of downloaded files: 70 kB Homepage: http://www.cpan.org/modules/by-module/Net/Net-SNMP-4.1.2.readme Description: A SNMP Perl Module License: Artistic* net-analyzer/net-snmp Latest version available: 5.0.9-r1 Latest version installed: 5.0.9-r1 Size of downloaded files: 2,290 kB Homepage: http://net-snmp.sourceforge.net/ Description: Software for generating and retrieving SNMP data. License: as-is
開始查詢 ATU-R 系統資訊
www tmp # snmpwalk 192.168.1.1 -c public -v 1 1.3.6.1.2.1.1 SNMPv2-MIB::sysDescr.0 = STRING: Alcatel SPEEDTOUCH 340 version 7.1.0.31 (patch) (25 April 2001) T60L280.01/H2.3.1.5.01/1.4.8 Copyright (c) 2001 SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.4684 SNMPv2-MIB::sysUpTime.0 = Timeticks: (83557662) 9 days, 16:06:16.62 SNMPv2-MIB::sysContact.0 = STRING: SNMPv2-MIB::sysName.0 = STRING: SNMPv2-MIB::sysLocation.0 = STRING: SNMPv2-MIB::sysServices.0 = INTEGER: 6
查詢 ATU-R 網路設備資訊
www tmp # snmpwalk 192.168.1.1 -c public -v 1 1.3.6.1.2.1.2
資料很多,所以可以改查詢網路設備的型別。
www tmp # snmpwalk 192.168.1.1 -c public -v 1 1.3.6.1.2.1.2.2.1.2 IF-MIB::ifType.1 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.2 = INTEGER: ppp(23) IF-MIB::ifType.3 = INTEGER: ppp(23) IF-MIB::ifType.4 = INTEGER: ppp(23) IF-MIB::ifType.5 = INTEGER: ppp(23) IF-MIB::ifType.6 = INTEGER: ppp(23) IF-MIB::ifType.7 = INTEGER: ppp(23) IF-MIB::ifType.8 = INTEGER: ppp(23) IF-MIB::ifType.9 = INTEGER: ppp(23) IF-MIB::ifType.10 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.11 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.12 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.13 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.14 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.15 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.16 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.17 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.18 = INTEGER: other(1) IF-MIB::ifType.19 = INTEGER: adsl(94) IF-MIB::ifType.20 = INTEGER: fast(125) IF-MIB::ifType.21 = INTEGER: interleave(124)
不過因為數字型式的 OID 難以記憶,通常會使用文字式代名。
www tmp # snmpwalk 192.168.1.1 -c public -v 1 interfaces.ifTable.ifEntry.ifType IF-MIB::ifType.1 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.2 = INTEGER: ppp(23) IF-MIB::ifType.3 = INTEGER: ppp(23) IF-MIB::ifType.4 = INTEGER: ppp(23) IF-MIB::ifType.5 = INTEGER: ppp(23) IF-MIB::ifType.6 = INTEGER: ppp(23) IF-MIB::ifType.7 = INTEGER: ppp(23) IF-MIB::ifType.8 = INTEGER: ppp(23) IF-MIB::ifType.9 = INTEGER: ppp(23) IF-MIB::ifType.10 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.11 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.12 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.13 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.14 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.15 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.16 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.17 = INTEGER: ethernetCsmacd(6) IF-MIB::ifType.18 = INTEGER: other(1) IF-MIB::ifType.19 = INTEGER: adsl(94) IF-MIB::ifType.20 = INTEGER: fast(125) IF-MIB::ifType.21 = INTEGER: interleave(124)
配合每一個界面的描述,大致上可以得知這 21 個界面的用途。
www tmp # snmpwalk 192.168.1.1 -c public -v 1 interfaces.ifTable.ifEntry.ifDescr IF-MIB::ifDescr.1 = STRING: ethernet IF-MIB::ifDescr.2 = STRING: ppp channel 1 IF-MIB::ifDescr.3 = STRING: ppp channel 2 IF-MIB::ifDescr.4 = STRING: ppp channel 3 IF-MIB::ifDescr.5 = STRING: ppp channel 4 IF-MIB::ifDescr.6 = STRING: ppp channel 5 IF-MIB::ifDescr.7 = STRING: ppp channel 6 IF-MIB::ifDescr.8 = STRING: ppp channel 7 IF-MIB::ifDescr.9 = STRING: ppp channel 8 IF-MIB::ifDescr.10 = STRING: ppp1 IF-MIB::ifDescr.11 = STRING: ppp2 IF-MIB::ifDescr.12 = STRING: ppp3 IF-MIB::ifDescr.13 = STRING: ppp4 IF-MIB::ifDescr.14 = STRING: ppp5 IF-MIB::ifDescr.15 = STRING: ppp6 IF-MIB::ifDescr.16 = STRING: ppp7 IF-MIB::ifDescr.17 = STRING: ppp8 IF-MIB::ifDescr.18 = STRING: bridge IF-MIB::ifDescr.19 = STRING: ADSL physical interface IF-MIB::ifDescr.20 = STRING: ADSL fast channel IF-MIB::ifDescr.21 = STRING: ADSL interleaved channel
比對過 ifType 和 ifDescr 後,可以判定第 1 個網路界面是 ethernet,也就是接到內部網路的那個界面;第 18 個網路界面是 bridge, 若使用 bridge 模式時會在這個網路界面上產生 I/O;第 19 個網路界面是 adsl, 也就是 ADSL 實體線路,當線路異常時會在這個界面上產生反應。
範例:檢查網路是否斷線
透過 interfaces.ifTable.ifEntry.ifOperStatus.xx 可以查詢指定界面的連線狀態,如:
www tmp # snmpwalk 192.168.1.1 -c public -v 1 interfaces.ifTable.ifEntry.ifOperStatus.1 IF-MIB::ifOperStatus.1 = INTEGER: up(1) www tmp # snmpwalk 192.168.1.1 -c public -v 1 interfaces.ifTable.ifEntry.ifOperStatus.18 IF-MIB::ifOperStatus.18 = INTEGER: up(1) www tmp # snmpwalk 192.168.1.1 -c public -v 1 interfaces.ifTable.ifEntry.ifOperStatus.19 IF-MIB::ifOperStatus.19 = INTEGER: up(1)
查詢某個 OID 的意義
當查詢某個裝置的資訊時,發現有無法明確辨識的 SNMP 標籤時其實可以透過 net-snmp 套件所提供的轉譯工具,將標籤轉成較為明確的說明,如 ATU-R 中有這個一個標籤 IF-MIB::ifLastChange,他的實際意義可以這樣查詢:
www tmp # snmptranslate -Td -OS IF-MIB::ifLastChange IF-MIB::ifLastChange ifLastChange OBJECT-TYPE -- FROM IF-MIB, RFC1213-MIB SYNTAX TimeTicks MAX-ACCESS read-only STATUS current DESCRIPTION "The value of sysUpTime at the time the interface entered its current operational state. If the current state was entered prior to the last re-initialization of the local network management subsystem, then this object contains a zero value." ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) interfaces(2) ifTable(2) ifEntry(1) 9 }
也可以查詢 IF-MIB::ifOperStatus 的完整說明。
www tmp # snmptranslate -Td -OS IF-MIB::ifOperStatus IF-MIB::ifOperStatus ifOperStatus OBJECT-TYPE -- FROM IF-MIB, RFC1213-MIB SYNTAX INTEGER { up(1), down(2), testing(3), unknown(4), dormant(5), notPresent(6), lowerLayerDown(7) } MAX-ACCESS read-only STATUS current DESCRIPTION "The current operational state of the interface. The testing(3) state indicates that no operational packets can be passed. If ifAdminStatus is down(2) then ifOperStatus should be down(2). If ifAdminStatus is changed to up(1) then ifOperStatus should change to up(1) if the interface is ready to transmit and receive network traffic; it should change to dormant(5) if the interface is waiting for external actions (such as a serial line waiting for an incoming connection); it should remain in the down(2) state if and only if there is a fault that prevents it from going to the up(1) state; it should remain in the notPresent(6) state if the interface has missing (typically, hardware) components." ::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) interfaces(2) ifTable(2) ifEntry(1) 8 }
應用
當我們知道如何查詢指定硬體的 SNMP 資訊後,即可加以整理作為系統效能的參考依據或是錯誤警示等,或者透過 MRTG 等其他工具將數據資訊以圖示方式顯示出來。這部份就是個人的創意問題了。
沒有留言:
張貼留言