=================================================================== RCS file: /cvs/nagios/check_openbgpd/check_openbgpd,v retrieving revision 1.4 retrieving revision 1.7 diff -u -r1.4 -r1.7 --- nagios/check_openbgpd/check_openbgpd 2009/11/19 21:22:01 1.4 +++ nagios/check_openbgpd/check_openbgpd 2015/03/25 03:19:28 1.7 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_openbgpd,v 1.3 2009/11/19 19:52:51 andrew Exp $ +# $RedRiver: check_openbgpd,v 1.4 2009/11/19 21:22:01 andrew Exp $ ######################################################################## # check_openbgpd *** A nagios check for OpenBSD bgpd # @@ -15,7 +15,7 @@ my $NAGIOS_OUTPUT = 1; my $LICENSE = <<'EOL'; -Copyright (c) 2009 Andrew Fresh +Copyright (c) 2009-2015 Andrew Fresh Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. @@ -56,7 +56,7 @@ exit $ERRORS{'OK'}; } -my @STATUS = read_status(); +my @STATUS = read_status( $CHECKS{_SOCKET} ); my %STATES = check_status( \@STATUS, \%CHECKS ); my $have_results = 0; @@ -89,12 +89,17 @@ exit $ERRORS{$state}; sub read_status { - my ($status) = @_; + my ($socket) = @_; my @S; + my @cmd = ($BGPCTL); + if ($socket) { + push @cmd, '-s', $socket; + } + push @cmd, 'show', 'summary'; + #open my $fh, '<', 'output' # XXX - open my $fh, '-|', $BGPCTL, 'show', 'summary' - or die "Couldn't open bgpctl: $!\n"; + open my $fh, '-|', @cmd or die "Couldn't open bgpctl: $!\n"; while (<$fh>) { chomp; push @S, parse_line($_); @@ -157,14 +162,14 @@ my ( $S, $C ) = @_; my %states; - my %neighbors = ( UNKNOWN => $C->{UNKNOWN} ); + my %neighbors = map { $_ => $C->{$_} } qw( _SOCKET _UNKNOWN ); STATE: foreach my $s ( @{$S} ) { my $n = $s->{neighbor}; $neighbors{$n} = $s; my $result; - if ( my $c = $C->{$n} || $C->{UNKNOWN} ) { + if ( my $c = $C->{$n} || $C->{_UNKNOWN} ) { CODE: foreach my $code ( 'CRITICAL', 'WARNING' ) { next CODE if ( ref $c->{$code} ne 'HASH' ); my $data = $s->{state}; @@ -215,7 +220,7 @@ return 'State (' . $d . ') is not numeric'; } - DIRECTION: foreach my $dir qw( low high ) { + DIRECTION: foreach my $dir (qw( low high )) { if ( !$c->{$dir} ) { next DIRECTION; } my $check = $c->{$dir}; @@ -260,14 +265,15 @@ my $opt = shift @argv; given ($opt) { when ( '-V' || '--version' ) { - print_revision( $PROGNAME, '$Revision: 1.4 $ ' ); + print_revision( $PROGNAME, '$Revision: 1.7 $ ' ); exit $ERRORS{'OK'} } when (/^-?-h(?:elp)?/xms) { print_help(); exit $ERRORS{'OK'} } + when (/^-?-s(?:ocket)?/xms) { $checks{_SOCKET} = shift @argv } when (/^-?-w(?:arning)?/xms) { $w = parse_check( shift @argv ) } when (/^-?-c(?:ritical)?/xms) { $c = parse_check( shift @argv ) } when (/^-?-u(?:nknown)?/xms) { - $checks{UNKNOWN} = { + $checks{_UNKNOWN} = { WARNING => $w, CRITICAL => $c, } @@ -289,9 +295,11 @@ sub print_help { print <<"EOL"; $PROGNAME - checks status of OpenBGPd peers - $PROGNAME [ -w ENTRY ][ -c ENTRY ]( -u | -n NEIGHBOR ) + $PROGNAME [ -s SOCKET ][ -w ENTRY ][ -c ENTRY ]( -u | -n NEIGHBOR ) Usage: + -s, --socket SOCKET + Path to bgpd socket to use. See -r in bgpd(8). -w, --warning RANGE or single ENTRY Exit with WARNING status if outside of RANGE or if != ENTRY May be entered multiple times. @@ -361,7 +369,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.4 $' ); + print_revision( $PROGNAME, '$Revision: 1.7 $' ); print $LICENSE;