=================================================================== RCS file: /cvs/nagios/check_pf_limits/check_pf_limits,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- nagios/check_pf_limits/check_pf_limits 2010/01/14 22:57:15 1.4 +++ nagios/check_pf_limits/check_pf_limits 2024/06/09 23:44:59 1.5 @@ -1,5 +1,5 @@ #!/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 # @@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. EOL -our ($VERSION) = '$Revision: 1.4 $' =~ m{ \$Revision: \s+ (\S+) }xms; +our ($VERSION) = '$Revision: 1.5 $' =~ m{ \$Revision: \s+ (\S+) }xms; my $PROGNAME = 'check_pf_limits'; my $PFCTL = '/sbin/pfctl'; @@ -155,8 +155,8 @@ state $section = 'Unknown'; chomp $line; - given ($line) { - when (/^\w+:/xms) { + for ($line) { + if (/^\w+:/xms) { while ( $line =~ s{ \s* (\w+): \s+ @@ -167,8 +167,8 @@ $result->{$1} = $2; } } - when (/^\S/xms) { ($section) = unpack 'A27', $line } - when (/^\s\s/xms) { + elsif (/^\S/xms) { ($section) = unpack 'A27', $line } + elsif (/^\s\s/xms) { my ( $name, $total, $rate ) = unpack 'x2 A25 x A14 A*'; foreach ( $total, $rate ) { s/^\s+//xms; @@ -178,7 +178,7 @@ rate => $rate, }; } - default {return} + else {return} } return 1; @@ -193,7 +193,11 @@ sub parse_check { my $check = shift; - return { match => [] } if !$check; + if (!$check) { + print_help(); + exit $ERRORS{'OK'}; + }; + my @values = split /,\s*/xms, $check; my %c = ( match => [] ); @@ -312,7 +316,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}; @@ -354,30 +358,32 @@ my ( %checks, $w, $c ); while (@argv) { - my $opt = shift @argv; - given ($opt) { - when ( '-V' || '--version' ) { - print_revision( $PROGNAME, '$Revision: 1.4 $ ' ); - exit $ERRORS{'OK'} - } - when (/^-?-h(?:elp)?/xms) { print_help(); exit $ERRORS{'OK'} } - when (/^-?-p(?:ath)?/xms) { $checks{_DEVICE} = shift @argv } - when (/^-?-w(?:arning)?/xms) { - $w = parse_check( shift @argv ) - } - when (/^-?-c(?:ritical)?/xms) { - $c = parse_check( shift @argv ) - } - when (/^-?-l(?:limit)?/xms) { - while ( @argv && $argv[0] !~ /^-/xms ) { - $checks{ shift @argv } = { - WARNING => $w, - CRITICAL => $c, - } + local $_ = shift @argv; + + if ( $_ eq '-V' || $_ eq '--version' ) { + print_revision( $PROGNAME, '$Revision: 1.5 $ ' ); + exit $ERRORS{'OK'} + } + elsif (/^-?-h(?:elp)?\Z/xms) { print_help(); exit $ERRORS{'OK'} } + elsif (/^-?-p(?:ath)?\Z/xms) { + $checks{_DEVICE} = shift @argv + || do { print_help(); exit $ERRORS{'OK'} }; + } + elsif (/^-?-w(?:arning)?\Z/xms) { + $w = parse_check( shift @argv ) + } + elsif (/^-?-c(?:ritical)?\Z/xms) { + $c = parse_check( shift @argv ) + } + elsif (/^-?-l(?:limit)?\Z/xms) { + 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) { @@ -441,7 +447,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.4 $' ); + print_revision( $PROGNAME, '$Revision: 1.5 $' ); print $LICENSE;