Archived
1
0

Add some debug messages

This commit is contained in:
Mercier Pierre-Olivier 2013-09-03 08:07:02 +02:00
parent aa7efab83f
commit dd3445ca95
3 changed files with 24 additions and 8 deletions

View File

@ -128,7 +128,7 @@ sub get_dn($$@)
scope => "base" scope => "base"
); );
if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return undef; } if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return undef; }
if ($mesg->count != 1) { ACU::Log::do_warn("$cn not found or multiple entries match"); return undef; } if ($mesg->count != 1) { ACU::Log::do_warn("$dn not found or multiple entries match"); return undef; }
return $mesg->entry(0); return $mesg->entry(0);
} }
@ -145,7 +145,7 @@ sub add_attribute($$$@)
my @data = $entry->get_value($what); my @data = $entry->get_value($what);
for my $value (@_) for my $value (@_)
{ {
if (! grep(/^$value$/, @data)) { if (! grep("^$value\$", @data)) {
$mod = 1; $mod = 1;
ACU::Log::do_debug("Add attribute $value to $dn"); ACU::Log::do_debug("Add attribute $value to $dn");
@ -160,7 +160,7 @@ sub add_attribute($$$@)
my $mesg = $entry->update($ldap) or die $!; my $mesg = $entry->update($ldap) or die $!;
if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return 0; } if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return 0; }
if ($mesg->count != 1) { ACU::Log::do_warn("$cn not found or multiple entries match"); return 0; } if ($mesg->count != 1) { ACU::Log::do_warn("$dn not found or multiple entries match"); return 0; }
return 1; return 1;
} }
@ -181,12 +181,15 @@ sub delete_attribute($$$@)
my @data = $entry->get_value($what); my @data = $entry->get_value($what);
for my $value (@_) for my $value (@_)
{ {
if (grep(/^$value$/, @data)) { if (grep("^$value\$", @data)) {
ACU::Log::do_debug("Remove attribute $what ($value) from $dn"); ACU::Log::do_debug("Remove attribute $what ($value) from $dn");
@data = grep(!/$value$/, @data); @data = grep(!"^$value\$", @data);
$mod = 1; $mod = 1;
} }
else {
ACU::Log::do_warn("No attribute $what with value $value for $dn");
}
} }
if ($mod) if ($mod)
@ -217,7 +220,7 @@ sub flush_attribute($$@)
my $ldap = shift // ldap_connect(); my $ldap = shift // ldap_connect();
my $dn = shift; my $dn = shift;
$ldap->modify($dn, delete => \@_)->code; my $mesg = $ldap->modify($dn, delete => \@_)->code;
if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return 0; } if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return 0; }
@ -250,7 +253,7 @@ sub search_dn($$@)
scope => "sub" scope => "sub"
); );
if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return undef; } if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return undef; }
if ($mesg->count != 1) { ACU::Log::do_warn("$cn not found or multiple entries match"); return undef; } if ($mesg->count != 1) { ACU::Log::do_warn("$filter not found or multiple entries match"); return undef; }
return $mesg->entry(0)->dn; return $mesg->entry(0)->dn;
} }

View File

@ -6,9 +6,10 @@ use v5.10.1;
use strict; use strict;
use warnings; use warnings;
use Term::ANSIColor qw(:constants); use Term::ANSIColor qw(:constants);
use Data::Dumper;
our $verbosity = 1; our $verbosity = 1;
our $debug = 0; our $debug = 1;
sub do_err(@) sub do_err(@)
{ {
@ -40,4 +41,11 @@ sub do_debug(@)
} }
} }
sub do_dump(@)
{
if ($debug) {
print Dumper(@_);
}
}
1; 1;

View File

@ -12,6 +12,8 @@ use XML::SAX::ParserFactory;
use List::Util "reduce"; use List::Util "reduce";
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
use ACU::Log;
use constant COEFF_OLD => 25; use constant COEFF_OLD => 25;
use constant WAITING_LOAD => 2; use constant WAITING_LOAD => 2;
@ -39,6 +41,9 @@ sub do_work ($$$@)
my $given_args = shift; my $given_args = shift;
my $priority = shift; my $priority = shift;
ACU::Log::do_debug("Starting job");
ACU::Log::do_dump($_[0]);
my $old = 0; my $old = 0;
# Check the load isn't to high for this process # Check the load isn't to high for this process
sleep WAITING_LOAD while ! check_load ($priority + (++$old / COEFF_OLD)); sleep WAITING_LOAD while ! check_load ($priority + (++$old / COEFF_OLD));