SNMP¶
Contents:
Contents
debianでのMIBインストール¶
sudo apt-get install snmp-mibs-downloader snmp
sudo /usr/bin/download-mibs
snmptranslate -Tp
> ここではisoしかでないはず
$ sudo vi /etc/snmp/snmp.conf
mibs +ALL
MIBDIRS +/var/lib/mibs/local
snmptranslate -Tp
ロードされているの分かる
変換の基礎¶
snmptranslate -On IF-MIB::ifDescr.1
.1.3.6.1.2.1.2.2.1.2.1
でname ->numが変換でき、
snmptranslate .1.3.6.1.2.1.2.2.1.2.1
IF-MIB::ifDescr.1
とOIDに変換できる。
MIBの追加¶
例えば、今の状態だと、
snmptranslate -On CISCO-NBAR-PROTOCOL-DISCOVERY-MIB::cnpdAllStatsProtocolName.15.26
CISCO-NBAR-PROTOCOL-DISCOVERY-MIB::cnpdAllStatsProtocolName.15.26: Unknown Object Identifier
となる。
例えば、Ciscoなら、
http://tools.cisco.com/ITDIT/MIBS/servlet/index
の
ftp://ftp.cisco.com/pub/mibs/supportlists/asr1000/asr1000-supportlist.html
から
ftp://ftp.cisco.com/pub/mibs/v2/CISCO-NBAR-PROTOCOL-DISCOVERY-MIB.my
を得られる。
つまり、
cd /var/lib/mibs
sudo mkdir local
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-PROCESS-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/SNMP-FRAMEWORK-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/HCNUM-TC.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-TC.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-SMI.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-BGP4-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-OSPF-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-OSPF-TRAP-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-PPPOE-MIB.my
sudo wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-NBAR-PROTOCOL-DISCOVERY-MIB.my
snmptranslate -On CISCO-NBAR-PROTOCOL-DISCOVERY-MIB::cnpdAllStatsProtocolName.15.26
.1.3.6.1.4.1.9.9.244.1.2.1.1.2.15.26
snmptranslate .1.3.6.1.4.1.9.9.244.1.2.1.1.2.15.26
CISCO-NBAR-PROTOCOL-DISCOVERY-MIB::cnpdAllStatsProtocolName.15.26
できたー。
どこが読まれている?¶
MIB search path: /home/kanai/.snmp/mibs:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp
+--iso(1)
よく使うMIB¶
SNMPv2-MIB::sysName.0 = STRING: router1
> hostname
IF-MIB::ifIndex.1 = INTEGER: 1
> ifnumのindexをとってくるならこれ
IF-MIB::ifDescr.1 = STRING: 10GigabitEthernet1/1
.1.3.6.1.2.1.2.2.1.2.1 = STRING: 10GigabitEthernet1/1
IF-MIB::ifName.1 = STRING: ethernet1/1
IF-MIB::ifMtu.1 = INTEGER: 1548
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.1 = INTEGER: down(2)
IF-MIB::ifInErrors.1 = Counter32: 0
IF-MIB::ifOutErrors.1 = Counter32: 0
IF-MIB::ifAlias.1 = STRING: test-port
IF-MIB::ifHCInOctets.1 = Counter64: 0
IF-MIB::ifHCOutOctets.1 = Counter64: 0
IF-MIB::ifHighSpeed.1 = Gauge32: 10000
> MB単位の速度
BRIDGE-MIB::dot1dTpFdbAddress.
.1.3.6.1.2.1.17.4.3.1.1
Q-BRIDGE-MIB::dot1qTpFdbPort
.1.3.6.1.2.1.17.7.1.2.2.1.2
IP-MIB::ipAdEntAddr.192.168.0.100 = IpAddress: 192.168.0.100
IP-MIB::ipAdEntAddr.10.1.1.1 = IpAddress: 10.1.1.1
IP-MIB::ipAdEntIfIndex.192.168.0.100 = INTEGER: 2049
IP-MIB::ipAdEntIfIndex.10.1.1.1 = INTEGER: 16777219
IP-MIB::ipAdEntNetMask.192.168.0.100 = IpAddress: 255.255.254.0
IP-MIB::ipAdEntNetMask.10.1.1.1 = IpAddress: 255.255.255.0
> ポートの種別
MIBの変換をしたい¶
snmptest -On -v2c -c public router1
Variable: IF-MIB::ifDescr.1
Variable: <enterのみ押下>
.1.3.6.1.2.1.2.2.1.2.1 = STRING: 10GigabitEthernet1/1
snmptest -v2c -c public router1
Variable: .1.3.6.1.2.1.2.2.1.2.1
Variable:<enterのみ押下>
IF-MIB::ifDescr.1 = STRING: 10GigabitEthernet1/1
snmptrapd.conf¶
# apt-get install snmptrapd
# sudo vi /etc/default/snmpd
> TRAPDRUN=yes
authCommunity log,execute,net public
format1 hostname = "%A" source = "%a" security = "%P" enterprise = "%N" generic_type = "%W" specific_type = "%q" uptime = "%#T" variable-bindings: %V + % + %v
format2 hostname = "%B" source = "%b" security = "%P" variable-bindings:%V + % + %v
Pythonのライブラリ¶
sudo pip install pysnmp
pip install pysnmp-mibs
その後のconvert
build-pysnmp-mib -h