Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new template to collect BGP peer information for Juniper devices #228

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Juniper BGP Stats by SNMP

## Overview

This template uses SNMP-LLD to generate monitoring items that collect BGP neighbor-related information, including neighbor state, the number of route entries received, and other data.

Template is made in version 6.4, which theoretically supports zabbix 5.4 or higher, try to modify the version field if you have problems with importing.

### Author
change4826

### Features

1. Supports IPv4/IPv6 BGP neighbors.
2. Uses preprocessing to handle IPv4/IPv6 address hex to text parsing, abbreviation.

### Items

1. Peer State: Represents the adjacency state of BGP neighbors.
2. PrefixesAccepted count: Represents the number of route entries received from specific neighbors and accepted after policy filtering.
3. PrefixesReceived count: Represents the total number of route entries received from specific neighbors.

### Triggers

1. Peer State: A base trigger on neighbor adjacency status, set as unclassified level and can be freely adjusted as needed.
2. PrefixesAccepted: Triggered when the latest value is not 0 and greater than 100, and the change interval of the latest value is greater than 40% (set in {$DIFF_RATIO}) compared to the change interval at the same time the previous day.

### Macros

1. {$DIFF_RATIO}: Used in triggers to define the change ratio of PrefixesAccepted, for example, 0.4 represents 40%.
2. {$ACCEPT_MIN}: Used in triggers to define the minimum value of PrefixesAccepted count received.

### LLD filters

- {$IGNORE_ASN}: Defines the range or individual Autonomous System Numbers to be ignored.
- {#PEEREMOTEADDR}: Optional, this LLD macro can be used to filter individual peers if needed.
- {#PEERSTATE}: Only considers adjacency with an established=6 state.

### Other Suggestions

- It is recommended to set trigger dependency chains: PrefixesAccepted->Peer State->other Juniper Device template triggers such as **High ICMP ping loss/High ICMP ping response time/Unavailable by ICMP ping/No SNMP data collection**.
- Be sure to test and make good use of LLD filters before deploying in a production environment.
- If you encounter a Zabbix error snmp_parse_oid() during testing, you may need to add mibs -BGP4-V2-MIB-JUNIPER in /etc/snmp/snmp.conf to cancel the parsing of mib-jnx-bgpmib2.txt, or move mib-jnx-bgpmib2.txt out of the corresponding snmp-mib-path directory.
- Tested on MX series such as MX960, MX480, MX240, etc. Other QFX51 series are also applicable, and Junos versions 12-20 are compatible.
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
zabbix_export:
version: '6.0'
template_groups:
- uuid: b91c91171d9d4f7d896da04811adc6c4
name: juniper
- uuid: 36bff6c29af64692839d077febfc7079
name: 'Templates/Network devices'
templates:
- uuid: 6325cab40a7e423a8193355a4b34200c
template: template_juniper_bgp_stats_by_snmp
name: template_juniper_bgp_stats_by_snmp
groups:
- name: juniper
- name: 'Templates/Network devices'
discovery_rules:
- uuid: b5f9ea9f3377492c967352aa6a28f314
name: bgp.info.base
type: SNMP_AGENT
snmp_oid: 'discovery[{#PEERSTATE},1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2,{#ADDRESSTYPE},1.3.6.1.4.1.2636.5.1.1.2.1.1.1.10,{#PEEREMOTEADDR},1.3.6.1.4.1.2636.5.1.1.2.1.1.1.11,{#PEERAS},1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13,{#PEERINDEX},1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14]'
key: bgp.info.discovery
delay: 1h
filter:
evaltype: AND
conditions:
- macro: '{#PEERAS}'
value: '{$IGNORE_ASN}'
operator: NOT_MATCHES_REGEX
formulaid: A
- macro: '{#PEERSTATE}'
value: '6'
formulaid: B
item_prototypes:
- uuid: 635aca7e338c40c095a720d80015039f
name: 'BGP Peer {#PEEREMOTEADDR} - State'
type: SNMP_AGENT
snmp_oid: '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.{#SNMPINDEX}'
key: 'jnxBgpM2PeerState.[{#PEERINDEX}]'
valuemap:
name: 'BGP FSM state'
tags:
- tag: function
value: 'bgp info'
- tag: item-type
value: 'bgp FSM'
trigger_prototypes:
- uuid: 7e1d3d0356c04d25bf17930864f11d74
expression: 'last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}]) <> 6 and last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}],#2) <> 6'
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: 'last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}])= 6 and avg(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}],5m) = 6'
name: 'BGP Peer {#PEEREMOTEADDR} - state change'
opdata: 'Current value: {ITEM.VALUE}'
manual_close: 'YES'
dependencies:
- name: 'BGP Peer {#PEEREMOTEADDR} - state change'
expression: 'last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}]) <> 6 and last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}],#2) <> 6'
recovery_expression: 'last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}])= 6 and avg(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PeerState.[{#PEERINDEX}],5m) = 6'
tags:
- tag: function
value: 'bgp info'
- tag: type
value: base
- uuid: 102e22efec2244179a74140abf6d481e
name: 'BGP Peer {#PEEREMOTEADDR} - PrefixesReceived count'
type: SNMP_AGENT
snmp_oid: '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7.{#PEERINDEX}'
key: 'jnxBgpM2PrefixInPrefixes.[{#PEERINDEX}]'
tags:
- tag: function
value: 'bgp info'
- tag: item-type
value: PrefixesReceived
- uuid: ff0cac6bb5024b8595e965f1ceee3d13
name: 'BGP Peer {#PEEREMOTEADDR} - PrefixesAccepted count'
type: SNMP_AGENT
snmp_oid: '.1.3.6.1.4.1.2636.5.1.1.2.6.2.1.8.{#PEERINDEX}'
key: 'jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}]'
tags:
- tag: function
value: 'bgp info'
- tag: item-type
value: PrefixesAccept
trigger_prototypes:
- uuid: 23a2939aa44b4ed091c3a767544cad2a
expression: |
(last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}]) <> 0 and last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}]) >= {$ACCEPT_MIN} )


