-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_bgp.pl
67 lines (52 loc) · 1.03 KB
/
check_bgp.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl -w
#
#
#
use strict;
my @bgp_vtysh = ();
my @bgp6_vtysh = ();
my $EXIT_FLAG = 0;
my ($nei, $state, $state_check, $HOST);
my $sudo = '';
my $vtysh = '';
if ($^O =~ m/linux/i) {
$sudo = '/usr/bin/sudo';
$vtysh = '/usr/bin/vtysh';
}
elsif ($^O =~ m/freebsd/i) {
$sudo = '/usr/local/bin/sudo';
$vtysh = '/usr/local/bin/vtysh';
}
if (! $sudo or ! $vtysh) {
$EXIT_FLAG++;
}
@bgp_vtysh = `$sudo $vtysh -c 'sh ip bgp summary'`;
@bgp6_vtysh = `$sudo $vtysh -c 'sh ipv6 bgp summary'`;
if (! @bgp_vtysh) {
$EXIT_FLAG++;
}
foreach (@bgp_vtysh) {
chomp;
if ($_ =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.+\s+(\D+)$/i) {
$EXIT_FLAG++;
} else {
next;
}
}
my $flag = 0;
foreach (@bgp6_vtysh) {
chomp;
if ($_ =~ m/^[a-f0-9\:]+$/i) {
$flag = 1;
}
elsif ($flag == 1 and m/.+(\D+)$/) {
$flag = 0;
$EXIT_FLAG++;
} elsif ($flag == 0 and $_ =~ m/^[a-f0-9\:]+\s+4.+(\D+)$/) {
$EXIT_FLAG++;
} else {
$flag = 0;
next;
}
}
print "$EXIT_FLAG\n";