Source code of Windows XP (NT5)
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.

383 lines
13 KiB

  1. /*---------------------------------------------------------------------------
  2. File: ScanLog.cpp
  3. Comments: Routines to scan the dispatch log for the DCT agents
  4. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 03/15/99 13:29:18
  9. ---------------------------------------------------------------------------
  10. */
  11. #include "StdAfx.h"
  12. #include "Common.hpp"
  13. #include "UString.hpp"
  14. #include "TNode.hpp"
  15. #include "ServList.hpp"
  16. #include "Globals.h"
  17. #include "Monitor.h"
  18. #include "FParse.hpp"
  19. #include "afxdao.h"
  20. #include "errDct.hpp"
  21. #define AR_Status_Created (0x00000001)
  22. #define AR_Status_Replaced (0x00000002)
  23. #define AR_Status_AlreadyExisted (0x00000004)
  24. #define AR_Status_RightsUpdated (0x00000008)
  25. #define AR_Status_DomainChanged (0x00000010)
  26. #define AR_Status_Rebooted (0x00000020)
  27. #define AR_Status_Warning (0x40000000)
  28. #define AR_Status_Error (0x80000000)
  29. #define BYTE_ORDER_MARK (0xFEFF)
  30. void ParseInputFile(const WCHAR * filename);
  31. DWORD __stdcall LogReaderFn(void * arg)
  32. {
  33. WCHAR logfile[MAX_PATH];
  34. BOOL bDone;
  35. long nSeconds;
  36. CoInitialize(NULL);
  37. gData.GetLogPath(logfile);
  38. gData.GetDone(&bDone);
  39. gData.GetWaitInterval(&nSeconds);
  40. while ( ! bDone )
  41. {
  42. ParseInputFile(logfile);
  43. Sleep(nSeconds * 1000);
  44. gData.GetDone(&bDone);
  45. gData.GetWaitInterval(&nSeconds);
  46. }
  47. CoUninitialize();
  48. return 0;
  49. }
  50. BOOL
  51. TErrorLogParser::ScanFileEntry(
  52. WCHAR * string, // in - line from TError log file
  53. WCHAR * timestamp, // out- timestamp from this line
  54. int * pSeverity, // out- severity level of this message
  55. int * pSourceLine, // out- the source line for this message
  56. WCHAR * msgtext // out- the textual part of the message
  57. )
  58. {
  59. BOOL bSuccess = TRUE;
  60. WCHAR cSeverity;
  61. WCHAR cNumber;
  62. int severity = 0;
  63. (*pSeverity) = 0;
  64. (*pSourceLine) = 0;
  65. // extract the timestamp
  66. if ( string[0] == BYTE_ORDER_MARK )
  67. {
  68. string++;
  69. }
  70. UStrCpy(timestamp,string,20);
  71. cSeverity = string[20];
  72. cNumber = string[21];
  73. severity = 0;
  74. switch ( cSeverity )
  75. {
  76. case L'I' :
  77. break;
  78. case L'W':
  79. if ( cNumber == L'1' ) severity = 1;
  80. break;
  81. case L'E':
  82. if ( cNumber == L'2' ) severity = 2;
  83. break;
  84. case L'S':
  85. if ( cNumber == L'3' ) severity = 3;
  86. break;
  87. case L'V':
  88. if ( cNumber == L'4' ) severity = 4;
  89. break;
  90. case L'U':
  91. if ( cNumber == L'5' ) severity = 5;
  92. break;
  93. case L'X':
  94. if ( cNumber == L'6' ) severity = 6;
  95. break;
  96. };
  97. if ( severity )
  98. {
  99. WCHAR temp[10];
  100. UStrCpy(temp,string+22,5);
  101. (*pSourceLine) = _wtoi(temp);
  102. UStrCpy(msgtext,string+28);
  103. }
  104. else
  105. {
  106. UStrCpy(msgtext,string+20);
  107. }
  108. (*pSeverity) = severity;
  109. if ( bSuccess )
  110. {
  111. msgtext[UStrLen(msgtext)-2] = 0;
  112. }
  113. return bSuccess;
  114. }
  115. BOOL GetServerFromMessage(WCHAR const * msg,WCHAR * server)
  116. {
  117. BOOL bSuccess = FALSE;
  118. int ndx = 0;
  119. for ( ndx = 0 ; msg[ndx] ; ndx++ )
  120. {
  121. if ( msg[ndx] == L'\\' && msg[ndx+1] == L'\\' )
  122. {
  123. bSuccess = TRUE;
  124. break;
  125. }
  126. }
  127. if ( bSuccess )
  128. {
  129. int i = 0;
  130. ndx+=2; // strip of the backslashes
  131. for ( i=0; msg[ndx] && msg[ndx] != L'\\' && msg[ndx]!= L' ' && msg[ndx] != L',' && msg[ndx] != L'\t' && msg[ndx] != L'\n' ; i++,ndx++)
  132. {
  133. server[i] = msg[ndx];
  134. }
  135. server[i] = 0;
  136. }
  137. else
  138. {
  139. server[0] = 0;
  140. }
  141. return bSuccess;
  142. }
  143. void ParseInputFile(WCHAR const * gLogFile)
  144. {
  145. FILE * pFile = 0;
  146. WCHAR server[200];
  147. int nRead = 0;
  148. int count = 0;
  149. HWND lWnd = NULL;
  150. long totalRead;
  151. BOOL bNeedToCheckResults = FALSE;
  152. TErrorLogParser parser;
  153. TErrorDct edct;
  154. parser.Open(gLogFile);
  155. gData.GetLinesRead(&totalRead);
  156. if ( parser.IsOpen() )
  157. {
  158. // scan the file
  159. while ( ! parser.IsEof() )
  160. {
  161. if ( parser.ScanEntry() )
  162. {
  163. nRead++;
  164. if ( nRead < totalRead )
  165. continue;
  166. // the first three lines each have their own specific format
  167. if ( nRead == 1 )
  168. {
  169. // first comes the name of the human-readable log file
  170. gData.SetReadableLogFile(parser.GetMessage());
  171. }
  172. else if ( nRead == 2 )
  173. {
  174. // next, the name and location of the result share - this is needed to look for the result files
  175. WCHAR const * dirName = parser.GetMessage();
  176. WCHAR const * colon = wcsrchr(dirName+3,':');
  177. if ( colon )
  178. {
  179. WCHAR const * sharename = colon+2;
  180. WCHAR const * netname = wcschr(sharename+2,L'\\');
  181. if ( netname )
  182. {
  183. gData.SetResultShare(netname+1);
  184. WCHAR directory[MAX_PATH];
  185. // UStrCpy(directory,dirName,(colon - dirName ));
  186. UStrCpy(directory,dirName,(int)(colon - dirName ));
  187. gData.SetResultDir(directory);
  188. }
  189. }
  190. continue;
  191. }
  192. else if ( nRead == 3 )
  193. {
  194. // now the count of computers being dispatched to
  195. count = _wtoi(parser.GetMessage());
  196. ComputerStats cStat;
  197. gData.GetComputerStats(&cStat);
  198. cStat.total = count;
  199. gData.SetComputerStats(&cStat);
  200. continue;
  201. }
  202. else // all other message have the following format: COMPUTER<tab>Action<tab>RetCode
  203. {
  204. WCHAR action[50];
  205. WCHAR const * pAction = wcschr(parser.GetMessage(),L'\t');
  206. WCHAR const * retcode = wcsrchr(parser.GetMessage(),L'\t');
  207. TServerNode * pServer = NULL;
  208. if ( GetServerFromMessage(parser.GetMessage(),server)
  209. && pAction
  210. && retcode
  211. && pAction != retcode
  212. )
  213. {
  214. // UStrCpy(action,pAction+1,retcode - pAction);
  215. UStrCpy(action,pAction+1,(int)(retcode - pAction));
  216. // add the server to the list, if it isn't already there
  217. gData.Lock();
  218. pServer = gData.GetUnsafeServerList()->FindServer(server);
  219. if ( ! pServer )
  220. pServer = gData.GetUnsafeServerList()->AddServer(server);
  221. gData.Unlock();
  222. retcode++;
  223. DWORD rc = _wtoi(retcode);
  224. if ( pServer )
  225. {
  226. if ( UStrICmp(pServer->GetTimeStamp(),parser.GetTimestamp()) < 0 )
  227. {
  228. pServer->SetTimeStamp(parser.GetTimestamp());
  229. }
  230. if ( !UStrICmp(action,L"WillInstall") )
  231. {
  232. pServer->SetIncluded(TRUE);
  233. }
  234. else if (! UStrICmp(action,L"JobFile") )
  235. {
  236. pServer->SetJobPath(retcode);
  237. }
  238. else if (! UStrICmp(action,L"Install") )
  239. {
  240. if ( rc )
  241. {
  242. if ( ! *pServer->GetMessageText() )
  243. {
  244. TErrorDct errTemp;
  245. WCHAR text[2000];
  246. errTemp.ErrorCodeToText(rc,DIM(text),text);
  247. pServer->SetMessageText(text);
  248. }
  249. pServer->SetSeverity(2);
  250. pServer->SetFailed();
  251. pServer->SetIncluded(TRUE);
  252. gData.GetListWindow(&lWnd);
  253. // SendMessage(lWnd,DCT_ERROR_ENTRY,NULL,(long)pServer);
  254. SendMessage(lWnd,DCT_ERROR_ENTRY,NULL,(LPARAM)pServer);
  255. }
  256. else
  257. {
  258. pServer->SetInstalled();
  259. pServer->SetIncluded(TRUE);
  260. gData.GetListWindow(&lWnd);
  261. // SendMessage(lWnd,DCT_UPDATE_ENTRY,NULL,(long)pServer);
  262. SendMessage(lWnd,DCT_UPDATE_ENTRY,NULL,(LPARAM)pServer);
  263. }
  264. }
  265. else if ( ! UStrICmp(action,L"Start") )
  266. {
  267. if ( rc )
  268. {
  269. if ( ! *pServer->GetMessageText() )
  270. {
  271. TErrorDct errTemp;
  272. WCHAR text[2000];
  273. errTemp.ErrorCodeToText(rc,DIM(text),text);
  274. pServer->SetMessageText(text);
  275. }
  276. pServer->SetSeverity(2);
  277. pServer->SetFailed();
  278. pServer->SetIncluded(TRUE);
  279. gData.GetListWindow(&lWnd);
  280. // SendMessage(lWnd,DCT_ERROR_ENTRY,NULL,(long)pServer);
  281. SendMessage(lWnd,DCT_ERROR_ENTRY,NULL,(LPARAM)pServer);
  282. }
  283. else
  284. {
  285. // extract the filename and GUID from the end of the message
  286. WCHAR filename[MAX_PATH];
  287. WCHAR guid[100];
  288. WCHAR * comma1 = wcschr(parser.GetMessage(),L',');
  289. WCHAR * comma2 = NULL;
  290. if ( comma1 )
  291. {
  292. comma2 = wcschr(comma1 + 1,L',');
  293. if ( comma2 )
  294. {
  295. // UStrCpy(filename,comma1+1,(comma2-comma1)); // skip the comma & space before the filename
  296. UStrCpy(filename,comma1+1,(int)(comma2-comma1)); // skip the comma & space before the filename
  297. safecopy(guid,comma2+1); // skip the comma & space before the guid
  298. pServer->SetJobID(guid);
  299. pServer->SetJobFile(filename);
  300. pServer->SetStarted();
  301. bNeedToCheckResults = TRUE;
  302. }
  303. gData.GetListWindow(&lWnd);
  304. // SendMessage(lWnd,DCT_UPDATE_ENTRY,NULL,(long)pServer);
  305. SendMessage(lWnd,DCT_UPDATE_ENTRY,NULL,(LPARAM)pServer);
  306. }
  307. }
  308. }
  309. else if ( ! UStrICmp(action,L"Finished") )
  310. {
  311. SendMessage(lWnd,DCT_UPDATE_ENTRY,NULL,NULL);
  312. }
  313. }
  314. }
  315. else
  316. {
  317. // if dispatcher finished dispatching agents set log done
  318. LPCWSTR psz = parser.GetMessage();
  319. if (wcsstr(psz, L"All") && wcsstr(psz, L"Finished"))
  320. {
  321. gData.SetLogDone(TRUE);
  322. }
  323. }
  324. }
  325. }
  326. }
  327. // if we don't have the handle from the list window, we couldn't really send the messages
  328. // in that case we must read the lines again next time, so that we can resend the messages.
  329. if ( lWnd )
  330. {
  331. // if we have sent the messages, we don't need to send them again
  332. gData.SetLinesRead(nRead);
  333. }
  334. gData.SetFirstPassDone(TRUE);
  335. parser.Close();
  336. }
  337. }