=================================================================== RCS file: /cvs/nagios/check_openbgpd/check_openbgpd,v retrieving revision 1.5 retrieving revision 1.13 diff -u -r1.5 -r1.13 --- nagios/check_openbgpd/check_openbgpd 2009/11/19 21:35:32 1.5 +++ nagios/check_openbgpd/check_openbgpd 2024/06/10 00:09:20 1.13 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -# $RedRiver: check_openbgpd,v 1.4 2009/11/19 21:22:01 andrew Exp $ +# $AFresh1: check_openbgpd,v 1.12 2024/06/09 23:02:37 afresh1 Exp $ ######################################################################## # check_openbgpd *** A nagios check for OpenBSD bgpd # @@ -9,13 +9,14 @@ use warnings; use 5.010; +use if $] >= 5.016, experimental => 'switch'; local %ENV = (); my $NAGIOS_OUTPUT = 1; my $LICENSE = <<'EOL'; -Copyright (c) 2009 Andrew Fresh +Copyright (c) 2009-2024 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. @@ -98,7 +99,7 @@ } push @cmd, 'show', 'summary'; - #open my $fh, '<', 'output' # XXX + #open my $fh, '<', 'output' or die $!; # XXX open my $fh, '-|', @cmd or die "Couldn't open bgpctl: $!\n"; while (<$fh>) { chomp; @@ -133,7 +134,11 @@ sub parse_check { my $check = shift; - return { match => [] } unless $check; + unless ($check) { + print_help(); + exit $ERRORS{'OK'} + } + my @values = split /,\s*/xms, $check; my %c = ( match => [] ); @@ -220,7 +225,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}; @@ -263,30 +268,33 @@ state( $w, $c ); my $opt = shift @argv; - given ($opt) { - when ( '-V' || '--version' ) { - print_revision( $PROGNAME, '$Revision: 1.5 $ ' ); + for ($opt) { + if ( $_ eq '-V' || $_ eq '--version' ) { + print_revision( $PROGNAME, '$Revision: 1.13 $ ' ); 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) { + elsif (/^-?-h(?:elp)?\Z/xms) { print_help(); exit $ERRORS{'OK'} } + elsif (/^-?-s(?:ocket)?\Z/xms) { + $checks{_SOCKET} = 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 (/^-?-u(?:nknown)?\Z/xms) { $checks{_UNKNOWN} = { - WARNING => $w, - CRITICAL => $c, - } + WARNING => $w, + CRITICAL => $c, + }; } - when (/^-?-n(?:eighbor)?/xms) { + elsif (/^-?-n(?:eighbor)?\Z/xms) { while ( @argv && $argv[0] !~ /^-/xms ) { $checks{ shift @argv } = { - WARNING => $w, - CRITICAL => $c, - } + WARNING => $w, + CRITICAL => $c, + }; } } - default { print_help(); exit $ERRORS{'UNKNOWN'} } + else { print_help(); exit $ERRORS{'UNKNOWN'} } } } return %checks; @@ -369,7 +377,7 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.5 $' ); + print_revision( $PROGNAME, '$Revision: 1.13 $' ); print $LICENSE;