Print

交换机使用snmp上下文名字采集特定bgp instance进程信息

2026-06-28 发表

问题描述

在针对设备进行SNMP采集时有时会遇到如下情景:

想要采集bgp的邻居状态信息但是设备的bgp配置的是带instance的采集不到,只能采集到不带instance的

设备配置如下,有两个bgp进程

bgp 65201

 graceful-restart

 router-id 10.255.250.4

 peer 100.100.5.11 as-number 200

 peer 100.100.5.11 ebgp-max-hop 2

 peer 192.168.0.1 as-number 65200

 #

 address-family ipv4 unicast

  peer 100.100.5.11 enable

 #

 

bgp 65201 instance TEST

 graceful-restart

 router-id 10.255.250.4

 peer 100.100.7.11 as-number 200

 peer 100.100.7.11 ebgp-max-hop 2

 peer 192.168.0.1 as-number 65200

 #

 address-family ipv4 unicast

  peer 100.100.7.11 enable

#

通过1.3.6.1.2.1.15.3读取bgp邻居状态信息,可以看到只能读取到不带instance的bgp进程的邻居,如果客户想要读取带instance的邻居该怎么办呢

C:\Users\Administrator>snmpwalk -v 2c -c public 172.31.2.54 1.3.6.1.2.1.15.3

Cannot find module (IP-MIB): At line 0 in (none)

Cannot find module (IF-MIB): At line 0 in (none)

Cannot find module (TCP-MIB): At line 0 in (none)

Cannot find module (UDP-MIB): At line 0 in (none)

Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none)

Cannot find module (SNMPv2-MIB): At line 0 in (none)

Cannot find module (SNMPv2-SMI): At line 0 in (none)

Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none)

Cannot find module (UCD-SNMP-MIB): At line 0 in (none)

Cannot find module (UCD-DEMO-MIB): At line 0 in (none)

Cannot find module (SNMP-TARGET-MIB): At line 0 in (none)

Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none)

Cannot find module (DISMAN-EVENT-MIB): At line 0 in (none)

Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none)

Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none)

Cannot find module (UCD-DLMOD-MIB): At line 0 in (none)

Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none)

Cannot find module (SNMP-MPD-MIB): At line 0 in (none)

Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none)

Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none)

Cannot find module (SNMPv2-TM): At line 0 in (none)

iso.3.6.1.2.1.15.3.1.1.100.100.5.11 = IpAddress: 0.0.0.0

iso.3.6.1.2.1.15.3.1.2.100.100.5.11 = INTEGER: 2

iso.3.6.1.2.1.15.3.1.3.100.100.5.11 = INTEGER: 2

iso.3.6.1.2.1.15.3.1.4.100.100.5.11 = INTEGER: 0

iso.3.6.1.2.1.15.3.1.5.100.100.5.11 = IpAddress: 0.0.0.0

iso.3.6.1.2.1.15.3.1.6.100.100.5.11 = INTEGER: 0

iso.3.6.1.2.1.15.3.1.7.100.100.5.11 = IpAddress: 100.100.5.11

iso.3.6.1.2.1.15.3.1.8.100.100.5.11 = INTEGER: 0

iso.3.6.1.2.1.15.3.1.9.100.100.5.11 = INTEGER: 200

iso.3.6.1.2.1.15.3.1.10.100.100.5.11 = Counter32: 0

iso.3.6.1.2.1.15.3.1.11.100.100.5.11 = Counter32: 0

iso.3.6.1.2.1.15.3.1.12.100.100.5.11 = Counter32: 0

iso.3.6.1.2.1.15.3.1.13.100.100.5.11 = Counter32: 0

iso.3.6.1.2.1.15.3.1.14.100.100.5.11 = Hex-STRING: 00 00

iso.3.6.1.2.1.15.3.1.15.100.100.5.11 = Counter32: 0

iso.3.6.1.2.1.15.3.1.16.100.100.5.11 = Gauge32: 0

iso.3.6.1.2.1.15.3.1.17.100.100.5.11 = INTEGER: 32

iso.3.6.1.2.1.15.3.1.18.100.100.5.11 = INTEGER: 0

iso.3.6.1.2.1.15.3.1.19.100.100.5.11 = INTEGER: 0

iso.3.6.1.2.1.15.3.1.20.100.100.5.11 = INTEGER: 180

iso.3.6.1.2.1.15.3.1.21.100.100.5.11 = INTEGER: 60

iso.3.6.1.2.1.15.3.1.22.100.100.5.11 = INTEGER: 30

iso.3.6.1.2.1.15.3.1.23.100.100.5.11 = INTEGER: 30

iso.3.6.1.2.1.15.3.1.24.100.100.5.11 = Gauge32: 0

过程分析

此时可以通过增加snmp context-name来实现采集特定上下文内容的信息,snmp context-name命令可以配置于bgp,vpn,isis,ospf视图下,以BGP为例,通过MIB(Management Information Base,管理信息库)节点对BGP进行管理时,BGP无法获知被管理的节点属于哪个BGP实例。为不同的BGP实例配置不同的SNMP上下文可以解决上述问题。

