Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
5.4 KiB

  1. @rem = '
  2. @goto endofperl
  3. ';
  4. $USAGE = "
  5. Usage: $0 datafile
  6. topchk-showconn takes the output of \"repadmin /showconn\" and summarizes the topology.
  7. ";
  8. die $USAGE unless @ARGV;
  9. printf("\n\n");
  10. $InFile = "";
  11. $replhours = 168; # No schedule means that DS replicates every hour.
  12. $hostsite = "unknown";
  13. $hostsrv = "unknown";
  14. $fromsite = "unknown";
  15. $fromsrv = "unknown";
  16. $schedule = "none";
  17. $enable = "unknown";
  18. $cxtion = "unknown";
  19. $skiprest = 0;
  20. while (<>) {
  21. if ($InFile ne $ARGV) {
  22. &PrintSummary();
  23. $InFile = $ARGV;
  24. $modtime = (stat $InFile)[9];
  25. printf("Processing file %s Modify Time: %s\n\n", $InFile, scalar localtime($modtime));
  26. $infilelist = $infilelist . " " . $InFile;
  27. $skiprest = 0;
  28. }
  29. if ($skiprest) {next;}
  30. chop;
  31. ($func, @a) = split(":");
  32. if (($func eq "") || ($func =~ m/^#/)) {next;}
  33. if (m/connections found./) {$skiprest = 1; next;}
  34. if ($func =~ m/Connection name/) {
  35. if ($cxtion ne "unknown") {&PrintRecord();}
  36. $cxtion = $a[0];
  37. $schedule = "none";
  38. next;
  39. }
  40. if ($func =~ m/enabledConnection/) {
  41. #printf("%s\n", $_);
  42. $enable = uc($a[0]);
  43. next;
  44. }
  45. if ($func =~ m/Server DNS name/) {
  46. $srvdns = $a[0];
  47. if ($srvdns eq " (null)") {++$NullDnsCount;}
  48. next;
  49. }
  50. if ($func =~ m/Server DN name/) {
  51. #printf("%s\n", $_);
  52. #Server DN name : CN=NTDS Settings,CN=C0010000,CN=Servers,CN=0100Site,CN=Sites,CN=Configuratio...
  53. ($hostsrv, $hostsite) = m/cn=ntds settings,cn=(.*),cn=servers,cn=(.*),cn=sites/i;
  54. if (m/LostAndFound/) {
  55. ++$LostCount;
  56. $hostsite = "Lost";
  57. $hostsrv = "AndFound";
  58. }
  59. next;
  60. }
  61. if ($func =~ m/fromServer/) {
  62. #printf("%s\n", $_);
  63. #
  64. # fromServer: Site-76\CYBER0760
  65. #
  66. ($fromsite, $fromsrv) = ($a[0] =~ m/ (.*)\\(.*)/);
  67. $from = $fromsite . "\\" . $fromsrv;
  68. $host = $hostsite . "\\" . $hostsrv;
  69. $fromlist{uc($from)}++;
  70. $hostlist{uc($host)}++;
  71. next;
  72. }
  73. if ($cxtion ne "unknown") {
  74. #
  75. # Mon: 001000000000000000000010
  76. #
  77. # Count the number of non-zero hours
  78. #
  79. if (m/Sun\:|Mon\:|Tue\:|Wed\:|Thu\:|Fri\:|Sat\:/) {
  80. ($dayname, $scvector) = split;
  81. if ($dayname eq "Sun:" ) {$replhours = 0;}
  82. if ($dayname eq "Mon:" ) {$schedule = lc($scvector);} # save Monday's schedule.
  83. for ($i=0; $i < 24; $i++) {
  84. if (substr($scvector, $i, 1) ne "0") {$replhours++;}
  85. }
  86. if ($daynum eq "Sat:") { &PrintRecord(); } # Day 7: output record.
  87. }
  88. }
  89. #
  90. # If start of a new Set. Print summary info on last one.
  91. #
  92. if ($func =~ m/Base DN/) {
  93. &PrintSummary();
  94. printf("\n\n%s\n\n", $_);
  95. next;
  96. }
  97. }
  98. &PrintSummary();
  99. exit;
  100. sub PrintRecord {
  101. printf("cxtion: %-36s host:%20s\\%-16s from:%20s\\%-16s RepHrs: %3d Sched: %-24s enabled: %5s\n",
  102. $cxtion, $hostsite, $hostsrv, $fromsite, $fromsrv, $replhours, $schedule, $enable);
  103. #
  104. # Track the number of connections with the same Monday schedule and the same per-week repl hours.
  105. #
  106. $monsched{$schedule}++;
  107. $hoursched{$replhours}++;
  108. if ($enable =~ m/FALSE/) {$disabledcxtion++;}
  109. $cxtioncount++;
  110. $cxtion = "unknown";
  111. $fromsite = "unknown";
  112. $fromsrv = "unknown";
  113. $enable = "unknown";
  114. $replhours = 168;
  115. $schedule = "none";
  116. }
  117. sub PrintSummary {
  118. if ($cxtioncount == 0) {return;}
  119. if ($cxtion ne "unknown") {
  120. #
  121. # print the last connection record.
  122. #
  123. &PrintRecord();
  124. }
  125. printf("\n\n Servers referenced from cxtions (From List) \n\n");
  126. foreach $param (sort keys(%fromlist)) {
  127. printf("%-25s %5d %5d\n", $param, $fromlist{$param}, $hostlist{$param});
  128. }
  129. printf("\n\n Servers hosting cxtions (Host List) \n\n");
  130. foreach $param (sort keys(%hostlist)) {
  131. printf("%-25s %5d %5d\n", $param, $hostlist{$param}, $fromlist{$param});
  132. }
  133. printf("\n\n\n S U M M A R Y R E P O R T \n\n");
  134. printf("\nConnection objects: %5d\n", $cxtioncount);
  135. printf("\nConnection objects set to disabled: %5d\n", $disabledcxtion);
  136. printf("\nConnection objects with null Server DNS names: %5d\n", $NullDnsCount);
  137. printf("\nConnection objects in LostAndFound: %5d\n", $LostCount);
  138. printf("\n\nNumber connections with given Monday Schedule\n\n");
  139. foreach $param (sort keys(%monsched)) {
  140. printf("%-28s %5d\n", $param, $monsched{$param});
  141. }
  142. printf("\n\nNumber connections with per-week active replication hours\n\n");
  143. foreach $param (sort keys(%hoursched)) {
  144. printf("%-28s %5d\n", $hoursched{$param}, $param);
  145. }
  146. print "\f\n";
  147. $replhours = 168; # No schedule means that DS replicates every hour.
  148. $hostsite = "unknown";
  149. $hostsrv = "unknown";
  150. $fromsite = "unknown";
  151. $fromsrv = "unknown";
  152. $schedule = "none";
  153. $enable = "unknown";
  154. $cxtion = "unknown";
  155. $cxtioncount = 0;
  156. $disabledcxtion = 0;
  157. undef %monsched;
  158. undef %hoursched;
  159. undef %fromlist;
  160. undef %hostlist;
  161. }
  162. __END__
  163. :endofperl
  164. @perl %~dpn0.cmd %*