and

((abs( last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}]) - avg(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}],1h:now-1d) ) / avg(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}],1h:now-1d)) >= {$DIFF_RATIO}

and

(abs( last(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}]) - avg(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}],1h:now-1w) ) / avg(/template_juniper_bgp_stats_by_snmp/jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}],1h:now-1w)) >= {$DIFF_RATIO})
name: 'BGP Peer {#PEEREMOTEADDR} PrefixesAccepted value changes more than {$DIFF_RATIO}'
opdata: 'Current value: {ITEM.VALUE}'
priority: INFO
description: 'bgp PrefixesAccepted value changes more than > {$DIFF_RATIO}'
manual_close: 'YES'
tags:
- tag: function
value: 'bgp info'
- tag: scope
value: notice
- tag: type
value: 'Accepted Change'
graph_prototypes:
- uuid: ef1804b373b24a3cbefe845406ca6b05
name: 'BGP Peer {#PEEREMOTEADDR} - PrefixesAccepted count'
graph_items:
- drawtype: BOLD_LINE
color: 0040FF
calc_fnc: ALL
item:
host: template_juniper_bgp_stats_by_snmp
key: 'jnxBgpM2PrefixInPrefixesAccepted.[{#PEERINDEX}]'
preprocessing:
- type: JAVASCRIPT
parameters:
- |
var json = JSON.parse(value);

function hexToIpv6(hexString) {
var hexArray = hexString.trim().split(" ");
var ipv6 = [];
for (var i = 0; i < hexArray.length; i += 2) {
ipv6.push(hexArray[i] + hexArray[i + 1]);
}
return ipv6.join(":");
}

function abbreviateIpv6(ipv6Address) {
var addr = ipv6Address.replace(/(^|:)(0)+(?=:|$)/g, ':').replace(/:{3,}/g, '::');
return addr === '::' ? '0' + addr : addr;
}

function hexToIpAddress(hexString) {
var hexArray = hexString.trim().split(" ");
var ipArray = hexArray.map(function(hex) {
return parseInt(hex, 16);
});
return ipArray.join(".");
}

json.forEach(function(obj) {
if (obj["{#ADDRESSTYPE}"] === "1") {
obj["{#PEERINDEX}"] += ".1.1";
obj["{#PEEREMOTEADDR}"] = hexToIpAddress(obj["{#PEEREMOTEADDR}"]);
} else if (obj["{#ADDRESSTYPE}"] === "2") {
obj["{#PEERINDEX}"] += ".2.1";
var ipv6Address = hexToIpv6(obj["{#PEEREMOTEADDR}"]);
obj["{#PEEREMOTEADDR}"] = abbreviateIpv6(ipv6Address).toLowerCase();
}
});

return JSON.stringify(json);
tags:
- tag: function
value: 'bgp stats'
- tag: vendor
value: juniper
macros:
- macro: '{$ACCEPT_MIN}'
value: '100'
- macro: '{$DIFF_RATIO}'
value: '0.4'
- macro: '{$IGNORE_ASN}'
value: '^6[45]*'
valuemaps:
- uuid: 649f22ef0f464d1d98ebe112636f384b
name: 'BGP FSM state'
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Juniper BGP Stats by SNMP

## Overview

This template uses SNMP-LLD to generate monitoring items that collect BGP neighbor-related information, including neighbor state, the number of route entries received, and other data.


### Author
change4826

### Features

1. Supports IPv4/IPv6 BGP neighbors.
2. Uses preprocessing to handle IPv4/IPv6 address hex to text parsing, abbreviation.

### Items

1. Peer State: Represents the adjacency state of BGP neighbors.
2. PrefixesAccepted count: Represents the number of route entries received from specific neighbors and accepted after policy filtering.
3. PrefixesReceived count: Represents the total number of route entries received from specific neighbors.

### Triggers

1. Peer State: A base trigger on neighbor adjacency status, set as unclassified level and can be freely adjusted as needed.
2. PrefixesAccepted: Triggered when the latest value is not 0 and greater than 100, and the change interval of the latest value is greater than 40% (set in {$DIFF_RATIO}) compared to the change interval at the same time the previous day.

### Macros

1. {$DIFF_RATIO}: Used in triggers to define the change ratio of PrefixesAccepted, for example, 0.4 represents 40%.
2. {$ACCEPT_MIN}: Used in triggers to define the minimum value of PrefixesAccepted count received.

### LLD filters

- {$IGNORE_ASN}: Defines the range or individual Autonomous System Numbers to be ignored.
- {#PEEREMOTEADDR}: Optional, this LLD macro can be used to filter individual peers if needed.
- {#PEERSTATE}: Only considers adjacency with an established=6 state.

### Other Suggestions

- It is recommended to set trigger dependency chains: PrefixesAccepted->Peer State->other Juniper Device template triggers such as **High ICMP ping loss/High ICMP ping response time/Unavailable by ICMP ping/No SNMP data collection**.
- Be sure to test and make good use of LLD filters before deploying in a production environment.
- If you encounter a Zabbix error snmp_parse_oid() during testing, you may need to add mibs -BGP4-V2-MIB-JUNIPER in /etc/snmp/snmp.conf to cancel the parsing of mib-jnx-bgpmib2.txt, or move mib-jnx-bgpmib2.txt out of the corresponding snmp-mib-path directory.
- Tested on MX series such as MX960, MX480, MX240, etc. Other QFX51 series are also applicable, and Junos versions 12-20 are compatible.
Loading