check
changeset 8 ac086cd3c0f4
parent 7 2bda25a39ef4
equal deleted inserted replaced
5:52faa36ba7f8 8:ac086cd3c0f4
    34 
    34 
    35 $SIG{__DIE__} = sub { unknown @_ unless $^S };
    35 $SIG{__DIE__} = sub { unknown @_ unless $^S };
    36 
    36 
    37 exit main @ARGV;
    37 exit main @ARGV;
    38 
    38 
    39 
       
    40 #----
    39 #----
    41 
    40 
    42 sub main {
    41 sub main {
       
    42     my @opt_ignore;
    43     my $opt_verbose = 0;
    43     my $opt_verbose = 0;
    44 
    44 
    45     GetOptions(
    45     GetOptions(
    46         'h|help' => sub { pod2usage(-verbose => 1, -exit => 0) },
    46         'i|ignore=s@' => \@opt_ignore,
    47         'm|man'  => sub { pod2usage(-verbose => 2, -exit => 0) },
    47         'h|help'      => sub { pod2usage(-verbose => 1, -exit => 0) },
    48         'v|verbose' => \$opt_verbose,
    48         'm|man'       => sub { pod2usage(-verbose => 2, -exit => 0) },
       
    49         'v|verbose'   => \$opt_verbose,
    49     ) or pod2usage;
    50     ) or pod2usage;
    50 
    51 
    51     if ($opt_verbose) { *::verbose = sub { say '# ', @_ } }
    52     if ($opt_verbose) {
    52     else { *::verbose = sub { } }
    53         *::verbose = sub { say '# ', @_ }
    53 
    54     }
       
    55     else {
       
    56         *::verbose = sub { }
       
    57     }
    54 
    58 
    55     # test needs to be run as root:* or as backup:backup
    59     # test needs to be run as root:* or as backup:backup
    56     my $USER  = 'backup';
    60     my $USER  = 'backup';
    57     my $CFDIR = '/etc/amanda';
    61     my $CFDIR = '/etc/amanda';
    58 
    62 
    73     my @confs = sort +unique eval { config_names $CFDIR }
    77     my @confs = sort +unique eval { config_names $CFDIR }
    74       or unknown $@;
    78       or unknown $@;
    75 
    79 
    76     eval { amchecks @confs } or critical $@;
    80     eval { amchecks @confs } or critical $@;
    77 
    81 
    78     my @dles = eval { amlists @confs } or critical $@;
    82     my @dles = eval { amlists confs => \@confs, ignore => \@opt_ignore } or critical $@;
    79     ok 'config: ' .join(', ', @confs), @dles;
    83     ok 'config: ' . join(', ', @confs), @dles;
    80 
    84 
    81     # never reached
    85     # never reached
    82     return 0;
    86     return 0;
    83 }
    87 }
    84 
    88 
   208     chomp((undef, my @dles) = qx(amdump_client --config '$conf' list));
   212     chomp((undef, my @dles) = qx(amdump_client --config '$conf' list));
   209     return map { [$_, (stat $_)[1] == 2 ? (stat $_)[0] : -1] } @dles;
   213     return map { [$_, (stat $_)[1] == 2 ? (stat $_)[0] : -1] } @dles;
   210 }
   214 }
   211 
   215 
   212 sub amlists {
   216 sub amlists {
   213     my @confs      = @_;
   217     my %arg = @_;
       
   218     my @confs = @{$arg{confs}} or croak 'missing list of confs';
       
   219     my @ignore = @{$arg{ignore}};
       
   220 
   214     my @candidates = get_devices;
   221     my @candidates = get_devices;
   215 
   222 
   216     my %missing;
   223     my %missing;
   217 
   224 
   218     foreach my $conf (@confs) {
   225     foreach my $conf (@confs) {
   221 
   228 
   222             # we're satisfied if either the name of the device is in
   229             # we're satisfied if either the name of the device is in
   223             # the disklist, or the device id is found
   230             # the disklist, or the device id is found
   224             $candidate->[0] ~~ [map { $_->[0] } @dles] and next;
   231             $candidate->[0] ~~ [map { $_->[0] } @dles] and next;
   225             $candidate->[1] ~~ [map { $_->[1] } @dles] and next;
   232             $candidate->[1] ~~ [map { $_->[1] } @dles] and next;
   226             push @{ $missing{$conf} }, $candidate->[0];
   233             push @{ $missing{$conf} }, $candidate->[0]
       
   234                 if not "$conf:$candidate->[0]" ~~ @ignore;
   227         }
   235         }
   228     }
   236     }
   229     die map { "$_ missing: " . join(', ' => @{ $missing{$_} }) . "\n" }
   237     die map { "$_ missing: " . join(', ' => @{ $missing{$_} }) . "\n" }
   230       keys %missing
   238       keys %missing
   231       if %missing;
   239       if %missing;
   244  check_amanda-client - check the amanda backup from the client side
   252  check_amanda-client - check the amanda backup from the client side
   245 
   253 
   246 =head1 SYNOPSIS
   254 =head1 SYNOPSIS
   247 
   255 
   248   check_amanda-client [-h|--help] [-m|--man]
   256   check_amanda-client [-h|--help] [-m|--man]
       
   257   check_amanda-client [options]
   249 
   258 
   250 =head1 DESCRIPTION
   259 =head1 DESCRIPTION
   251 
   260 
   252 This nagios check plugin checks the Amanda setup from the client side.
   261 This nagios check plugin checks the Amanda setup from the client side.
   253 
   262 
   254 =head1 OPTIONS
   263 =head1 OPTIONS
   255 
   264 
   256 =over
   265 =over
       
   266 
       
   267 =item B<-i>|B<--ignore> I<config:filesystem>
       
   268 
       
   269 The name of a filesystem to be ignored. Example:
       
   270 
       
   271     check_amanda-client --ignore weekly:/var/spool/squid --ignore daily:/boot
   257 
   272 
   258 =item B<-h>|B<--help>
   273 =item B<-h>|B<--help>
   259 
   274 
   260 Show a short description and help text.
   275 Show a short description and help text.
   261 
   276