check
changeset 2 7b9bad9c85e6
parent 1 1ea5da2535d7
child 3 71a0c4bd43b1
child 4 da08b2a30e06
equal deleted inserted replaced
1:1ea5da2535d7 2:7b9bad9c85e6
    14 sub su;
    14 sub su;
    15 sub find_tool;
    15 sub find_tool;
    16 sub check_perms;
    16 sub check_perms;
    17 sub config_names;
    17 sub config_names;
    18 sub get_devices;
    18 sub get_devices;
       
    19 
    19 sub amchecks;
    20 sub amchecks;
    20 sub amlists;
    21 sub amlists;
       
    22 
    21 sub main;
    23 sub main;
    22 
    24 
    23 my $NAME = 'AMANDA-CLIENT';
    25 my $NAME = 'AMANDA-CLIENT';
    24 
    26 
    25 sub ok;
    27 sub ok;
   143 	die "no configs found below $dir (amanda-client.conf needs need `conf \"foo\"' line)\n"
   145 	die "no configs found below $dir (amanda-client.conf needs need `conf \"foo\"' line)\n"
   144 		if not @configs;
   146 		if not @configs;
   145 	return @configs;
   147 	return @configs;
   146 };
   148 };
   147 
   149 
       
   150 sub _amcheck {
       
   151 	#config: daily
       
   152 	#CHECKING
       
   153 	#
       
   154 	#Amanda Backup Client Hosts Check
       
   155 	#--------------------------------
       
   156 	#Client check: 1 host checked in 2.242 seconds.  0 problems found.
       
   157 	#
       
   158 	#(brought to you by Amanda 3.3.1)
       
   159 	#The check is finished
       
   160 
       
   161 	my $conf = shift;
       
   162 	my $_ = qx(amdump_client --config '$conf' check 2>&1);
       
   163 	/^config:\s+$conf\n
       
   164 		 CHECKING\n
       
   165 		 .*\n
       
   166 		 Client.check:.1.host.checked.in.\d+\.\d+.seconds\.\s+0.problems.found\.\n
       
   167 		 .*\n
       
   168 		 The.check.is.finished$
       
   169 	/smx or die "unexpected output from check:\n$_";
       
   170 }
       
   171 
   148 sub amchecks {
   172 sub amchecks {
   149 	my @errors;
   173 	my @errors = ();
   150 	foreach my $conf (@_) {
   174 	foreach my $conf (@_) {
   151 		push @errors, map { "$conf: $_" } grep { /^error/i } qx(amdump_client --config '$conf' check 2>&1);
   175 		eval { _amcheck $conf } or push @errors, $@;
   152 	}
   176 	}
   153 	die join "\n", @errors if @errors;
   177 	die @errors if @errors;
   154 	return 1;
   178 	return 1;
   155 }
   179 }
   156 
   180 
   157 sub amlist {
   181 sub _amlist {
   158 	# return a list of [ name, dev ] tupels.
   182 	# return a list of [ name, dev ] tupels.
   159 	# name: the name of the disk/device
   183 	# name: the name of the disk/device
   160 	# dev:  the local device id (stat)[0]
   184 	# dev:  the local device id (stat)[0]
   161 	# iff the inum of $name != 2, it's not the top directory
   185 	# iff the inum of $name != 2, it's not the top directory
   162 	# and we set the device id to -1, since $name does not stand for a whole
   186 	# and we set the device id to -1, since $name does not stand for a whole
   171 	my @candidates = get_devices;
   195 	my @candidates = get_devices;
   172 
   196 
   173 	my %missing;
   197 	my %missing;
   174 
   198 
   175 	foreach my $conf (@confs) {
   199 	foreach my $conf (@confs) {
   176 		my @dles = amlist $conf;
   200 		my @dles = _amlist $conf;
   177 		foreach my $candidate (@candidates) {
   201 		foreach my $candidate (@candidates) {
   178 			# we're satisfied if either the name of the device is in
   202 			# we're satisfied if either the name of the device is in
   179 			# the disklist, or the device id is found
   203 			# the disklist, or the device id is found
   180 			$candidate->[0] ~~ [ map { $_->[0] } @dles ] and next;
   204 			$candidate->[0] ~~ [ map { $_->[0] } @dles ] and next;
   181 			$candidate->[1] ~~ [ map { $_->[1] } @dles ] and next;
   205 			$candidate->[1] ~~ [ map { $_->[1] } @dles ] and next;