version 1.4, 2010/01/14 22:57:15 |
version 1.5, 2024/06/09 23:44:59 |
|
|
#!/usr/bin/perl -T |
#!/usr/bin/perl -T |
# $AFresh1: check_pf_limits,v 1.3 2010/01/14 22:42:12 andrew Exp $ |
# $AFresh1: check_pf_limits,v 1.4 2010/01/14 22:57:15 andrew Exp $ |
######################################################################## |
######################################################################## |
# check_openbgpd *** A nagios check for OpenBSD bgpd |
# check_openbgpd *** A nagios check for OpenBSD bgpd |
# |
# |
|
|
state $section = 'Unknown'; |
state $section = 'Unknown'; |
|
|
chomp $line; |
chomp $line; |
given ($line) { |
for ($line) { |
when (/^\w+:/xms) { |
if (/^\w+:/xms) { |
while ( |
while ( |
$line =~ s{ \s* |
$line =~ s{ \s* |
(\w+): \s+ |
(\w+): \s+ |
|
|
$result->{$1} = $2; |
$result->{$1} = $2; |
} |
} |
} |
} |
when (/^\S/xms) { ($section) = unpack 'A27', $line } |
elsif (/^\S/xms) { ($section) = unpack 'A27', $line } |
when (/^\s\s/xms) { |
elsif (/^\s\s/xms) { |
my ( $name, $total, $rate ) = unpack 'x2 A25 x A14 A*'; |
my ( $name, $total, $rate ) = unpack 'x2 A25 x A14 A*'; |
foreach ( $total, $rate ) { |
foreach ( $total, $rate ) { |
s/^\s+//xms; |
s/^\s+//xms; |
|
|
rate => $rate, |
rate => $rate, |
}; |
}; |
} |
} |
default {return} |
else {return} |
} |
} |
|
|
return 1; |
return 1; |
|
|
sub parse_check { |
sub parse_check { |
my $check = shift; |
my $check = shift; |
|
|
return { match => [] } if !$check; |
if (!$check) { |
|
print_help(); |
|
exit $ERRORS{'OK'}; |
|
}; |
|
|
my @values = split /,\s*/xms, $check; |
my @values = split /,\s*/xms, $check; |
|
|
my %c = ( match => [] ); |
my %c = ( match => [] ); |
|
|
return 'State (' . $d . ') is not numeric'; |
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; } |
if ( !$c->{$dir} ) { next DIRECTION; } |
|
|
my $check = $c->{$dir}; |
my $check = $c->{$dir}; |
|
|
|
|
my ( %checks, $w, $c ); |
my ( %checks, $w, $c ); |
while (@argv) { |
while (@argv) { |
my $opt = shift @argv; |
local $_ = shift @argv; |
given ($opt) { |
|
when ( '-V' || '--version' ) { |
if ( $_ eq '-V' || $_ eq '--version' ) { |
print_revision( $PROGNAME, '$Revision$ ' ); |
print_revision( $PROGNAME, '$Revision$ ' ); |
exit $ERRORS{'OK'} |
exit $ERRORS{'OK'} |
} |
} |
when (/^-?-h(?:elp)?/xms) { print_help(); exit $ERRORS{'OK'} } |
elsif (/^-?-h(?:elp)?\Z/xms) { print_help(); exit $ERRORS{'OK'} } |
when (/^-?-p(?:ath)?/xms) { $checks{_DEVICE} = shift @argv } |
elsif (/^-?-p(?:ath)?\Z/xms) { |
when (/^-?-w(?:arning)?/xms) { |
$checks{_DEVICE} = shift @argv |
$w = parse_check( shift @argv ) |
|| do { print_help(); exit $ERRORS{'OK'} }; |
} |
} |
when (/^-?-c(?:ritical)?/xms) { |
elsif (/^-?-w(?:arning)?\Z/xms) { |
$c = parse_check( shift @argv ) |
$w = parse_check( shift @argv ) |
} |
} |
when (/^-?-l(?:limit)?/xms) { |
elsif (/^-?-c(?:ritical)?\Z/xms) { |
while ( @argv && $argv[0] !~ /^-/xms ) { |
$c = parse_check( shift @argv ) |
$checks{ shift @argv } = { |
} |
WARNING => $w, |
elsif (/^-?-l(?:limit)?\Z/xms) { |
CRITICAL => $c, |
while ( @argv && $argv[0] !~ /^-/xms ) { |
} |
$checks{ shift @argv } = { |
|
WARNING => $w, |
|
CRITICAL => $c, |
} |
} |
} |
} |
default { print_help(); exit $ERRORS{'UNKNOWN'} } |
|
} |
} |
|
else { print_help(); exit $ERRORS{'UNKNOWN'} } |
} |
} |
|
|
if (defined $w) { |
if (defined $w) { |