Pour connaitre le niveau de replication de syncrepl , il faut interroger l'attribut 'contextCSN' du maitre et du replicat
Voici un exemple de programme qui réalise cette opération :
#! /usr/bin/perl
### by germanlinux
use strict;
use Date::Calc qw(Delta_DHMS);
use Net::LDAP ();
## mes fonctions
sub lookup_csn {
my ($ldap, $server_name) = @_;
my $search = $ldap->search(
scope => 'base',
base => $server_name->{base},
filter => "(objectclass=*)",
attrs => [ 'contextCSN' ]
);
$search->code() and do {
print STDERR "Error: failed to execute search on
$server_name->{host}: "
. $search->error() . " (" . $search->code() .
")\n";
exit(1);
};
my $entry = $search->shift_entry() or do {
print STDERR "Error: search on $server_name->{host} failed to find
entry\n";
exit(1);
};
my $csn = $entry->get_value('contextCSN');
if (!defined($csn)) {
print STDERR "Error: no contextCSN attribute found in
$server_name->{host} entry\n";
exit(1);
}
return $csn;
}
my $ldap_master = Net::LDAP->new($master->{host}, ) or do {
print STDERR "Error: failed to connect to LDAP master: $@";
exit(1);
};
my $ldap_replicat = Net::LDAP->new($replicat->{host},port => $replicat->{port},) or do {
print STDERR "Error: failed to connect to LDAP replicat: $@";
exit(1);
};
my $msg1 =$ldap_master->bind(dn =>$master->{dn} ,
password => $master->{password} ) ;
my $msg2 =$ldap_replicat->bind(dn =>$replicat->{dn} ,
password =>$replicat->{password} ) ;
my $master_csn = lookup_csn($ldap_master,$master);
my $replicat_csn = lookup_csn($ldap_replicat, $replicat);
if ($master_csn eq $replicat_csn )
{ print "0 - 0\n";
}
else {
my $master_csn_date=$master_csn;
my $replicat_csn_date =$replicat_csn;
$master_csn_date=~ s/Z.*//;
$replicat_csn_date =~s/Z.*//;
(my $y1,my $m1,my $d1,my $h1,my $mm1,my $s1) = $master_csn_date=~/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
(my $y2,my $m2,my $d2,my $h2,my $mm2,my $s2) = $replicat_csn_date=~/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
(my $dt,my $ht,my $mmt,my $st) = Delta_DHMS (
$y2,$m2,$d2, $h2, $mm2,$s2,
$y1,$m1,$d1, $h1, $mm1,$s1,
);
print "$master_csn_date - $replicat_csn_date\n";
my $deltamin = ($ht * 60) + $mmt ;
print "$dt - $ht - $mmt - $st\n";
print "$deltamin minutes\n";
}
Le résultat du programme est de la forme :
20080617144859 - 20080617140355
0 - 0 - 45 - 4
45 minutes
Aucun commentaire:
Enregistrer un commentaire