Created
February 6, 2015 10:58
-
-
Save duncaninnes/c91985822be9782df581 to your computer and use it in GitHub Desktop.
FreeIPA: Monitor Replication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use Net::LDAP; | |
use strict; | |
print "Content-type: text/html\n\n"; | |
#BIND INFORMATION, and SEARCH BASE | |
my $user = "CN=Directory Manager"; | |
my $passwd = "Password"; | |
my $base = "cn=config"; | |
#Attributes | |
my $server ="nsDS5ReplicaHost"; | |
my $status ="nsds5replicaLastUpdateStatus"; | |
my $laststart ="nsds5replicaLastUpdateStart"; | |
my $lastend ="nsds5replicaLastUpdateEnd"; | |
my @ipa_servers = ( | |
"ipa01.example.com", | |
"ipa02.example.com", | |
"ipa03.example.com", | |
"ipa04.example.com" | |
); | |
print "<html>"; | |
print "<head>"; | |
print "</head>"; | |
print "<body>"; | |
print "<h1>IPA Replication Status</h1>"; | |
print "<p>Updated: ".localtime()."</p>"; | |
print "<table border=1 style=\"background:#f3f3f3; border-collapse: collapse; border:thin; border:black\">"; | |
print "<thead><tr><th>Source</th><th>Target</th><th>Status</th><th>Last Started</th><th>Last Ended</th></tr></thead>"; | |
print "<tbody>\n"; | |
my $ipa_source; | |
foreach $ipa_source ( @ipa_servers ) { | |
#connect to ldap server | |
my $ldap = Net::LDAP->new ( $ipa_source ) or die "$@"; | |
my $mesg = $ldap->bind ( "$user", password => "$passwd" , version => 3 ); | |
$mesg->code && warn "error: ", $mesg->error; | |
my $result=LDAPSearch($ldap,"objectClass=nsDS5ReplicationAgreement","",$base); | |
my @entries = $result->entries; | |
my $entr; | |
foreach $entr ( @entries ) { | |
my $servername=$entr->get_value($server); | |
my $serverstatus=$entr->get_value($status); | |
my $serverlaststart=$entr->get_value($laststart); | |
my $serverlastend=$entr->get_value($lastend); | |
$serverlaststart =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/; | |
$serverlastend =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/; | |
print "<tr>"; | |
print "<td>$ipa_source</td><td>$servername</td><td>$serverstatus</td><td>$serverlaststart</td>"; | |
print "<td>$serverlastend</td>"; | |
print "</tr>"; | |
print "\n"; | |
} | |
} | |
print "</tbody></table></body></html>"; | |
exit; | |
sub LDAPSearch { | |
my ($ldap,$searchString,$attrs,$base) = @_; | |
my $result = $ldap->search ( base => "$base", | |
scope => "sub", | |
filter => "$searchString", | |
attrs => $attrs | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use Net::LDAP; | |
use strict; | |
print "Content-type: text/html\n\n"; | |
#BIND INFORMATION, and SEARCH BASE | |
my $user = "CN=Directory Manager"; | |
my $passwd = "Password"; | |
my $base = "cn=config"; | |
#Attributes | |
my $server ="nsDS5ReplicaHost"; | |
my $status ="nsds5replicaLastUpdateStatus"; | |
my $laststart ="nsds5replicaLastUpdateStart"; | |
my $lastend ="nsds5replicaLastUpdateEnd"; | |
my @ipa_servers = ( | |
"ipa01.example.com", | |
"ipa02.example.com", | |
"ipa03.example.com", | |
"ipa04.example.com" | |
); | |
my $ipa_source; | |
my @report = (); | |
foreach $ipa_source ( @ipa_servers ) { | |
#connect to ldap server | |
my $ldap = Net::LDAP->new ( $ipa_source ) or die "$@"; | |
my $mesg = $ldap->bind ( "$user", password => "$passwd" , version => 3 ); | |
$mesg->code && warn "error: ", $mesg->error; | |
my $result=LDAPSearch($ldap,"objectClass=nsDS5ReplicationAgreement","",$base); | |
my @entries = $result->entries; | |
my $entr; | |
foreach $entr ( @entries ) { | |
my $servername=$entr->get_value($server); | |
my $serverstatus=$entr->get_value($status); | |
my $serverlaststart=$entr->get_value($laststart); | |
my $serverlastend=$entr->get_value($lastend); | |
$serverlaststart =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/; | |
$serverlastend =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/; | |
push @report, [ $serverlastend , $serverlaststart , $ipa_source , $servername , $serverstatus ]; | |
} | |
} | |
my $i; | |
my $j; | |
my @sorted = sort {$b->[1] cmp $a->[1]} @report; | |
print "<html>"; | |
print "<head>"; | |
print "</head>"; | |
print "<body>"; | |
print "<h1>IPA Replication Status</h1>"; | |
print "<p>Updated: ".localtime()."</p>"; | |
print "<table border=1 style=\"background:#f3f3f3; border-collapse: collapse; border:thin; border:black\">"; | |
print "<thead><tr><th>Source</th><th>Target</th><th>Status</th><th>Last Started</th><th>Last Ended</th></tr></thead>"; | |
print "<tbody>"; | |
for $i ( 0 .. $#sorted ) { | |
my $source = $sorted[$i][2]; | |
my $target = $sorted[$i][3]; | |
my $status = $sorted[$i][4]; | |
my $start = $sorted[$i][1]; | |
my $end = $sorted[$i][0]; | |
print "<tr>"; | |
print "<td>$source</td><td>$target</td><td>$status</td><td>$start</td><td>$end</td>"; | |
print "</tr>\n"; | |
} | |
print "</tbody></table></body></html>"; | |
exit; | |
sub LDAPSearch { | |
my ($ldap,$searchString,$attrs,$base) = @_; | |
my $result = $ldap->search ( base => "$base", | |
scope => "sub", | |
filter => "$searchString", | |
attrs => $attrs | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on Perl script at: http://directory.fedoraproject.org/docs/389ds/howto/howto-replicationmonitoring.html
Expanded to contact all IPA servers in a list.
Version 2 then sorts list by Last Ended, Last Started, Source, Target, Status
Not very pretty, but functional.