2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/router/cisco_bgp_

107 lines
2.6 KiB
Plaintext
Raw Normal View History

2009-05-04 20:35:23 +02:00
#!/usr/bin/perl -w
#
# Plugin to monitor BGP table summary statistics on a cisco router.
#
# Original Author: Peter Holzleitner
#
2010-10-15 19:29:08 +02:00
# Revision 1.1 2010/10/14 19:19
2009-05-04 20:35:23 +02:00
#
# Configuration variables:
#
# iosuser - username (default "")
# iospass - password (default "")
#
# Parameters:
#
# config (required)
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#%# family=auto
use Net::Telnet::Cisco;
2010-10-15 19:29:08 +02:00
use Sys::Syslog;
2009-05-04 20:35:23 +02:00
if ($0 =~ /^(?:|.*\/)cisco_bgp_([^_]+)$/) {
$host = $1;
}
2010-10-15 19:29:08 +02:00
($^O eq "linux" || $^O eq "openbsd") && Sys::Syslog::setlogsock('unix');
openlog('munin.bgp', 'cons,pid', 'daemon');
2009-05-04 20:35:23 +02:00
my @BGP_nbr;
my @BGP_pfx;
my $tot_pfx;
my $iosuser = $ENV{iosuser} || "";
my $iospass = $ENV{iospass} || "";
&fetch_bgpstats($host, $iosuser, $iospass);
if ($ARGV[0] and $ARGV[0] eq "config") {
print "host_name $host\n";
print "graph_args --base 1024 -l 0 --vertical-label Prefixes\n";
print "graph_title BGP Neighbour Statistics\n";
print "graph_category network\n";
print "graph_info This graph shows the number of BGP prefixes received by neighbour.\n";
my($n, $i); $n = scalar @BGP_nbr; $i = 0;
while($n--) {
my $neigh = $BGP_nbr[$i++];
print "n$i.label $neigh\n";
}
# print "total.label Total\n";
# print "total.info Total number of prefixes in the BGP table\n";
} else {
my($n, $i); $n = scalar @BGP_nbr; $i = 0;
while($n--) {
my $pfx = $BGP_pfx[$i++];
print "n$i.value $pfx\n";
}
# print "total.value $tot_pfx\n";
}
sub fetch_bgpstats
{
my $hostname = shift;
my $username = shift;
my $password = shift;
my $session = Net::Telnet::Cisco->new(Host => $host);
2010-10-15 19:29:08 +02:00
2009-05-04 20:35:23 +02:00
$session->login($username, $password);
2010-10-15 19:29:08 +02:00
$session->cmd('terminal length 200');
$session->cmd('terminal width 200');
2009-05-04 20:35:23 +02:00
my @output = $session->cmd('show ip bgp summary');
2010-10-15 19:29:08 +02:00
# example output of router
# ------------------------
# [...]
# Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
# 11.111.11.111 4 98765 12403694 509571 308911893 0 0 1d23h 329193
# 122.122.122.122 4 1234 13242856 383827 308911879 0 0 00:08:22 330761
2009-05-04 20:35:23 +02:00
foreach(@output) {
2010-10-15 19:29:08 +02:00
chomp; s/\r//g;
2009-05-04 20:35:23 +02:00
$tot_pfx = $1 if /^BGP activity (\d+)\/(\d+) prefixes/;
2010-10-15 19:29:08 +02:00
syslog('debug', "$hostname: $_\n");
next unless /^(\d+\.\d+\.\d+\.\d+)\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+[0-9a-z:]+\s+(\d+)/;
2009-05-04 20:35:23 +02:00
my ($neigh, $as, $pfx) = ($1, $2, $3);
2010-10-15 19:29:08 +02:00
syslog('debug', "$neigh (AS $as)");
2009-05-04 20:35:23 +02:00
push @BGP_nbr, "$neigh (AS $as)";
push @BGP_pfx, $pfx;
}
}
# vim:syntax=perl:ts=8