Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / router / cisco_bgp_ @ 5061ef1d

Historique | Voir | Annoter | Télécharger (2,6 ko)

1 90237822 Peter Holzleitner
#!/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 fc7eca20 P.Holzleitner
# Revision 1.1  2010/10/14 19:19
8 90237822 Peter Holzleitner
#
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 fc7eca20 P.Holzleitner
use Sys::Syslog;
25 90237822 Peter Holzleitner
26
27
if ($0 =~ /^(?:|.*\/)cisco_bgp_([^_]+)$/) {
28
    $host  = $1;
29
    }
30
31 fc7eca20 P.Holzleitner
($^O eq "linux" || $^O eq "openbsd") && Sys::Syslog::setlogsock('unix');
32
openlog('munin.bgp', 'cons,pid', 'daemon');
33 90237822 Peter Holzleitner
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 fc7eca20 P.Holzleitner
80 90237822 Peter Holzleitner
    $session->login($username, $password);
81 fc7eca20 P.Holzleitner
    $session->cmd('terminal length 200');
82
    $session->cmd('terminal width 200');
83 90237822 Peter Holzleitner
    my @output = $session->cmd('show ip bgp summary');
84
85 fc7eca20 P.Holzleitner
# 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 90237822 Peter Holzleitner
92
    foreach(@output) {
93 fc7eca20 P.Holzleitner
        chomp; s/\r//g;
94 90237822 Peter Holzleitner
	$tot_pfx = $1 if /^BGP activity (\d+)\/(\d+) prefixes/;
95 fc7eca20 P.Holzleitner
        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 90237822 Peter Holzleitner
	my ($neigh, $as, $pfx) = ($1, $2, $3);
99 fc7eca20 P.Holzleitner
        syslog('debug', "$neigh (AS $as)");
100 90237822 Peter Holzleitner
	push @BGP_nbr,  "$neigh (AS $as)";
101
	push @BGP_pfx,  $pfx;
102
	}
103
    }
104
105
106
# vim:syntax=perl:ts=8