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

Diff for /nagios/check_openbgpd/check_openbgpd between version 1.4 and 1.7

version 1.4, 2009/11/19 21:22:01 version 1.7, 2015/03/25 03:19:28
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/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  # check_openbgpd *** A nagios check for OpenBSD bgpd
 #  #
Line 15 
Line 15 
 my $NAGIOS_OUTPUT = 1;  my $NAGIOS_OUTPUT = 1;
   
 my $LICENSE = <<'EOL';  my $LICENSE = <<'EOL';
 Copyright (c) 2009 Andrew Fresh <andrew@afresh1.com>  Copyright (c) 2009-2015 Andrew Fresh <andrew@afresh1.com>
 Permission to use, copy, modify, and distribute this software for any  Permission to use, copy, modify, and distribute this software for any
 purpose with or without fee is hereby granted, provided that the above  purpose with or without fee is hereby granted, provided that the above
 copyright notice and this permission notice appear in all copies.  copyright notice and this permission notice appear in all copies.
Line 56 
Line 56 
     exit $ERRORS{'OK'};      exit $ERRORS{'OK'};
 }  }
   
 my @STATUS = read_status();  my @STATUS = read_status( $CHECKS{_SOCKET} );
 my %STATES = check_status( \@STATUS, \%CHECKS );  my %STATES = check_status( \@STATUS, \%CHECKS );
   
 my $have_results = 0;  my $have_results = 0;
Line 89 
Line 89 
 exit $ERRORS{$state};  exit $ERRORS{$state};
   
 sub read_status {  sub read_status {
     my ($status) = @_;      my ($socket) = @_;
     my @S;      my @S;
   
       my @cmd = ($BGPCTL);
       if ($socket) {
           push @cmd, '-s', $socket;
       }
       push @cmd, 'show', 'summary';
   
     #open my $fh, '<', 'output'    # XXX      #open my $fh, '<', 'output'    # XXX
     open my $fh, '-|', $BGPCTL, 'show', 'summary'      open my $fh, '-|', @cmd or die "Couldn't open bgpctl: $!\n";
         or die "Couldn't open bgpctl: $!\n";  
     while (<$fh>) {      while (<$fh>) {
         chomp;          chomp;
         push @S, parse_line($_);          push @S, parse_line($_);
Line 157 
Line 162 
     my ( $S, $C ) = @_;      my ( $S, $C ) = @_;
   
     my %states;      my %states;
     my %neighbors = ( UNKNOWN => $C->{UNKNOWN} );      my %neighbors = map { $_ => $C->{$_} } qw( _SOCKET _UNKNOWN );
 STATE: foreach my $s ( @{$S} ) {  STATE: foreach my $s ( @{$S} ) {
         my $n = $s->{neighbor};          my $n = $s->{neighbor};
         $neighbors{$n} = $s;          $neighbors{$n} = $s;
   
         my $result;          my $result;
   
         if ( my $c = $C->{$n} || $C->{UNKNOWN} ) {          if ( my $c = $C->{$n} || $C->{_UNKNOWN} ) {
         CODE: foreach my $code ( 'CRITICAL', 'WARNING' ) {          CODE: foreach my $code ( 'CRITICAL', 'WARNING' ) {
                 next CODE if ( ref $c->{$code} ne 'HASH' );                  next CODE if ( ref $c->{$code} ne 'HASH' );
                 my $data = $s->{state};                  my $data = $s->{state};
Line 215 
Line 220 
             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 264 
Line 269 
                 exit $ERRORS{'OK'}                  exit $ERRORS{'OK'}
             }              }
             when (/^-?-h(?:elp)?/xms) { print_help(); 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 (/^-?-w(?:arning)?/xms)  { $w = parse_check( shift @argv ) }
             when (/^-?-c(?:ritical)?/xms) { $c = parse_check( shift @argv ) }              when (/^-?-c(?:ritical)?/xms) { $c = parse_check( shift @argv ) }
             when (/^-?-u(?:nknown)?/xms) {              when (/^-?-u(?:nknown)?/xms) {
                 $checks{UNKNOWN} = {                  $checks{_UNKNOWN} = {
                     WARNING      => $w,                      WARNING      => $w,
                         CRITICAL => $c,                          CRITICAL => $c,
                 }                  }
Line 289 
Line 295 
 sub print_help {  sub print_help {
     print <<"EOL";      print <<"EOL";
 $PROGNAME - checks status of OpenBGPd peers  $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:  Usage:
       -s, --socket SOCKET
           Path to bgpd socket to use. See -r in bgpd(8).
     -w, --warning RANGE or single ENTRY      -w, --warning RANGE or single ENTRY
         Exit with WARNING status if outside of RANGE or if != ENTRY          Exit with WARNING status if outside of RANGE or if != ENTRY
         May be entered multiple times.          May be entered multiple times.

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.7

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