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.

297 lines
7.7 KiB

  1. // Copyright (c) Microsoft. All rights reserved.
  2. //
  3. // This is unpublished source code of Microsoft.
  4. // The copyright notice above does not evidence any
  5. // actual or intended publication of such source code.
  6. // OneLiner : Implementation of MEventLog
  7. // DevUnit : wlbstest
  8. // Author : Murtaza Hakim
  9. // include files
  10. #include "MEventLog.h"
  11. #include "MWmiParameter.h"
  12. #include "MWmiInstance.h"
  13. #include "MTrace.h"
  14. // constructor for remote operations
  15. //
  16. MEventLog::MEventLog( _bstr_t machineIP )
  17. : _mIP ( machineIP ),
  18. machine( machineIP,
  19. L"root\\cimv2",
  20. NLBMGR_USERNAME,
  21. NLBMGR_PASSWORD )
  22. {
  23. }
  24. // constructor for local operations
  25. //
  26. MEventLog::MEventLog()
  27. : _mIP ( L"Not Set"),
  28. machine( L"root\\cimv2" )
  29. {
  30. }
  31. // copy constructor
  32. //
  33. MEventLog::MEventLog( const MEventLog& obj )
  34. : _mIP( obj._mIP ),
  35. machine( machine )
  36. {
  37. }
  38. // assignment operator
  39. //
  40. MEventLog&
  41. MEventLog::operator=(const MEventLog& rhs )
  42. {
  43. _mIP = rhs._mIP;
  44. machine = rhs.machine;
  45. return *this;
  46. }
  47. // destructor
  48. //
  49. MEventLog::~MEventLog()
  50. {
  51. }
  52. // getEvents
  53. //
  54. MEventLog::MEventLog_Error
  55. MEventLog::getEvents( vector< Event >* eventContainer )
  56. {
  57. MWmiObject::MWmiObject_Error errO;
  58. vector< MWmiInstance > instanceStore;
  59. machine.getInstances( L"Win32_NTLogEvent",
  60. &instanceStore );
  61. // set parameters to get.
  62. vector<MWmiParameter* > parameterStore;
  63. MWmiParameter RecordNumber(L"RecordNumber");
  64. parameterStore.push_back( &RecordNumber );
  65. MWmiParameter Logfile(L"LogFile");
  66. parameterStore.push_back( &Logfile );
  67. MWmiParameter EventIdentifier(L"EventIdentifier");
  68. parameterStore.push_back( &EventIdentifier );
  69. MWmiParameter EventCode(L"EventCode");
  70. parameterStore.push_back( &EventCode );
  71. MWmiParameter SourceName(L"SourceName");
  72. parameterStore.push_back( &SourceName );
  73. MWmiParameter Type(L"Type");
  74. parameterStore.push_back( &Type );
  75. MWmiParameter Category(L"Category");
  76. parameterStore.push_back( &Category );
  77. MWmiParameter ComputerName(L"ComputerName");
  78. parameterStore.push_back( &ComputerName );
  79. MWmiParameter Message(L"Message");
  80. parameterStore.push_back( &Message );
  81. MWmiInstance::MWmiInstance_Error errI;
  82. Event msg;
  83. for( int i = 0; i < instanceStore.size(); ++i )
  84. {
  85. instanceStore[i].getParameters( parameterStore );
  86. msg.RecordNumber = long ( RecordNumber.getValue() );
  87. msg.Logfile = Logfile.getValue();
  88. msg.EventIdentifier = ( long )EventIdentifier.getValue();
  89. msg.EventCode = ( long ) EventCode.getValue();
  90. msg.SourceName = SourceName.getValue();
  91. msg.Type = Type.getValue();
  92. msg.Category = ( long ) Category.getValue();
  93. msg.ComputerName = ComputerName.getValue();
  94. msg.Message = Message.getValue();
  95. eventContainer->push_back( msg );
  96. }
  97. return MEventLog_SUCCESS;
  98. }
  99. // getEvents
  100. //
  101. MEventLog::MEventLog_Error
  102. MEventLog::getEvents( map< unsigned int, UniqueEvent >& systemEvents,
  103. map< unsigned int, UniqueEvent >& applicationEvents )
  104. {
  105. MWmiObject::MWmiObject_Error errO;
  106. vector< MWmiInstance > instanceStore;
  107. machine.getInstances( L"Win32_NTLogEvent",
  108. &instanceStore );
  109. // set parameters to get.
  110. vector<MWmiParameter* > parameterStore;
  111. MWmiParameter Logfile(L"LogFile");
  112. parameterStore.push_back( &Logfile );
  113. MWmiParameter EventCode(L"EventCode");
  114. parameterStore.push_back( &EventCode );
  115. MWmiParameter SourceName(L"SourceName");
  116. parameterStore.push_back( &SourceName );
  117. MWmiParameter Type(L"Type");
  118. parameterStore.push_back( &Type );
  119. MWmiParameter Category(L"Category");
  120. parameterStore.push_back( &Category );
  121. MWmiParameter ComputerName(L"ComputerName");
  122. parameterStore.push_back( &ComputerName );
  123. MWmiParameter Message(L"Message");
  124. parameterStore.push_back( &Message );
  125. MWmiInstance::MWmiInstance_Error errI;
  126. for( int i = 0; i < instanceStore.size(); ++i )
  127. {
  128. instanceStore[i].getParameters( parameterStore );
  129. UniqueEvent msg;
  130. msg.Logfile = Logfile.getValue();
  131. msg.EventCode = ( long ) EventCode.getValue();
  132. msg.SourceName = SourceName.getValue();
  133. msg.Type = Type.getValue();
  134. msg.Category = ( long ) Category.getValue();
  135. msg.ComputerName = ComputerName.getValue();
  136. msg.Message = Message.getValue();
  137. if( msg.Logfile == _bstr_t( L"Application" ) )
  138. {
  139. if( applicationEvents.find( msg.EventCode ) != applicationEvents.end() )
  140. {
  141. // this event has occured previously
  142. applicationEvents[ msg.EventCode ].Count++;
  143. }
  144. else
  145. {
  146. // first occurence.
  147. msg.Count = 1;
  148. applicationEvents[msg.EventCode] = msg;
  149. }
  150. }
  151. else if( msg.Logfile == _bstr_t( L"System") )
  152. {
  153. if( systemEvents.find( msg.EventCode ) != systemEvents.end() )
  154. {
  155. // this event has occured previously
  156. systemEvents[ msg.EventCode].Count++;
  157. }
  158. else
  159. {
  160. // first occurence.
  161. msg.Count = 1;
  162. systemEvents[msg.EventCode] = msg;
  163. }
  164. }
  165. else
  166. {
  167. cout << "should not be here" << endl;
  168. }
  169. }
  170. return MEventLog_SUCCESS;
  171. }
  172. MEventLog::MEventLog_Error
  173. MEventLog::getEvents( map< _bstr_t, map< unsigned int, UniqueEvent > >& Events )
  174. {
  175. MWmiObject::MWmiObject_Error errO;
  176. vector< MWmiInstance > instanceStore;
  177. machine.getInstances( L"Win32_NTLogEvent",
  178. &instanceStore );
  179. // set parameters to get.
  180. vector<MWmiParameter* > parameterStore;
  181. MWmiParameter Logfile(L"LogFile");
  182. parameterStore.push_back( &Logfile );
  183. MWmiParameter EventCode(L"EventCode");
  184. parameterStore.push_back( &EventCode );
  185. MWmiParameter SourceName(L"SourceName");
  186. parameterStore.push_back( &SourceName );
  187. MWmiParameter Type(L"Type");
  188. parameterStore.push_back( &Type );
  189. MWmiParameter Category(L"Category");
  190. parameterStore.push_back( &Category );
  191. MWmiParameter ComputerName(L"ComputerName");
  192. parameterStore.push_back( &ComputerName );
  193. MWmiParameter Message(L"Message");
  194. parameterStore.push_back( &Message );
  195. MWmiInstance::MWmiInstance_Error errI;
  196. map< unsigned int, UniqueEvent >::iterator top;
  197. map< unsigned int, UniqueEvent > temp;
  198. for( int i = 0; i < instanceStore.size(); ++i )
  199. {
  200. instanceStore[i].getParameters( parameterStore );
  201. UniqueEvent msg;
  202. msg.Logfile = Logfile.getValue();
  203. msg.EventCode = ( long ) EventCode.getValue();
  204. msg.SourceName = SourceName.getValue();
  205. msg.Type = Type.getValue();
  206. msg.Category = ( long ) Category.getValue();
  207. msg.ComputerName = ComputerName.getValue();
  208. msg.Message = Message.getValue();
  209. if( Events.find( msg.Logfile ) != Events.end() )
  210. {
  211. if( ( top = Events[msg.Logfile].find( msg.EventCode )) != Events[msg.Logfile].end() )
  212. {
  213. // this event has occured previously
  214. (*top).second.Count++;
  215. }
  216. else
  217. {
  218. // first occurence.
  219. msg.Count = 1;
  220. (*top).second = msg;
  221. }
  222. }
  223. else
  224. {
  225. // first occurence of this logfile
  226. msg.Count = 1;
  227. temp[msg.EventCode] = msg;
  228. Events[msg.Logfile] = temp;
  229. }
  230. }
  231. return MEventLog_SUCCESS;
  232. }