瀏覽代碼

Ticket 47538 - Fix repl-monitor color and lag times

Bug Description:  Colors do not match the legend, and when the supplier or
                  consumer max csns are not available, the lag time is displayed
                  incorrectly.

Fix Description:  The color hash table needed to be sorted before processing,
                  and we were not properly detecting the "Unavailable" state of
                  a replica which lead to the odd lag times.  Also added the
                  string "Unavailable" for uninitialized values which allowed
                  for a cleaner report when replicas are offline.

                  Updated the man page as well.

https://fedorahosted.org/389/ticket/47538

Reviewed by: nhosoi(Thanks!)
Mark Reynolds 9 年之前
父節點
當前提交
34c9293532
共有 2 個文件被更改,包括 86 次插入24 次删除
  1. 32 20
      ldap/admin/src/scripts/repl-monitor.pl.in
  2. 54 4
      man/man1/repl-monitor.1

+ 32 - 20
ldap/admin/src/scripts/repl-monitor.pl.in

@@ -596,7 +596,7 @@ sub process_suppliers
 			# Skip replicas without agreements defined yet
 			next if (! grep {$_->{ridx} == $ridx} @allagreements);
 			$maxcsn = &print_master_header ($ridx, $mid);
-			if ( "$maxcsn" ne "none" ) {
+			if ( "$maxcsn" ne "Unavailable" ) {
 				&print_consumer_header ();
 				&print_consumers ($ridx, $mid);
 			}
@@ -754,12 +754,12 @@ sub print_consumers
 	my ($c_maxcsn, $c_maxcsn_str, $c_lastmodified, $c_sidx, $lag, $markcolor);
 	my ($c_replicaroot, $c_replicatype);
 	my ($first_entry, $s_ldapurl, $c_ldapurl);
-	my $supplier_maxcsn = "_";
+	my $supplier_maxcsn = "Unavailable";
 	my ($nrows);
 	my ($found);
 
 	undef @ouragreements;
-	$c_lastmodified = "";
+	$c_lastmodified = "Unavailable";
     
 	# Collect all the consumer replicas for the current master replica
 	push (@consumers, $m_ridx);
@@ -790,18 +790,20 @@ sub print_consumers
         
 		if ($c_ridx >= 0) {
 			$myruv = $allruvs {"$c_ridx:$mid"};
-			($c_maxcsn, $c_lastmodified) = split ( /;/, $myruv );
-			($c_sidx, $c_replicaroot, $c_replicatype) = split (/:/, $allreplicas[$c_ridx]);
-			$c_replicaroot = "same as master" if $m_replicaroot eq $c_replicaroot;
+			if ($myruv) {
+				($c_maxcsn, $c_lastmodified) = split ( /;/, $myruv );
+				($c_sidx, $c_replicaroot, $c_replicatype) = split (/:/, $allreplicas[$c_ridx]);
+				$c_replicaroot = "same as master" if $m_replicaroot eq $c_replicaroot;
+			}
 		}
 		else {
 			# $c_ridx is actually -$c_sidx when c is not available
 			$c_sidx = -$c_ridx;
-			$c_maxcsn_str = "_";
+			$c_maxcsn_str = "Unavailable";
 			$lag = "n/a";
 			$markcolor = "red";
-			$c_replicaroot = "_";
-			$c_replicatype = "_";
+			$c_replicaroot = "Unavailable";
+			$c_replicatype = "Unavailable";
 		}
 
 		$nrows = 0;
@@ -932,7 +934,7 @@ sub get_supplier_maxcsn
 {
 	my ($ridx, $s, $cn, $h, $p) = @_;
 	my $decimalcsn;
-	my $csn = "";
+	my $csn = "Unavailable";
 	# normalize suffix
 	$s =~ s/ //;
 	$s =~ lc $s;
@@ -944,7 +946,7 @@ sub get_supplier_maxcsn
 			last;
 		}
 	}
