version 1.3, 2009/11/19 19:52:51 |
version 1.4, 2009/11/19 21:22:01 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver: check_openbgpd,v 1.2 2009/11/13 22:23:24 andrew Exp $ |
# $RedRiver: check_openbgpd,v 1.3 2009/11/19 19:52:51 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_openbgpd *** A nagios check for OpenBSD bgpd |
# check_openbgpd *** A nagios check for OpenBSD bgpd |
# |
# |
|
|
my ( $S, $C ) = @_; |
my ( $S, $C ) = @_; |
|
|
my %states; |
my %states; |
my %neighbors; |
my %neighbors = ( UNKNOWN => $C->{UNKNOWN} ); |
STATE: foreach my $s ( @{$S} ) { |
STATE: foreach my $s ( @{$S} ) { |
my $n = $s->{neighbor}; |
my $n = $s->{neighbor}; |
$neighbors{$n} = $s; |
$neighbors{$n} = $s; |
|
|
my $result; |
my $result; |
|
|
if ( my $c = $C->{$n} ) { |
if ( my $c = $C->{$n} || $C->{UNKNOWN} ) { |
CODE: foreach my $code ( 'CRITICAL', 'WARNING' ) { |
CODE: foreach my $code ( 'CRITICAL', 'WARNING' ) { |
next CODE if ( ref $c->{$code} ne 'HASH' ); |
next CODE if ( ref $c->{$code} ne 'HASH' ); |
my $data = $s->{state}; |
my $data = $s->{state}; |
|
|
print_revision( $PROGNAME, '$Revision$ ' ); |
print_revision( $PROGNAME, '$Revision$ ' ); |
exit $ERRORS{'OK'} |
exit $ERRORS{'OK'} |
} |
} |
when (/^-?-h(?:elp)?/xms) { print_help(); exit $ERRORS{'OK'} } |
when (/^-?-h(?:elp)?/xms) { print_help(); exit $ERRORS{'OK'} } |
when (/^-?-w(?:arning)?/xms) { $w = parse_check( shift @argv ) } |
when (/^-?-w(?:arning)?/xms) { $w = parse_check( shift @argv ) } |
when (/^-?-c(?:ritical)?/xms) { $c = parse_check( shift @argv ) } |
when (/^-?-c(?:ritical)?/xms) { $c = parse_check( shift @argv ) } |
|
when (/^-?-u(?:nknown)?/xms) { |
|
$checks{UNKNOWN} = { |
|
WARNING => $w, |
|
CRITICAL => $c, |
|
} |
|
} |
when (/^-?-n(?:eighbor)?/xms) { |
when (/^-?-n(?:eighbor)?/xms) { |
while ( @argv && $argv[0] !~ /^-/xms ) { |
while ( @argv && $argv[0] !~ /^-/xms ) { |
$checks{ shift @argv } = { |
$checks{ shift @argv } = { |
WARNING => $w, |
WARNING => $w, |
CRITICAL => $c |
CRITICAL => $c, |
} |
} |
} |
} |
} |
} |
|
|
sub print_help { |
sub print_help { |
print <<"EOL"; |
print <<"EOL"; |
$PROGNAME - checks status of OpenBGPd peers |
$PROGNAME - checks status of OpenBGPd peers |
$PROGNAME [ -w ENTRY ][ -c ENTRY ][ -n NEIGHBOR [ NEIGHBOR2 ] ] |
$PROGNAME [ -w ENTRY ][ -c ENTRY ]( -u | -n NEIGHBOR ) |
|
|
Usage: |
Usage: |
-w, --warning RANGE or single ENTRY |
-w, --warning RANGE or single ENTRY |
Exit with WARNING status if outside of RANGE or if != ENTRY |
Exit with WARNING status if outside of RANGE or if != ENTRY |
|
May be entered multiple times. |
-c, --critical RANGE or single ENTRY |
-c, --critical RANGE or single ENTRY |
Exit with CRITICAL status if outside of RANGE or if != ENTRY |
Exit with CRITICAL status if outside of RANGE or if != ENTRY |
|
May be entered multiple times. |
-n, --neighbor NEIGHBOR |
-n, --neighbor NEIGHBOR |
The name of the Neighbor |
The name of the Neighbor, can be a space separated list of neighbors. |
|
May be entered multiple times. |
|
-u, --unknown |
|
As if you specified -n for all unknown neighbors |
|
|
ENTRY is a comma separated list of items to match against. Each item can be |
ENTRY is a comma separated list of items to match against. Each item can be |
a RANGE or it will just be matched against the status. |
a RANGE or it will just be matched against the status. |
|
|
the output causes a CRITICAL result. |
the output causes a CRITICAL result. |
|
|
Any time a NEIGHBOR that is NOT specified on the command line shows up in the |
Any time a NEIGHBOR that is NOT specified on the command line shows up in the |
output causes a CRITICAL result. |
output causes a CRITICAL result. If -u is specified, it treats NEIGHBOR as if |
|
it were specified at that position. |
|
|
|
|
$PROGNAME -w 10:300 -c 10:500 -n P1 P2 -n P3 |
|
|
|
CRITICAL |
|
If any of P1, P2, P3 are below 10, above 500 or any non-numeric value. |
|
|
|
WARNING |
|
If any of P1, P2, P3 are above 300. |
|
|
|
|
|
$PROGNAME -c Idle -n P1 -c 1:1 -n P2 -w 200:300 -c Active,10: -n P3 |
$PROGNAME -c Idle -n P1 -c 1:1 -n P2 -w 200:300 -c Active,10: -n P3 |
|
|
CRITICAL |
CRITICAL |
|
|
If P3 is above 10 and below 200 or above 300. |
If P3 is above 10 and below 200 or above 300. |
|
|
|
|
$PROGNAME -n P1 -w 50%:70% -c 10%:90% -n P2 P3 |
$PROGNAME -u -w 50%:70% -c 10%:90% -n P2 P3 |
|
|
No checks on P1 |
No checks of unknown neighbors. |
|
|
CRITICAL |
CRITICAL |
If P2 or P3 do not have max-prefix set or if they do but learned prefixes |
If P2 or P3 do not have max-prefix set or if they do but learned prefixes |
are below 10% or above 90% of max-prefix. |
are below 10% or above 90% of max-prefix or any non-numeric value. |
|
|
WARNING |
WARNING |
If P2 or P3 have learned prefixes below 50% or above 90% of max-prefix. |
If P2 or P3 have learned prefixes below 50% or above 70% of max-prefix. |
|
|
|
|
|
$PROGNAME -w 50%:70% -c 10%:90% -u |
|
|
|
CRITICAL |
|
If any neighbor does not have max-prefix set or if they do but learned |
|
prefixes are below 10% or above 90% of max-prefix or any non-numeric value. |
|
|
|
WARNING |
|
If any neighbor have learned prefixes below 50% or above 70% of max-prefix. |
|
|
EOL |
EOL |
|
|