设备接收到SNMP报文后,根据报文中携带的上下文(对于SNMPv3)或团体名称(对于SNMPv1/v2c),判断如何进行处理

 对于SNMPv3报文:

 如果报文中不携带上下文,且没有为default实例配置SNMP上下文,则对BGP default实例的MIB节点进行相应处理。

 如果报文中携带上下文,设备上存在对应的SNMP上下文(通过系统视图下的snmp-agent context命令创建),且该上下文与为某一个BGP实例配置的上下文相同,则对该BGP实例的MIB节点进行相应处理。

 其他情况下,不允许对任何MIB节点进行处理。

对于SNMPv1/v2c报文:

 如果设备上没有通过系统视图下的snmp-agent community-map命令将报文中的团体名映射为SNMP上下文,且没有为default实例配置SNMP上下文,则对BGP default实例的MIB节点进行相应处理。

 如果设备上将团体名映射为SNMP上下文,设备上存在对应的SNMP上下文,且该上下文与为某一个BGP实例配置的上下文相同,则对该BGP实例的MIB节点进行相应处理。

 其他情况下,不允许对任何MIB节点进行处理。

解决方法

具体配置如下
1、在instance bgp视图下增加snmp context-name
bgp 65201 instance TEST
graceful-restart
snmp context-name bgp-TEST
router-id 10.255.250.4
peer 100.100.7.11 as-number 200
peer 100.100.7.11 ebgp-max-hop 2
peer 192.168.0.1 as-number 65200
#
address-family ipv4 unicast
peer 100.100.7.11 enable
#
return
2、创建snmp团体名,并绑定snmp团体名和上下文的关系,需增加配置如下
 
display current-configuration | include snmp
...
snmp-agent community read TEST
snmp-agent context TEST
snmp-agent community-map TEST context bgp-TEST
 
3、使用snmpwalk命令读取时需要携带上下文参数,-n为指定上下文名,可以看到已经读取带实例bgp的邻居信息
C:\Users\Administrator>snmpwalk -v 2c -c TEST -n bgp-TEST 172.31.2.54 1.3.6.1.2.1.15.3
Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)
Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none)
Cannot find module (SNMPv2-MIB): At line 0 in (none)
Cannot find module (SNMPv2-SMI): At line 0 in (none)
Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none)
Cannot find module (UCD-SNMP-MIB): At line 0 in (none)
Cannot find module (UCD-DEMO-MIB): At line 0 in (none)
Cannot find module (SNMP-TARGET-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none)
Cannot find module (DISMAN-EVENT-MIB): At line 0 in (none)
Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none)
Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none)
Cannot find module (UCD-DLMOD-MIB): At line 0 in (none)
Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none)
Cannot find module (SNMP-MPD-MIB): At line 0 in (none)
Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none)
Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none)
Cannot find module (SNMPv2-TM): At line 0 in (none)
iso.3.6.1.2.1.15.3.1.1.100.100.7.11 = IpAddress: 0.0.0.0
iso.3.6.1.2.1.15.3.1.2.100.100.7.11 = INTEGER: 2
iso.3.6.1.2.1.15.3.1.3.100.100.7.11 = INTEGER: 2
iso.3.6.1.2.1.15.3.1.4.100.100.7.11 = INTEGER: 0
iso.3.6.1.2.1.15.3.1.5.100.100.7.11 = IpAddress: 0.0.0.0
iso.3.6.1.2.1.15.3.1.6.100.100.7.11 = INTEGER: 0
iso.3.6.1.2.1.15.3.1.7.100.100.7.11 = IpAddress: 100.100.7.11
iso.3.6.1.2.1.15.3.1.8.100.100.7.11 = INTEGER: 0
iso.3.6.1.2.1.15.3.1.9.100.100.7.11 = INTEGER: 200
iso.3.6.1.2.1.15.3.1.10.100.100.7.11 = Counter32: 0
iso.3.6.1.2.1.15.3.1.11.100.100.7.11 = Counter32: 0
iso.3.6.1.2.1.15.3.1.12.100.100.7.11 = Counter32: 0
iso.3.6.1.2.1.15.3.1.13.100.100.7.11 = Counter32: 0
iso.3.6.1.2.1.15.3.1.14.100.100.7.11 = Hex-STRING: 00 00
iso.3.6.1.2.1.15.3.1.15.100.100.7.11 = Counter32: 0
iso.3.6.1.2.1.15.3.1.16.100.100.7.11 = Gauge32: 0
iso.3.6.1.2.1.15.3.1.17.100.100.7.11 = INTEGER: 32
iso.3.6.1.2.1.15.3.1.18.100.100.7.11 = INTEGER: 0
iso.3.6.1.2.1.15.3.1.19.100.100.7.11 = INTEGER: 0
iso.3.6.1.2.1.15.3.1.20.100.100.7.11 = INTEGER: 180
iso.3.6.1.2.1.15.3.1.21.100.100.7.11 = INTEGER: 60
iso.3.6.1.2.1.15.3.1.22.100.100.7.11 = INTEGER: 30
iso.3.6.1.2.1.15.3.1.23.100.100.7.11 = INTEGER: 30
iso.3.6.1.2.1.15.3.1.24.100.100.7.11 = Gauge32: 0