-	if($csn ne ""){
+	if($csn && $csn ne "Unavailable"){
 		$decimalcsn = &to_decimal_csn ($csn);
 		return "$csn:$decimalcsn";
 	}
@@ -966,11 +968,16 @@ sub cacl_time_lag
 	$supplier_csn_str = &to_string_csn ($s_maxcsn);
 	$csn_str = &to_string_csn ($c_maxcsn);
 	
-	if ($s_maxcsn && !$c_maxcsn) {
+	if ((!$s_maxcsn || $s_maxcsn eq "Unavailable") &&
+	    (!$c_maxcsn || $c_maxcsn eq "Unavailable")) {
+		$lag_str = "?:??:??";
+		$markcolor = "white"; # Both unknown
+	}
+	elsif ($s_maxcsn && (!$c_maxcsn || $c_maxcsn eq "Unavailable")) {
 		$lag_str = "- ?:??:??";
 		$markcolor = &get_color (36000); # assume consumer has big latency
 	}
-	elsif (!$s_maxcsn && $c_maxcsn) {
+	elsif ((!$s_maxcsn || $s_maxcsn eq "Unavailable") && $c_maxcsn) {
 		$lag_str = "+ ?:??:??";
 		$markcolor = &get_color (1); # consumer is ahead of supplier
 	}
@@ -1180,7 +1187,7 @@ sub to_decimal_csn
 {
 	my ($maxcsn) = @_;
 	if (!$maxcsn || $maxcsn eq "" || $maxcsn eq "Unavailable") {
-		return "none";
+		return "Unavailable";
 	}
 
 	my ($tm, $seq, $masterid, $subseq) = unpack("a8 a4 a4 a4", $maxcsn);
@@ -1195,9 +1202,13 @@ sub to_decimal_csn
 
 sub to_string_csn
 {
-	my ($rawcsn, $decimalcsn) = split(/:/, "@_");
+	my $str = shift;
+	if (!defined($str)){
+		return "Unavailable";
+	}
+	my ($rawcsn, $decimalcsn) = split(/:/, "$str");
 	if (!$rawcsn || $rawcsn eq "") {
-		return "none";
+		return "Unavailable";
 	}
 	if ($rawcsn eq "Unavailable"){
 	    return $rawcsn;
@@ -1221,7 +1232,7 @@ sub get_color
 	$lag_minute /= 60;
 	my ($color) = $allcolors { $colorkeys[0] };
 	
-	foreach ( keys %allcolors) {
+	foreach ( sort keys %allcolors) {
 		if ($lag_minute >= $_){
 		    $color = $allcolors {$_};
 		}
@@ -1300,14 +1311,15 @@ sub print_legend
 	if($opt_s){ return; }
 	print "\n<center><p><font class=page-subtitle color=#0099cc>Time Lag Legend:</font><p>\n";
 	print "<table cellpadding=6 cols=$nlegends width=40%>\n<tr>\n";
+	print "\n<td bgcolor=white><center>Unknown</center></td>\n";
 	my ($i, $j);
 	for ($i = 0; $i < $nlegends - 1; $i++) {
 		$j = $colorkeys[$i];
-		print "\n<td bgcolor=$allcolors{$j}><center>within $colorkeys[$i+1] min</center></td>\n";
+		print "\n<td bgcolor=$allcolors{$j}><center>Within $colorkeys[$i+1] minutes</center></td>\n";
 	}
 	$j = $colorkeys[$i];
-	print "\n<td bgcolor=$allcolors{$j}><center>over $colorkeys[$i] min</center></td>\n";
-	print "\n<td bgcolor=red><center>server n/a</center></td>\n";
+	print "\n<td bgcolor=$allcolors{$j}><center>Over $colorkeys[$i] minutes</center></td>\n";
+	print "\n<td bgcolor=red><center>Server n/a</center></td>\n";
 	print "</table></center>\n";
 }
 

+ 54 - 4
man/man1/repl-monitor.1

@@ -2,7 +2,7 @@
 .\" First parameter, NAME, should be all caps
 .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
 .\" other parameters are allowed: see man(7), man(1)
-.TH REPL-MONITOR 1 "May 18, 2008"
+.TH REPL-MONITOR 1 "Jun 28, 2016"
 .\" Please adjust this date whenever revising the manpage.
 .\"
 .\" Some roff macros, for reference:
@@ -68,6 +68,56 @@ Prompt for passwords
 Print plain text report
 
 .br
+.SH CONFIGURATION FILE
+This section describes the various directives that can be used in the configuration file.
+.TP
+.B [connection]
+The connection details about a replica
+.br
+
+host:port:binddn:bindpwd:cert_file
+.br
+
+or,
+.br
+
+host:port=shadowport:binddn:bindpwd:cert_file
+.TP
+.B [alias]
+Define an alias for a server, this alias is used in the report in place of the
+hostname/port
+
+.br
+alias = host:port
+.TP
+.B [color]
+Set a color based on the replicaton lag time lowmark (in minutes)
+.br
+
+.R lowmark = color
+.SH EXAMPLE
+Example of a configuration file:
+
+[connection]
+.br
+localhost.localdomain:3891:cn=directory manager:password:*
+.br
+localhost2.localdomain:3892:cn=directory manager:password:*
+
+[alias]
+.br
+MY_SYSTEM1 = localhost.localdomain:3891
+.br
+MY_SYSTEM2 = localhost2.localdomain:3892
+
+[color]
+.br
+0 = #CCFFCC
+.br
+5 = #FFFFCC
+.br
+60 = #FFCCCC
+
 .SH AUTHOR
 repl-monitor was written by the 389 Project.
 .SH "REPORTING BUGS"
@@ -75,14 +125,14 @@ Report bugs to https://fedorahosted.org/389/newticket.
 .SH COPYRIGHT
 Copyright \(co 2001 Sun Microsystems, Inc. Used by permission.
 .br
-Copyright \(co 2008 Red Hat, Inc.
+Copyright \(co 2016 Red Hat, Inc.
 .br
 This manual page was written by Michele Baldessari <[email protected]>,
 for the Debian project (but may be used by others).
 .br
-Manual page updated by Mark Reynolds <[email protected]> 10/11/13
+Manual page updated by Mark Reynolds <[email protected]> 6/28/2016
 .br
 This is free software.  You may redistribute copies of it under the terms of
 the Directory Server license found in the LICENSE file of this
 software distribution.  This license is essentially the GNU General Public
-License version 2 with an exception for plug\(hyin distribution.
+License version 3 with an exception for plug\(hyin distribution.