root / plugins / router / cisco_bgp_ @ 5061ef1d
Historique | Voir | Annoter | Télécharger (2,6 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor BGP table summary statistics on a cisco router. |
| 4 |
# |
| 5 |
# Original Author: Peter Holzleitner |
| 6 |
# |
| 7 |
# Revision 1.1 2010/10/14 19:19 |
| 8 |
# |
| 9 |
# Configuration variables: |
| 10 |
# |
| 11 |
# iosuser - username (default "") |
| 12 |
# iospass - password (default "") |
| 13 |
# |
| 14 |
# Parameters: |
| 15 |
# |
| 16 |
# config (required) |
| 17 |
# |
| 18 |
# Magic markers (optional - only used by munin-config and some |
| 19 |
# installation scripts): |
| 20 |
#%# family=auto |
| 21 |
|
| 22 |
|
| 23 |
use Net::Telnet::Cisco; |
| 24 |
use Sys::Syslog; |
| 25 |
|
| 26 |
|
| 27 |
if ($0 =~ /^(?:|.*\/)cisco_bgp_([^_]+)$/) {
|
| 28 |
$host = $1; |
| 29 |
} |
| 30 |
|
| 31 |
($^O eq "linux" || $^O eq "openbsd") && Sys::Syslog::setlogsock('unix');
|
| 32 |
openlog('munin.bgp', 'cons,pid', 'daemon');
|
| 33 |
|
| 34 |
|
| 35 |
my @BGP_nbr; |
| 36 |
my @BGP_pfx; |
| 37 |
my $tot_pfx; |
| 38 |
my $iosuser = $ENV{iosuser} || "";
|
| 39 |
my $iospass = $ENV{iospass} || "";
|
| 40 |
|
| 41 |
&fetch_bgpstats($host, $iosuser, $iospass); |
| 42 |
|
| 43 |
|
| 44 |
if ($ARGV[0] and $ARGV[0] eq "config") {
|
| 45 |
print "host_name $host\n"; |
| 46 |
print "graph_args --base 1024 -l 0 --vertical-label Prefixes\n"; |
| 47 |
print "graph_title BGP Neighbour Statistics\n"; |
| 48 |
print "graph_category network\n"; |
| 49 |
print "graph_info This graph shows the number of BGP prefixes received by neighbour.\n"; |
| 50 |
|
| 51 |
my($n, $i); $n = scalar @BGP_nbr; $i = 0; |
| 52 |
while($n--) {
|
| 53 |
my $neigh = $BGP_nbr[$i++]; |
| 54 |
print "n$i.label $neigh\n"; |
| 55 |
} |
| 56 |
|
| 57 |
# print "total.label Total\n"; |
| 58 |
# print "total.info Total number of prefixes in the BGP table\n"; |
| 59 |
|
| 60 |
} else {
|
| 61 |
|
| 62 |
my($n, $i); $n = scalar @BGP_nbr; $i = 0; |
| 63 |
while($n--) {
|
| 64 |
my $pfx = $BGP_pfx[$i++]; |
| 65 |
print "n$i.value $pfx\n"; |
| 66 |
} |
| 67 |
# print "total.value $tot_pfx\n"; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
sub fetch_bgpstats |
| 74 |
{
|
| 75 |
my $hostname = shift; |
| 76 |
my $username = shift; |
| 77 |
my $password = shift; |
| 78 |
my $session = Net::Telnet::Cisco->new(Host => $host); |
| 79 |
|
| 80 |
$session->login($username, $password); |
| 81 |
$session->cmd('terminal length 200');
|
| 82 |
$session->cmd('terminal width 200');
|
| 83 |
my @output = $session->cmd('show ip bgp summary');
|
| 84 |
|
| 85 |
# example output of router |
| 86 |
# ------------------------ |
| 87 |
# [...] |
| 88 |
# Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd |
| 89 |
# 11.111.11.111 4 98765 12403694 509571 308911893 0 0 1d23h 329193 |
| 90 |
# 122.122.122.122 4 1234 13242856 383827 308911879 0 0 00:08:22 330761 |
| 91 |
|
| 92 |
foreach(@output) {
|
| 93 |
chomp; s/\r//g; |
| 94 |
$tot_pfx = $1 if /^BGP activity (\d+)\/(\d+) prefixes/; |
| 95 |
syslog('debug', "$hostname: $_\n");
|
| 96 |
|
| 97 |
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+)/; |
| 98 |
my ($neigh, $as, $pfx) = ($1, $2, $3); |
| 99 |
syslog('debug', "$neigh (AS $as)");
|
| 100 |
push @BGP_nbr, "$neigh (AS $as)"; |
| 101 |
push @BGP_pfx, $pfx; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
# vim:syntax=perl:ts=8 |
