This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
forked from stephank/nagios-bird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_bird_proto.pl
executable file
·71 lines (62 loc) · 2.08 KB
/
check_bird_proto.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
68
69
70
71
#!/usr/bin/perl -w
use strict;
use warnings;
use Monitoring::Plugin;
use birdctl;
my $np = Monitoring::Plugin->new(
plugin => "check_bird_proto", shortname => "BIRD_PROTO", version => "0.1",
usage => "Usage: %s -p <protocol> [ -r <table> -z -s <socket> ]",
);
$np->add_arg(
spec => "protocol|p=s",
help => "The name of the protocol to monitor.",
required => 1,
);
$np->add_arg(
spec => "table|r=s",
help => "The table to search for routes.",
default => "master",
);
$np->add_arg(
spec => "zero|z",
help => "Whether zero routes is an error.",
);
$np->add_arg(
spec => "socket|s=s",
help => "The location of the BIRD control socket.",
default => "/var/run/bird.ctl",
);
$np->getopts;
# Handle timeouts (also triggers on invalid command)
$SIG{ALRM} = sub { $np->nagios_exit(CRITICAL, "Timeout (possibly invalid command)") };
alarm $np->opts->timeout;
eval q{
my $bird = new birdctl(socket => $np->opts->socket, restrict => 1);
# Get protocol information
my @status;
foreach ($bird->long_cmd("show protocols " . $np->opts->protocol)) {
# Find the first 1002 line.
/^1002-/ and @status = split(/\s+/, substr($_, 5)) and last;
# Fall through: no information found, print closing line.
/^\d{4} / and $np->nagios_exit(CRITICAL, $_);
}
# Check status
if ($status[3] ne "up") {
if ($status[5]) {
$np->nagios_exit(CRITICAL, "Protocol $status[0] is $status[3] - info: $status[5]");
}
else {
$np->nagios_exit(CRITICAL, "Protocol $status[0] is $status[3] - info: Protocol Down");
}
}
# Inspect routes imported from this protocol
my $search_string = '^[0-1][0-9][0-9][0-9][- ]?(\d+) of (\d+) routes for \d+ networks[ in table '.$np->opts->table.']*';
my $route_count = $bird->cmd("show route table " . $np->opts->table . " protocol " . $np->opts->protocol . " count");
$route_count =~ $search_string or $np->nagios_exit(CRITICAL, $_);
# Final status
$np->nagios_exit(
$np->opts->zero && $1 eq "0" ? CRITICAL : OK,
"Protocol $status[0] is $status[3] - $1 routes imported ($2 total)."
);
};
if ($@) { $np->nagios_exit(CRITICAL, $@); }