Monitoring BGP Status with Zabbix Templates

Introduction to BGP Monitoring in Zabbix

Zabbix is a widely recognized tool for monitoring IT infrastructure including networks, servers, virtual machines, and cloud services. It also supports BGP monitoring to ensure proper routing information exchange and network performance.

To monitor BGP through Zabbix, SNMP protocol can be used to collect data from BGP-enabled devices like routers or switches. Configuring Zabbix to query these devices via SNMP allows for gathering essential metrics such as the number of BGP peers, route counts, and session states.

This article outlines two approaches:

  1. Manually adding items for monitoring
  2. Using Zabbix templates

Both methods achieve the same goal, but using templates streamlines the process by enabling automatic discovery of BGP peers.

Prerequisites for BGP Monitoring in Zabbix

1. Identify OID values for BGP-related nodes on the device
2. Enable SNMP agent on the target device

Huawei OID Reference (e.g., S7700)

https://support.huawei.com/enterprise/zh/doc/EDOC1100126910/5dad6178

Cisco OID Reference

https://oidref.com/1.3.6.1.2.1.15.3.1.2

Note: Some Huawei models may share similar OIDs; refer to official documentation for confirmation.

Understanding BGP Neighbor States

There are six key states of a BGP neighbor relationship that should be monitored in Zabbix:

1. Idle:
   BGP starts in this state and rejects incoming connections. After initialization, it attempts to establish a TCP connection and transitions to the Connect state.

2. Connect:
   Waits for the completion of TCP handshake. If successful, sends an Open message and moves to Opensent. Otherwise, retries connection or moves to Active.

3. Active:
   Attempts to initiate a TCP connection. On success, transitions to Opensent. If timeout occurs, returns to Connect.

4. Opensent:
   Has sent an Open message and waits for one from the peer. If valid, proceeds to OpenConfirm; otherwise, moves to Idle.

5. OpenConfirm:
   Awaiting confirmation from the peer. If Keeplive received, enters Established; Notification leads back to Idle.

6. Established:
   Session is fully operational. Messages are exchanged between peers until failure or shutdown.

Manual Method: Adding Items in Zabbix

First, identify how many BGP peers exist on the device.

For example, there are four BGP peers.

Step-by-step:

  1. Add monitoring items: Use the format OID.node.IP_address for each peer:

    1.3.6.1.2.1.15.3.1.2.10.0.0.250
    
    

    Where 1.3.6.1.2.1.15.3.1.2 is the base OID and 10.0.0.250 is the peer IP.

    Ensure unique keys to avoid conflicts. Create separate items for each of the four peers.

  2. Create triggers based on peer status.

  3. Generate graphs to visualize peer states over time.

  4. Configure alerting actions, such as email, WeChat, or DingTalk notifications.

Manual setup complete.

Automated Approach: Using Zabbix Templates

We'll use a pre-built template compatible with Zabbix 6.0 TLS version.

Import Template

Save the following YAML content into a file named template_bgpv4_snmp.yaml:

