Network
banshee/network-collection/network/snmp/
bgp-peers
The BGP peers of a router by SNMP (BGP4-MIB): the state of each session, its remote AS, its time established and its flaps.
by banshee1 installation2 versions
// The BGP peers of a router, by SNMP (BGP4-MIB, RFC 4273): the state of each session, the AS of the peer,
// how long the session has been established, and how many times it has come up, which shows a peer that
// flaps. A peer is named by its address. A peer the administrator has stopped reads "stopped", so that it
// does not pass for a peer that fell.
// BGP4-MIB lists IPv4 peers only, and counts no prefixes: the prefixes received are in each vendor's MIB.
need('protocol:snmp');
per('peer', 'Peers');
output('state', 'text', array('label' => 'Session state', 'per' => 'peer'));
output('remote-as', 'number', array('label' => 'Remote AS', 'per' => 'peer'));
output('established-for', 'number', array('label' => 'Time established', 'unit' => 'min', 'per' => 'peer'));
output('established-count', 'number', array('label' => 'Times established', 'per' => 'peer'));
watch.expect('down', 'Session down', 'state', array(
'help' => 'Critical when a session is neither established nor stopped by the administrator.',
'critical' => array('established', 'stopped'),
));
watch.increase('flapping', 'Session flapping', 'established-count', array('warning' => 2, 'window' => '1 h'));
watch.below('recently-established', 'Session established recently', 'established-for', array('warning' => 15, 'enabled' => false));
watch.missing('missing', 'Missing peer', 'state', array('enabled' => false));
// bgpPeerTable, by the address of the peer (four numbers, the IPv4 address): bgpPeerState,
// bgpPeerAdminStatus, bgpPeerRemoteAs, bgpPeerFsmEstablishedTransitions and bgpPeerFsmEstablishedTime (in
// seconds, how long the session has been established, or since it was last).
$peers = snmp.table(array(
'state' => '1.3.6.1.2.1.15.3.1.2',
'admin' => '1.3.6.1.2.1.15.3.1.3',
'remote-as' => '1.3.6.1.2.1.15.3.1.9',
'transitions' => '1.3.6.1.2.1.15.3.1.15',
'time' => '1.3.6.1.2.1.15.3.1.16',
));
if (list.count($peers) == 0) {
fail('misconfigured', 'The agent serves no BGP peer (bgpPeerTable, BGP4-MIB)',
'A router without BGP, or a view that does not grant BGP4-MIB to the poller.');
}
// bgpPeerState in words; bgpPeerAdminStatus stop (1) reads "stopped".
$states = array(1 => 'idle', 2 => 'connect', 3 => 'active', 4 => 'opensent', 5 => 'openconfirm', 6 => 'established');
foreach ($peers as $address => $row) {
$state = list.get($states, list.get($row, 'state', 0), 'unknown');
if (list.get($row, 'admin', 2) == 1) {
$state = 'stopped';
}
value('state', $state, $address);
if (list.has($row, 'remote-as')) {
value('remote-as', $row['remote-as'], $address);
}
if (list.has($row, 'transitions')) {
value('established-count', $row['transitions'], $address);
}
if ($state == 'established' && list.has($row, 'time')) {
value('established-for', number.round($row['time'] / 60, 1), $address);
}
}