version 1.1, 2009/11/13 02:05:20 |
version 1.2, 2009/11/13 22:23:24 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $RedRiver$ |
# $RedRiver: check_openbgpd,v 1.1 2009/11/13 02:05:20 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_openbgpd *** A nagios check for OpenBSD bgpd |
# check_openbgpd *** A nagios check for OpenBSD bgpd |
# |
# |
|
|
|
|
local %ENV = (); |
local %ENV = (); |
|
|
my $NAGIOS_OUTPUT = 0; |
my $NAGIOS_OUTPUT = 1; |
|
|
my $LICENSE = <<'EOL'; |
my $LICENSE = <<'EOL'; |
Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com> |
Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com> |
|
|
my %STATES = check_status( \@STATUS, \%CHECKS ); |
my %STATES = check_status( \@STATUS, \%CHECKS ); |
|
|
my $have_results = 0; |
my $have_results = 0; |
my $state = 'OK'; |
my $state = 'OK'; |
foreach |
foreach |
my $error ( reverse sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS ) |
my $error ( reverse sort { $ERRORS{$a} <=> $ERRORS{$b} } keys %ERRORS ) |
{ |
{ |
|
|
my @S; |
my @S; |
|
|
#open my $fh, '<', 'output' # XXX |
#open my $fh, '<', 'output' # XXX |
open my $fh , '-|', $BGPCTL, 'show', 'summary' |
open my $fh, '-|', $BGPCTL, 'show', 'summary' |
or die "Couldn't open bgpctl: $!\n"; |
or die "Couldn't open bgpctl: $!\n"; |
while (<$fh>) { |
while (<$fh>) { |
chomp; |
chomp; |
|
|
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 ( /^-?-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, |
|
|
|
|
sub print_help { |
sub print_help { |
print <<"EOL"; |
print <<"EOL"; |
$PROGNAME - monitors sysctl hw.bgpstatus on OpenBSD |
$PROGNAME - checks status of OpenBGPd peers |
$PROGNAME [ -w ENTRY ][ -c ENTRY ][ -n NEIGHBOR [ NEIGHBOR2 ] ] |
$PROGNAME [ -w ENTRY ][ -c ENTRY ][ -n NEIGHBOR [ NEIGHBOR2 ] ] |
|
|
Usage: |
Usage: |
|
|
NEIGHBOR is the name that shows when running "bgpctl show summary" |
NEIGHBOR is the name that shows when running "bgpctl show summary" |
|
|
Examples: |
Examples: |
|
(where many of the numbers would probably have to be multiplied by 1000) |
|
|
$PROGNAME -w 10000:300000 -c 1000:500000 -n eBGP1 eBGP2 -n eBGP3 |
Any time a NEIGHBOR is specified on the command line but does NOT show up in |
|
the output causes a CRITICAL result. |
|
|
Checks that peers eBGP1, eBGP2 and eBGP2 are within the ranges specified |
Any time a NEIGHBOR that is NOT specified on the command line shows up in the |
|
output causes a CRITICAL result. |
|
|
$PROGNAME -c 1:1 -n eBGP1 -w 200000:300000 -c 100: -n iBGP1 |
|
|
|
Checks that 1 and only 1 prefix is received from from eBGP1, warns if less |
$PROGNAME -w 10:300 -c 10:500 -n P1 P2 -n P3 |
than 200000 or more than 300000 prefixes are recieved from peer iBGP1 and is |
|
critical if less than 100 prefixes are recieved from peer iBGP1 |
|
|
|
$PROGNAME -c Idle -n iBGP1 -w |
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 |
|
|
|
CRITICAL |
|
If P1 is any value but Idle. |
|
If P2 is any value but 1. |
|
If P3 is below 10 or any non-numeric value other than "Active". |
|
|
|
WARNING |
|
If P3 is above 10 and below 200 or above 300. |
|
|
EOL |
EOL |
|
|