[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: Testing the state of replicates



On Tue, 4 Mar 2008, Marantz, Roy wrote:

> Again any help would be appreciated.

Here's a simple perl script I run on my ldap replicas to check their state.
Seems to work for me, although I can't guarantee I didn't misunderstand
something...


#! /usr/bin/perl

use Net::LDAP ();

my $ldap_master = Net::LDAP->new("ldap-master.csupomona.edu", timeout =>
10) or do {
        print STDERR "Error: failed to connect to LDAP master: $@";
        exit(1);
};

my $ldap_slave = Net::LDAP->new("localhost", timeout => 10) or do {
        print STDERR "Error: failed to connect to LDAP slave: $@";
        exit(1);
};

my $master_csn = lookup_csn($ldap_master, 'master');
my $slave_csn = lookup_csn($ldap_slave, 'slave');

if ($master_csn ne $slave_csn) {
        my $prev_master_csn = $master_csn;
        my $prev_slave_csn = $slave_csn;

        sleep 120;

        $master_csn = lookup_csn($ldap_master, 'master');
        $slave_csn = lookup_csn($ldap_slave, 'slave');

        if ($master_csn ne $slave_csn) {

                if ($prev_slave_csn ne $slave_csn) {
                        my $master_csn_date = $master_csn; $master_csn_date
=~ s/Z.*//;
                        my $slave_csn_date = $slave_csn; $slave_csn_date =~
s/Z.*//;

                        if ($master_csn_date - $slave_csn_date > 1000) {
                                print STDERR "Warning: LDAP replica out of
syncronization\n";
                                print STDERR "         master_csn =
$master_csn, slave_csn = $slave_csn\n";
                                exit(1);
                        }
                }
                else {
                        print STDERR "Error: LDAP replica out of
syncronization, no apparent update progress seen\n";
                        print STDERR "       master_csn = $master_csn,
slave_csn = $slave_csn\n";
                        exit(1);
                }
        }
}

sub lookup_csn {
        my ($ldap, $server_name) = @_;

        my $search = $ldap->search(
                scope  => 'base',
                base   => "dc=csupomona,dc=edu",
                filter => "(objectclass=*)",
                attrs  => [ 'contextCSN' ]
                );

        $search->code() and do {
                print STDERR "Error: failed to execute search on
$server_name: "
                        . $search->error() . " (" . $search->code() .
")\n";
                exit(1);
        };

        my $entry = $search->shift_entry() or do {
                print STDERR "Error: search on $server_name 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 entry\n";
                exit(1);
        }

        return $csn;
}



-- 
Paul B. Henson  |  (909) 979-6361  |  http://www.csupomona.edu/~henson/
Operating Systems and Network Analyst  |  henson@csupomona.edu
California State Polytechnic University  |  Pomona CA 91768