use Time::local; my $view = "cmtools_view"; my $ccdrive = $ENV{CC_DEFAULT_DRIVE}; my $file = "$ccdrive\\$view\\swf\\vobadmin\\vob_manager_mrrd.txt"; my $upsitesynckey = "SyncState ERLH"; my $downsitesynckey = "SyncState SCR"; my $upsitereplicakey = "Replica for ERLH"; my $downsitereplicakey = "Replica for SCR"; my @newtime; my $htmlpath='synccheck1.htm'; my $logfile='synccheck.log'; my $maxtime; my %month = (Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5, Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11); #Define some colors... my $GRN="#00FF00"; my $YEL="#FFFF00"; my $RED="#FF0000"; my $GRY="#808080"; my $curcolor=$GRN; my %rephash; my $x; my $y; my @erlh; my @scr; open(TFILE2,">$htmlpath") || die "Can't open $htmlpath"; # Print the html header section. print TFILE2 < SyncCheck

 

Clearcase Sync Check Summary

 

WEB_PAGE # Handle the "Last Update" my $time=localtime(time); print TFILE2 "

Last update: $time


\n"; open (FILE, "$file") || die "Can't open $file"; $tmp=; foreach(split(/\t/,$tmp)){ push(@vobhashkeys, $_); } while () { $tmp=$_; @vobconfig=split(/\t/,$tmp); $idx=0; #Combine the two arrays into a hash. Taking the long way around, here. foreach(@vobconfig){ $vobhash{$vobhashkeys[$idx]}=$_; $idx++; } #Clear out the arrays. @vobconfig=(""); # Get a more accurate vob tag. $vobname=$vobhash{"VOB-Tag"}; #If the syncstate of a site has an X or "EXPORT", Add its replica to the list. if(uc($vobhash{$upsitesynckey}) eq "X" || uc($vobhash{$upsitesynckey}) eq "EXPORT"){ push(@replicas, $vobhash{$upsitereplicakey}); push(@vobs, $vobname); } if(uc($vobhash{$downsitesynckey}) eq "X" || uc($vobhash{$downsitesynckey}) eq "EXPORT"){ push(@replicas, $vobhash{$downsitereplicakey}); push(@vobs, $vobname); } %vobhash = (""); } close (FILE); foreach $replica (@replicas) { if ($replica =~ /scr/g || $replica =~ /princeton/g) { push (@scr, $replica); #print TFILE2 "$replica"; #print TFILE2 "$durhours"; } if ($replica =~ /erlh/g) { push (@erlh, $replica); #print TFILE2 " $replica   "; #print TFILE2 " $durhours   "; } } $idx=0; foreach $replica (@scr || @erlh) { $cmd="cleartool describe replica:$replica\@\\$vobs[$idx]"; $time=`$cmd`; $time =~ /last_export = /g; $time=substr($time, pos($time), length($time)-pos($time)); @timelocal = localtime(time); $day=substr($time, 0, 2); $mon=substr($time, 3, 3); $year="20".substr($time, 7, 2); $hour=substr($time, 10, 2); $min=substr($time, 13, 2); $sec=substr($time, 16, 2); # Convert the month abbreviation to a number (0-11). Use separate variable. $mon = $month{$mon}; @newtime=($sec, $min, $hour, $day, $mon, $year, undef, undef, undef); $x=Time::Local::timelocal(@timelocal); $y=Time::Local::timelocal(@newtime); $z=$x-$y; my $durhours=int($z/3600); $z-=($durhours*3600); my $durmins=int($z/60); $z-=($durmins*60); my $dursecs=$z; if ($durhours < 3) { $curcolor = "$GRN"; } if ($durhours >= 3 && $durhours < 7 ) { $curcolor = "$YEL"; } if ($durhours > 7 ) { $curcolor = "$RED"; } if ($durhours > $maxtime) { $maxtime = $durhours; } if ($maxtime < 3) { $currentstatus = "OK"; } if ($maxtime >= 3 && $maxtime < 7 ) { $currentstatus = "WARN"; } if ($maxtime > 7 ) { $currentstatus = "ERROR"; } $idx++; } $idxa=0; print TFILE2 ""; while ($idx > @scr || $idx > @erlh) { print TFILE2 " "; print TFILE2 ""; print TFILE2 ""; print TFILE2 ""; print TFILE2 ""; print TFILE2 ""; print TFILE2 ""; $idxa++; } print TFILE2 "
$scr[$idx]$durhours $erlh[$idx] $durhours
"; &loghandler ($currentstatus); print "$currentstatus\n"; sub loghandler{ #Updates the log file with the current status. Adds history line to page. my @logs; #Array to hold log entries my @currenttime; my $entryidx; #Index to the correct log entry. my $currentstatus=$_[0]; #Define some colors... my $GRN="#00FF00"; my $YEL="#FFFF00"; my $RED="#FF0000"; my $GRY="#808080"; my $curcolor=$GRN; # Get the log file open(LOGFILE,"$logfile") || die "Can't get $logfile"; $tmp=; #Ignore the first line. while(){ $tmp=$_; chomp($tmp); push(@logs, $tmp); } close(LOGFILE); # Calculate which entry to change and do it. @currenttime=localtime(time); $entryidx=($currenttime[2]*4)+int($currenttime[1]/15); $logs[$entryidx]=$currentstatus; #Add the timeline to the webpage. print TFILE2 "

History

\n"; print TFILE2 "

12A 1A  2A  3A  4A  5A  6A  7A  8A  9A  10A 11A 12P 1P  2P  3P  4P  5P  6P  7P  8P  9P  10P 11P 
"; print TFILE2 "

| ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' | ' 
"; print TFILE2 "

";

#Re-generate the log file and add entries to the time line.
open(LOGFILE,">$logfile") || die "Can't create $logfile";
print LOGFILE "$rgyerror errors in Clearcase registry. \n";
$x=0;
foreach $entry (@logs) {
	if($x > $entryidx){
		#RE-Define some colors...
		$GRN="#00A000";
		$YEL="#A0A000";
		$RED="#A00000";
		$GRY="#808080";
	}
	print LOGFILE "$entry\n";
	if($entry eq "OK" && $curcolor ne $GRN){ print TFILE2 ""; $curcolor=$GRN;}
	if($entry eq "WARN" && $curcolor ne $YEL){ print TFILE2 ""; $curcolor=$YEL;}
	if($entry eq "ERROR" && $curcolor ne $RED){ print TFILE2 ""; $curcolor=$RED;}
	if($entry eq "UNAVAILABLE" && $curcolor ne $GRY){ print TFILE2 ""; $curcolor=$GRY;}
	print TFILE2 "*";
	$x++;
}
close(LOGFILE);

#Finally add the pointer to the current entry
print TFILE2 "

";
for(0..$entryidx-1){print TFILE2 " ";}
print TFILE2 "^ 
"; print "Time: $currenttime[2]: $currenttime[1] Entry: $entryidx\n" ; } #End of Sub