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.

221 lines
5.2 KiB

  1. /*
  2. BCErrorCheck.js
  3. Connect to build console machine and query current status.
  4. Optionally query for more details (slower).
  5. Copyright 2000 - Microsoft
  6. Author: Joe Porkka 6/2/00
  7. */
  8. function MachineInfo()
  9. {
  10. this.strName = '';
  11. this.strIdentity = '';
  12. }
  13. var MAX_MACHINENAME_LENGTH = 32;
  14. var g_aMachines;
  15. var g_fVerbose;
  16. Error.prototype.toString = Error_ToString;
  17. ParseArguments(WScript.Arguments);
  18. main(g_aMachines, g_fVerbose);
  19. WScript.Quit(0);
  20. function Error_ToString()
  21. {
  22. var i;
  23. var str = 'Exception(';
  24. for(i in this)
  25. {
  26. str += i + ": " + this[i] + " ";
  27. }
  28. return str + ")";
  29. }
  30. // PadString(n, cLength)
  31. function PadString(str, cLength)
  32. {
  33. while (str.length < cLength)
  34. str += ' ';
  35. if (str.length > cLength)
  36. str = str.slice(0, cLength);
  37. return str;
  38. }
  39. // MyEval(expr)
  40. // evaluating uneval'ed objects creates a bunch of junk local variables.
  41. // by putting the eval call in a little subroutine, we avoid keeping those
  42. // locals around.
  43. function MyEval(expr)
  44. {
  45. try
  46. {
  47. return eval(expr);
  48. }
  49. catch(ex)
  50. {
  51. WScript.Echo("caught an exception: " + ex);
  52. WScript.Echo("evaluating " + expr);
  53. throw ex;
  54. }
  55. }
  56. function ParseArguments(Arguments)
  57. {
  58. var aMachines = new Array();
  59. var fVerbose = false;
  60. var strArg;
  61. var chArg0;
  62. var chArg1;
  63. var argn;
  64. var fIsMachine = true;
  65. var machine;
  66. for(argn = 0; argn < Arguments.length; argn++)
  67. {
  68. strArg = Arguments(argn);
  69. chArg0 = strArg.charAt(0);
  70. chArg1 = strArg.toLowerCase().slice(1);
  71. if (chArg0 != '-' && chArg0 != '/')
  72. {
  73. if (fIsMachine)
  74. {
  75. machine = new MachineInfo();
  76. machine.strMachine = strArg;
  77. }
  78. else
  79. {
  80. machine.strIdentity = strArg;
  81. aMachines[aMachines.length] = machine;
  82. }
  83. fIsMachine = !fIsMachine;
  84. }
  85. else
  86. {
  87. // Currently, no options
  88. switch(chArg1)
  89. {
  90. case 'v':
  91. fVerbose = true;
  92. break;
  93. default:
  94. Usage();
  95. break;
  96. }
  97. }
  98. }
  99. if (aMachines.length == 0)
  100. Usage();
  101. if (!fIsMachine) // we have computer name but don't have an identity
  102. Usage();
  103. g_aMachines = aMachines;
  104. g_fVerbose = fVerbose;
  105. return true;
  106. }
  107. function Usage()
  108. {
  109. WScript.Echo('');
  110. WScript.Echo('Usage: BCErrorCheck [-v] machine identity [machine identity...]');
  111. WScript.Echo(' -v = verbose');
  112. WScript.Quit(1);
  113. }
  114. function main(aMachines, fVerbose)
  115. {
  116. var i;
  117. for (i = 0; i < aMachines.length; ++i)
  118. {
  119. try
  120. {
  121. CheckMachine(aMachines[i].strMachine, aMachines[i].strIdentity, fVerbose);
  122. }
  123. catch(ex)
  124. {
  125. WScript.Echo("Error while checking " + aMachines[i].strMachine + "\\" + aMachines[i].strIdentity + ":" + ex);
  126. }
  127. }
  128. }
  129. function GetPostBuildIdentity(RemoteObj)
  130. {
  131. var i;
  132. var objEnviron = RemoteObj.Exec('getpublic', 'PrivateData.objEnviron');
  133. objEnviron = MyEval(objEnviron);
  134. for (i=0; i<objEnviron.Machine.length; i++)
  135. {
  136. if (objEnviron.Machine[i].Name.toLowerCase() == objEnviron.BuildManager.Name.toLowerCase())
  137. {
  138. return objEnviron.Machine[i].Identity;
  139. }
  140. }
  141. return "undefined";
  142. }
  143. function CheckMachine(strBldMgr, strBMIdentity, fVerbose)
  144. {
  145. var RemoteObj;
  146. var fError;
  147. var objBuildType;
  148. var objEnviron;
  149. var strMode;
  150. var strMsg = "";
  151. var objEnviron;
  152. RemoteObj = new ActiveXObject('MTScript.Proxy');
  153. RemoteObj.ConnectToMTScript(strBldMgr, strBMIdentity, false);
  154. fError = RemoteObj.StatusValue(0);
  155. strMsg = PadString(strBldMgr + "\\" + strBMIdentity , MAX_MACHINENAME_LENGTH) + ": ";
  156. if (fError)
  157. strMsg += "Error ";
  158. else
  159. strMsg += "OK ";
  160. if (fVerbose)
  161. {
  162. strMode = RemoteObj.Exec('getpublic', 'PublicData.strMode');
  163. strMode = MyEval(strMode);
  164. if (strMode == 'idle')
  165. strMsg += "idle ";
  166. else
  167. {
  168. strMsg += "Build Type: ";
  169. try
  170. {
  171. objBuildType = RemoteObj.Exec('getpublic', 'PublicData.aBuild[0].objBuildType')
  172. objBuildType = MyEval(objBuildType);
  173. strMsg += PadString(objBuildType.strConfigLongName,32) + " ";
  174. strMsg += PadString(objBuildType.strEnviroLongName,32) + " ";
  175. strMsg += PadString(objBuildType.strPostBuildMachine + "\\" + GetPostBuildIdentity(RemoteObj),
  176. MAX_MACHINENAME_LENGTH);
  177. }
  178. catch(ex)
  179. { // If we can't get build type
  180. strMsg += "unavailable";
  181. }
  182. }
  183. }
  184. WScript.Echo(strMsg);
  185. }