plugins/check_amanda-client
changeset 45 fe9aec849ab3
parent 44 8d2c3b246651
child 61 c037c0bdd01a
equal deleted inserted replaced
44:8d2c3b246651 45:fe9aec849ab3
    10 use Data::Dumper;
    10 use Data::Dumper;
    11 use File::Find;
    11 use File::Find;
    12 use Carp;
    12 use Carp;
    13 use Pod::Usage;
    13 use Pod::Usage;
    14 use Const::Fast;
    14 use Const::Fast;
       
    15 use if $ENV{DEBUG} => 'Smart::Comments';
    15 
    16 
    16 const my $NAME  => 'AMANDA-CLIENT';
    17 const my $NAME  => 'AMANDA-CLIENT';
    17 const my $USER  => 'backup';
    18 const my $USER  => 'backup';
    18 const my $CFDIR => '/etc/amanda';
    19 const my $CFDIR => '/etc/amanda';
    19 
    20 
    31 sub OK;
    32 sub OK;
    32 sub WARNING;
    33 sub WARNING;
    33 sub CRITICAL;
    34 sub CRITICAL;
    34 sub UNKNOWN;
    35 sub UNKNOWN;
    35 sub verbose;
    36 sub verbose;
    36 sub unique { my %h; @h{@_} = (); keys %h }
    37 sub unique { my %h; @h{@_} = (); return keys %h }
    37 
    38 
    38 local $SIG{__DIE__} = sub { UNKNOWN @_ unless $^S };
    39 local $SIG{__DIE__} = sub { UNKNOWN @_ unless $^S };
    39 
    40 
    40 # this we need for testing only, if this file gets
    41 # this we need for testing only, if this file gets
    41 # included as a module
    42 # included as a module
   153         my $msg =
   154         my $msg =
   154           sprintf "need: 0%04o root:%s, got: 0%04o %s:%s\n",
   155           sprintf "need: 0%04o root:%s, got: 0%04o %s:%s\n",
   155 				$mode, $group, $f_mode, $f_owner, $f_group;
   156 				$mode, $group, $f_mode, $f_owner, $f_group;
   156 
   157 
   157 		if (-f '/etc/debian_version') {
   158 		if (-f '/etc/debian_version') {
   158 			$msg .= sprintf  "try dpkg-statoverride --update --add root %s 0%04o %s\n",
   159 			$msg .= sprintf  "try dpkg-statoverride --update --add root %sgroup 0%04o %s\n",
   159 			  $group, $mode, $file;
   160 			  $group, $mode, $file;
   160 		}
   161 		}
   161 
   162 
   162         die $msg unless $f_owner eq $owner;
   163         die $msg unless $f_owner eq $owner;
   163         die $msg unless $f_group eq $group;
   164         die $msg unless $f_group eq $group;
   237 }
   238 }
   238 
   239 
   239 sub compare_lists {
   240 sub compare_lists {
   240     my %arg     = @_;
   241     my %arg     = @_;
   241     my @confs   = @{ $arg{confs} } or croak 'missing list of confs';
   242     my @confs   = @{ $arg{confs} } or croak 'missing list of confs';
   242     my @exclude = @{ $arg{exclude} };
   243 
       
   244     # magic: if there is no config with the exclude, generate a list of config:exclude
       
   245     my @exclude = map { /^[^\/]+?:/ ? $_ : do { my $x = $_; map { "$_:$x" } @confs } }  
       
   246 		  @{ $arg{exclude} };
       
   247     ### exclude:@exclude
   243 
   248 
   244     WARNING
   249     WARNING
   245       "excluded filesystem(s) @$_ does not exist, update the config please!\n"
   250       "excluded filesystem(s) @$_ does not exist, update the config please!\n"
   246       if @exclude
   251       if @exclude
   247           and @$_ = grep { not -e } unique map { /^.*?:(.*)/ } @exclude;
   252           and @$_ = grep { not -e } unique map { /^.*?:(.*)/ } @exclude;
   248 
   253 
   249     my @candidates = get_devices;
   254     my @candidates = get_devices;
   250     my %missing;
   255     my %missing;
   251 
   256 
       
   257     ### Candidates: @candidates
   252     foreach my $conf (@confs) {
   258     foreach my $conf (@confs) {
   253         my @dles = _amlist $conf;
   259         my @dles = _amlist $conf;
       
   260 	### DLEs: @dles
       
   261 
   254         foreach my $candidate (@candidates) {
   262         foreach my $candidate (@candidates) {
   255             next if not $candidate =~ m{^/|\Q$conf\E:};
   263             ### $candidate
       
   264             #next if not $candidate =~ m{^/|\Q$conf\E:};
   256 
   265 
   257             # we're satisfied if either the name of the device is in
   266             # we're satisfied if either the name of the device is in
   258             # the disklist, or the device id is found
   267             # the disklist, or the device id is found
   259             $candidate->[0] ~~ [map { $_->[0] } @dles] and next;
   268             $candidate->[0] ~~ [map { $_->[0] } @dles] and next;
   260             $candidate->[1] ~~ [map { $_->[1] } @dles] and next;
   269             $candidate->[1] ~~ [map { $_->[1] } @dles] and next;