I am new to LDAP.pm and like to query several ldap servers for
redundancy/failover. The documentation says that the host can be an array:
"HOST may also be a reference to an array of hosts, host-port pairs or URIs
to try. Each will be tried in order until a connection is made. Only when
all have failed will the result of undef be returned."
When I use the below perl script with 192.168.1.12 being the good ldap
server and 192.168.1.18 a bad ldap server (e.g. switched off). I get
./ldap_query.pl
IO::Socket::SSL: connect: timeout at ./ldap_query.pl line 4, <DATA> line
228.
an error. But I would expect the same result as with
$ldap = Net::LDAPS->new( '192.168.1.12', timeout => 2, version => 3) or die
"$@";
./ldap_query.pl
MM Result: 500
only delayed by max 2 seconds.
What is wrong in my script as I don't get a syntax error or similar ?
Thank you
Markus
#!/usr/bin/perl
use Net::LDAPS;
$ldap = Net::LDAPS->new( '192.168.1.18 192.168.1.12', timeout => 2, version
=> 3) or die "$@";
$mesg = $ldap->bind('cn=ldap user,cn=users,dc=win2003r2,dc=home', password
=> 'TestPass!') ;
$mesg = $ldap->search( # perform a search
base => "dc=win2003r2,dc=home",
filter => "(samaccountname=mm)",
attrs => ["employeeid"]
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->entries) {
$ref=$entry->get_value('employeeid');print "MM Result: $ref\n"; }
$mesg = $ldap->unbind; # take down session