[BACK]Return to check_pf_limits CVS log [TXT][DIR] Up to [local] / nagios / check_pf_limits

Diff for /nagios/check_pf_limits/check_pf_limits between version 1.2 and 1.5

version 1.2, 2010/01/14 22:37:40 version 1.5, 2024/06/09 23:44:59
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 # $AFresh1: check_pf_limits,v 1.1 2010/01/14 22:21:34 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
 #  #
Line 155 
Line 155 
     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+
Line 167 
Line 167 
                 $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;
Line 178 
Line 178 
                 rate  => $rate,                  rate  => $rate,
             };              };
         }          }
         default {return}          else {return}
     }      }
   
     return 1;      return 1;
Line 193 
Line 193 
 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 => [] );
Line 250 
Line 254 
     );      );
   
     my %states;      my %states;
       my $status = $S->{info}{Status};
       if (0 == index $status, 'Enabled') {
           push @{ $states{OK} }, $status;
       }
       else {
           push @{ $states{CRITICAL} }, $status;
       }
   
   
     my %matched;      my %matched;
 STATE: foreach my $k ( keys %known_limits ) {  STATE: foreach my $k ( keys %known_limits ) {
         $matched{$k} = 1;          $matched{$k} = 1;
Line 303 
Line 316 
             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};
Line 345 
Line 358 
   
     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'} }
     }      }
   
     $checks{_UNKNOWN} = {      if (defined $w) {
         WARNING  => $w,          $checks{_UNKNOWN}{WARNING} = $w;
         CRITICAL => $c,      }
       if (defined $c) {
           $checks{_UNKNOWN}{CRITICAL} = $c;
     };      };
   
     return %checks;      return %checks;
 }  }
   
Line 414 
Line 432 
   
 Any known limits that are unspecified are checked with the last specified  Any known limits that are unspecified are checked with the last specified
 warning and criticical ENTRY.  warning and criticical ENTRY.
   
   Also checks if pf is enabled and is CRITICAL if not.
   
 Example:  Example:
   

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>