zabbix_export:
  version: '6.0'
  date: '2021-11-21T22:04:29Z'
  groups:
    -
      uuid: e0242822f07b4633a283b8dc935d3dd9
      name: Templates_Created
  templates:
    -
      uuid: 6bf016389ccf49c8b491ac73c41a4fd0
      template: 'BGPv4 SNMP'
      name: 'BGPv4 SNMP'
      description: |
        ## Description
        
        Template BGPv4 Sessions -Admin Status -Established Time -Operation Status -AS Name -BGP last Error By: Flavio Gomes Figueira Camacho Junior Require: ValueMaps .BGP4-MIB::bgpPeerAdminStatus .BGP4-MIB::bgpPeerState ExternalScript .as_name Base: BGP4-MIB.mib https://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml
        
        ## Overview
        
        Template BGPv4 Sessions

        -Admin Status

        -Established Time

        -Operation Status

        -AS Name

        -BGP last Error

        By: Flavio Camacho Junior

        
        Require:

        ValueMaps

        .BGP4-MIB::bgpPeerAdminStatus

        .BGP4-MIB::bgpPeerState

        ExternalScript

        .as_name
 
        Base: 

        BGP4-MIB.mib

        <https://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml>

        External Scripts and Value Mapping on my Github:
        
        https://github.com/flaviojunior1995/Zabbix-Templates
        
        
        
        ## Author
        
        Flavio Camacho Junior
        
      groups:
        -
          name: Templates_Created
      discovery_rules:
        -
          uuid: 860002e447bb45bca37b3c75527d38ee
          name: 'BGPv4 Peers Discovery'
          type: SNMP_AGENT
          snmp_oid: 'discovery[{#SNMPVALUE},.1.3.6.1.2.1.15.3.1.7,{#SNMPASN},.1.3.6.1.2.1.15.3.1.9]'
          key: BgpPeerDiscovery
          delay: 1h
          lifetime: 7d
          item_prototypes:
            -
              uuid: 9b1be237207d4e45bdd916f3b7af5a48
              name: 'AS Name for IPv4 peer $1'
              type: EXTERNAL
              key: 'as_name["{#SNMPVALUE}","{#SNMPASN}"]'
              delay: 1d
              history: 7d
              trends: '0'
              value_type: CHAR
              tags:
                -
                  tag: Application
                  value: BGPv4
                -
                  tag: Application
                  value: 'BGPv4 {#SNMPVALUE}'
            -
              uuid: 44dbf3e1fac84ff8a70047810ee08a62
              name: 'Administrative status for peer $1'
              type: SNMP_AGENT
              snmp_oid: '1.3.6.1.2.1.15.3.1.3.{#SNMPVALUE}'
              key: 'bgpPeerAdminStatus[{#SNMPVALUE}]'
              delay: 10m
              history: 7d
              trends: '0'
              valuemap:
                name: 'BGP4-MIB::bgpPeerAdminStatus'
              tags:
                -
                  tag: Application
                  value: BGPv4
                -
                  tag: Application
                  value: 'BGPv4 {#SNMPVALUE}'
            -
              uuid: 28010bead7854f5c871557f5b6dd9681
              name: 'Established time for peer $1'
              type: SNMP_AGENT
              snmp_oid: '1.3.6.1.2.1.15.3.1.16.{#SNMPVALUE}'
              key: 'bgpPeerFsmEstablishedTime[{#SNMPVALUE}]'
              delay: 10m
              history: 30d
              trends: '0'
              units: uptime
              tags:
                -
                  tag: Application
                  value: BGPv4
                -
                  tag: Application
                  value: 'BGPv4 {#SNMPVALUE}'
              trigger_prototypes:
                -
                  uuid: bca14f8136ae4df9ad04c56c7399ac53
                  expression: 'last(/BGPv4 SNMP/bgpPeerFsmEstablishedTime[{#SNMPVALUE}])<{$PEER_LOW_TIME}'
                  name: 'BGP peer up time low {#SNMPVALUE} ASN {#SNMPASN}'
                  priority: INFO
                  dependencies:
                    -
                      name: 'BGP peer {#SNMPVALUE} ASN {#SNMPASN} is DOWN'
                      expression: 'last(/BGPv4 SNMP/bgpPeerState[{#SNMPVALUE}],#3)<>6 and last(/BGPv4 SNMP/bgpPeerAdminStatus[{#SNMPVALUE}])=2'
            -
              uuid: fb9b74ba11ee4b62a38cfde81f0593f4
              name: 'BGP peer last error {#SNMPVALUE}'
              type: SNMP_AGENT
              snmp_oid: '1.3.6.1.2.1.15.3.1.14.{#SNMPVALUE}'
              key: 'bgpPeerLastError[{#SNMPVALUE}]'
              delay: 10m
              history: 30d
              trends: '0'
              value_type: CHAR
              preprocessing:
                -
                  type: JAVASCRIPT
                  parameters:
                    - |
                      value = (value.replace(/\s+/g, ''));
                      
                      if (value === "0000") {
                         return "NO last error"
                      }
                      
                      if (value === "0100") {
                         return "Message Header Error - Unspecific"
                      }
                      
                      if (value === "0101") {
                         return "Message Header Error - Connection Not Synchronized"
                      }
                      
                      if (value === "0102") {
                         return "Message Header Error - Bad Message Length"
                      }
                      
                      if (value === "0103") {
                         return "Message Header Error - Bad Message Type"
                      }
                      
                      if (value === "0200") {
                         return "OPEN Message Error - Unspecific"
                      }
                      
                      if (value === "0201") {
                         return "OPEN Message Error - Unsupported Version Number"
                      }
                      
                      if (value === "0202") {
                         return "OPEN Message Error - Bad Peer AS"
                      }
                      
                      if (value === "0203") {
                         return "OPEN Message Error - Bad BGP Identifier"
                      }
                      
                      if (value === "0204") {
                         return "OPEN Message Error - Unsupported Optional Parameter"
                      }
                      
                      if (value === "0205") {
                         return "OPEN Message Error - [Deprecated]"
                      }
                      
                      if (value === "0206") {
                         return "OPEN Message Error - Unacceptable Hold Time"
                      }
                      
                      if (value === "0207") {
                         return "OPEN Message Error - Unsupported Capability";
                      }
                      
                      if (value === "0208") {
                         return "OPEN Message Error - Role Mismatch (Expire on 2021-03-29)"
                      }
                      
                      if (value === "0300") {
                         return "UPDATE Message Error - Unspecific"
                      }
                      
                      if (value === "0301") {
                         return "UPDATE Message Error - Malformed Attribute List"
                      }
                      
                      if (value === "0302") {
                         return "UPDATE Message Error - Unrecognized Well-known Attibute"
                      }
                      
                      if (value === "0303") {
                         return "UPDATE Message Error - Missing Well-know Attribute"
                      }
                      
                      if (value === "0304") {
                         return "UPDATE Message Error - Attribute Flags Error"
                      }
                      
                      if (value === "0305") {
                         return "UPDATE Message Error - Attribute Length Error"
                      }
                      
                      if (value === "0306") {
                         return "UPDATE Message Error - Invalid ORIGIN Attribute"
                      }
                      
                      if (value === "0307") {
                         return "UPDATE Message Error - [Deprecated]"
                      }
                      
                      if (value === "0308") {
                         return "UPDATE Message Error - Invalid NEXT_HOP Attribute"
                      }
                      
                      if (value === "0309") {
                         return "UPDATE Message Error - Optional Attribute Error"
                      }
                      
                      if (value === "0310") {
                         return "UPDATE Message Error - Invalid Network Field"
                      }
                      
                      if (value === "0311") {
                         return "UPDATE Message Error - Malformed AS_PATH"
                      }
                      
                      if (value === "0400") {
                         return "Hold Timer Expired"
                      }
                      
                      if (value === "0500") {
                         return "Finite State Machine Error - Unspecified Error"
                      }
                      
                      if (value === "0501") {
                         return "Finite State Machine Error - Receive Unexpected Message in OpenSent State"
                      }
                      
                      if (value === "0502") {
                         return "Finite State Machine Error - Receive Unexpected Message in OpenConfirm State"
                      }
                      
                      if (value === "0503") {
                         return "Finite State Machine Error - Receive Unexpected Message in Established State"
                      }
                      
                      if (value === "0600") {
                         return "Cease NOTIFICATION - Reserved"
                      }
                      
                      if (value === "0601") {
                         return "Cease NOTIFICATION - Maximum Number of Prefixes Reached"
                      }
                      
                      if (value === "0602") {
                         return "Cease NOTIFICATION - Administrative Shutdown"
                      }
                      
                      if (value === "0603") {
                         return "Cease NOTIFICATION - Peer De-configured"
                      }
                      
                      if (value === "0604") {
                         return "Cease NOTIFICATION - Administrative Reset"
                      }
                      
                      if (value === "0605") {
                         return "Cease NOTIFICATION - Connection Rejected"
                      }
                      
                      if (value === "0606") {
                         return "Cease NOTIFICATION - Other Configuration Change"
                      }
                      
                      if (value === "0607") {
                         return "Cease NOTIFICATION - Connection Collision Resolution"
                      }
                      
                      if (value === "0608") {
                         return "Cease NOTIFICATION - Out of Resources"
                      }
                      
                      if (value === "0609") {
                         return "Cease NOTIFICATION - Hard Reset"
                      }
                      
                      if (value === "0700") {
                         return "ROUTE-REFRESH Message Error - Reserded"
                      }
                      
                      if (value === "0701") {
                         return "ROUTE-REFRESH Message Error - Invalid Message Length"
                      }
                      
                      return value
              tags:
                -
                  tag: Application
                  value: BGPv4
                -
                  tag: Application
                  value: 'BGPv4 {#SNMPVALUE}'
            -
              uuid: 32ffca92bd1644e1b99ba8f8b6b2cf65
              name: 'Remote AS for peer $1'
              type: SNMP_AGENT
              snmp_oid: '1.3.6.1.2.1.15.3.1.9.{#SNMPVALUE}'
              key: 'bgpPeerRemoteAs[{#SNMPVALUE}]'
              delay: 1d
              history: 7d
              trends: '0'
              tags:
                -
                  tag: Application
                  value: BGPv4
                -
                  tag: Application
                  value: 'BGPv4 {#SNMPVALUE}'
            -
              uuid: af084bc48aed4b189ef4c8a5caf21405
              name: 'Operational status for peer $1'
              type: SNMP_AGENT
              snmp_oid: '1.3.6.1.2.1.15.3.1.2.{#SNMPVALUE}'
              key: 'bgpPeerState[{#SNMPVALUE}]'
              history: 30d
              trends: '0'
              valuemap:
                name: 'BGP4-MIB::bgpPeerState'
              tags:
                -
                  tag: Application
                  value: BGPv4
                -
                  tag: Application
                  value: 'BGPv4 {#SNMPVALUE}'
          trigger_prototypes:
            -
              uuid: 454e93c4d273469ba4e9baac37a5ff5e
              expression: 'last(/BGPv4 SNMP/bgpPeerState[{#SNMPVALUE}],#3)<>6 and last(/BGPv4 SNMP/bgpPeerAdminStatus[{#SNMPVALUE}])=2'
              name: 'BGP peer {#SNMPVALUE} ASN {#SNMPASN} is DOWN'
              priority: HIGH
              description: 'Trigger for peer that has a remote AS matching {$BGP_PEER_AS} macro.'
      macros:
        -
          macro: '{$PEER_LOW_TIME}'
          value: '14400'
          description: 'time in sec alarm for low uptime bgp session'
      valuemaps:
        -
          uuid: f94f32d1110545879431b948674e0be4
          name: 'BGP4-MIB::bgpPeerAdminStatus'
          mappings:
            -
              value: '1'
              newvalue: stoped
            -
              value: '2'
              newvalue: started
        -
          uuid: 292fe22b2d484c27a5fe38ff1f95cfa5
          name: 'BGP4-MIB::bgpPeerState'
          mappings:
            -
              value: '1'
              newvalue: idle
            -
              value: '2'
              newvalue: connect
            -
              value: '3'
              newvalue: active
            -
              value: '4'
              newvalue: opensent
            -
              value: '5'
              newvalue: openconfirm
            -
              value: '6'
              newvalue: established

Import this file into Zabbix 6.0.

Apply Template

After importing, assign the template to your switch or router.

Click on "Auto-discovery" and then "Test".

Run the discovery manually to populate monitoring items.

Alerting and notification settings follow a similar pattern to manual setups.

Tags: BGP SNMP Zabbix monitoring template

Posted on Sun, 01 Nov 2026 16:43:53 +0000 by daniel_mintz