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.

6215 lines
156 KiB

  1. //***************************************************************************
  2. //
  3. // DATACLTR.CPP
  4. //
  5. // Module: HEALTHMON SERVER AGENT
  6. //
  7. // Purpose: CDataCollector class to do WMI instance collection.
  8. //
  9. // Copyright (c)1999 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include <tchar.h>
  13. #include "datacltr.h"
  14. #include "datagrp.h"
  15. #include "system.h"
  16. extern CSystem* g_pSystem;
  17. extern CSystem* g_pStartupSystem;
  18. extern LPTSTR conditionLocStr[10];
  19. extern LPTSTR stateLocStr[9];
  20. // STATIC DATA
  21. NSLIST CDataCollector::mg_nsList;
  22. //STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC
  23. void CDataCollector::DETerminationCleanup(void)
  24. {
  25. NSSTRUCT *pns;
  26. int iSize;
  27. int i;
  28. // Since this is a global shared array, we need to do this
  29. // in a static function.
  30. iSize = mg_nsList.size();
  31. for (i = 0; i < iSize ; i++)
  32. {
  33. MY_ASSERT(i<mg_nsList.size());
  34. pns = &mg_nsList[i];
  35. pns->pIWbemServices->Release();
  36. pns->pIWbemServices = NULL;
  37. if (pns->szTargetNamespace)
  38. {
  39. delete [] pns->szTargetNamespace;
  40. pns->szTargetNamespace = NULL;
  41. }
  42. if (pns->szLocal)
  43. {
  44. delete [] pns->szLocal;
  45. pns->szLocal = NULL;
  46. }
  47. }
  48. if (g_pDataCollectorEventSink != NULL)
  49. {
  50. g_pDataCollectorEventSink->Release();
  51. g_pDataCollectorEventSink = NULL;
  52. }
  53. if (g_pDataCollectorPerInstanceEventSink != NULL)
  54. {
  55. g_pDataCollectorPerInstanceEventSink->Release();
  56. g_pDataCollectorPerInstanceEventSink = NULL;
  57. }
  58. }
  59. //////////////////////////////////////////////////////////////////////
  60. // Construction/Destruction
  61. //////////////////////////////////////////////////////////////////////
  62. CDataCollector::CDataCollector()
  63. {
  64. MY_OUTPUT(L"ENTER ***** CDataCollector...", 4);
  65. Init();
  66. m_hmStatusType = HMSTATUS_DATACOLLECTOR;
  67. m_bValidLoad = FALSE;
  68. MY_OUTPUT(L"EXIT ***** CDataCollector...", 4);
  69. }
  70. CDataCollector::~CDataCollector()
  71. {
  72. MY_OUTPUT(L"ENTER ***** ~CDataCollector...", 4);
  73. g_pStartupSystem->RemovePointerFromMasterList(this);
  74. m_bValidLoad = TRUE;
  75. Cleanup(FALSE);
  76. if (m_szGUID)
  77. {
  78. delete [] m_szGUID;
  79. m_szGUID = NULL;
  80. }
  81. if (m_szParentObjPath)
  82. {
  83. delete [] m_szParentObjPath;
  84. m_szParentObjPath = NULL;
  85. }
  86. MY_OUTPUT(L"EXIT ***** ~CDataCollector...", 4);
  87. }
  88. // get polling interval in milliseconds.
  89. long CDataCollector::GetCollectionIntervalMultiple()
  90. {
  91. return m_lCollectionIntervalMultiple;
  92. }
  93. //
  94. // We keep a global static list of pointers to namespaces, so we can share them
  95. // and be more efficient about it. Each time a new one comes in, we add it to the
  96. // list.
  97. //
  98. HRESULT CDataCollector::fillInNamespacePointer(void)
  99. {
  100. HRESULT hRetRes = S_OK;
  101. int i;
  102. int iSize;
  103. BSTR bsNamespace = NULL;
  104. BSTR bsLocal = NULL;
  105. BOOL bFound = FALSE;
  106. NSSTRUCT ns;
  107. NSSTRUCT *pns;
  108. IWbemLocator *pLocator = NULL;
  109. IWbemServices *pService = NULL;
  110. ns.szTargetNamespace = NULL;
  111. ns.szLocal = NULL;
  112. MY_OUTPUT(L"ENTER ***** fillInNamespacePointer...", 4);
  113. hRetRes = CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
  114. CLSCTX_INPROC_SERVER,
  115. IID_IWbemLocator,
  116. (LPVOID*) &pLocator);
  117. if (FAILED(hRetRes))
  118. {
  119. MY_HRESASSERT(hRetRes);
  120. return hRetRes;
  121. }
  122. MY_ASSERT(pLocator);
  123. // We already have apointer to the local Healthmon namespace
  124. if (!_wcsicmp(m_szTargetNamespace, L"healthmon"))
  125. {
  126. m_pIWbemServices = g_pIWbemServices;
  127. }
  128. else
  129. {
  130. iSize = mg_nsList.size();
  131. for (i = 0; i < iSize ; i++)
  132. {
  133. MY_ASSERT(i<mg_nsList.size());
  134. pns = &mg_nsList[i];
  135. if (!_wcsicmp(m_szTargetNamespace, pns->szTargetNamespace) && !_wcsicmp(m_szLocal, pns->szLocal))
  136. {
  137. m_pIWbemServices = pns->pIWbemServices;
  138. bFound = TRUE;
  139. break;
  140. }
  141. }
  142. if (bFound == FALSE)
  143. {
  144. bsNamespace = SysAllocString(m_szTargetNamespace);
  145. MY_ASSERT(bsNamespace); if (!bsNamespace) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  146. if (_wcsicmp(m_szLocal, L""))
  147. {
  148. bsLocal = SysAllocString(m_szLocal);
  149. MY_ASSERT(bsLocal); if (!bsLocal) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  150. }
  151. hRetRes = pLocator->ConnectServer(bsNamespace,
  152. NULL,
  153. NULL,
  154. bsLocal,
  155. 0L,
  156. NULL,
  157. NULL,
  158. &pService);
  159. if (FAILED(hRetRes))
  160. {
  161. hRetRes = hRetRes;
  162. m_pIWbemServices = NULL;
  163. if (hRetRes != WBEM_E_INVALID_NAMESPACE) MY_HRESASSERT(hRetRes);
  164. MY_OUTPUT2(L"Failed to connect to namespace=%s", m_szTargetNamespace, 4);
  165. }
  166. else
  167. {
  168. // Store one in the static array
  169. m_pIWbemServices = pService;
  170. ns.szTargetNamespace = new TCHAR[wcslen(m_szTargetNamespace)+1];
  171. MY_ASSERT(ns.szTargetNamespace); if (!ns.szTargetNamespace) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  172. wcscpy(ns.szTargetNamespace , m_szTargetNamespace);
  173. ns.szLocal = new TCHAR[wcslen(m_szLocal)+1];
  174. MY_ASSERT(ns.szLocal); if (!ns.szLocal) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  175. wcscpy(ns.szLocal , m_szLocal);
  176. ns.pIWbemServices = pService;
  177. mg_nsList.push_back(ns);
  178. }
  179. SysFreeString(bsNamespace);
  180. bsNamespace = NULL;
  181. if (bsLocal)
  182. {
  183. SysFreeString(bsLocal);
  184. bsLocal = NULL;
  185. }
  186. }
  187. }
  188. if (pLocator)
  189. {
  190. pLocator->Release();
  191. pLocator = NULL;
  192. }
  193. MY_OUTPUT(L"EXIT ***** fillInNamespacePointer...", 4);
  194. return hRetRes;
  195. error:
  196. MY_ASSERT(FALSE);
  197. if (bsNamespace)
  198. SysFreeString(bsNamespace);
  199. if (bsLocal)
  200. SysFreeString(bsLocal);
  201. if (ns.szTargetNamespace)
  202. delete [] ns.szTargetNamespace;
  203. if (ns.szLocal)
  204. delete [] ns.szLocal;
  205. if (pLocator)
  206. pLocator->Release();
  207. m_bValidLoad = FALSE;
  208. Cleanup(FALSE);
  209. return FALSE;
  210. }
  211. //
  212. // Load a single DataCollector, and everything under it.
  213. //
  214. HRESULT CDataCollector::LoadInstanceFromMOF(IWbemClassObject* pObj, CDataGroup *pParentDG, LPTSTR pszParentObjPath, BOOL bModifyPass/*FALSE*/)
  215. {
  216. GUID guid;
  217. int i, iSize;
  218. CThreshold* pThreshold;
  219. LPTSTR pszTemp;
  220. LPTSTR pszStr;
  221. HRESULT hRetRes = S_OK;
  222. //XXXXX
  223. //static count = 0;
  224. MY_OUTPUT(L"ENTER ***** CDataCollector::LoadInstanceFromMOF...", 4);
  225. // Make sure that the Thresholds are loaded properly first
  226. iSize = m_thresholdList.size();
  227. for (i = 0; i < iSize ; i++)
  228. {
  229. MY_ASSERT(i<m_thresholdList.size());
  230. pThreshold = m_thresholdList[i];
  231. if (pThreshold->m_bValidLoad == FALSE)
  232. // return WBEM_E_INVALID_OBJECT;
  233. return S_OK;
  234. }
  235. m_bValidLoad = TRUE;
  236. Cleanup(bModifyPass);
  237. if (bModifyPass == FALSE)
  238. {
  239. // This is the first initial read in of this
  240. // Get the GUID property
  241. // If this fails we will actually not go through with the creation of this object.
  242. if (m_szGUID)
  243. {
  244. delete [] m_szGUID;
  245. m_szGUID = NULL;
  246. }
  247. hRetRes = GetStrProperty(pObj, L"GUID", &m_szGUID);
  248. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  249. m_szParentObjPath = new TCHAR[wcslen(pszParentObjPath)+1];
  250. MY_ASSERT(m_szParentObjPath); if (!m_szParentObjPath) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  251. wcscpy(m_szParentObjPath, pszParentObjPath);
  252. m_pParentDG = pParentDG;
  253. hRetRes = CoCreateGuid(&guid);
  254. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  255. StringFromGUID2(guid, m_szStatusGUID, 100);
  256. hRetRes = g_pStartupSystem->AddPointerToMasterList(this);
  257. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  258. }
  259. else
  260. {
  261. m_lIntervalCount = -1;
  262. }
  263. MY_OUTPUT2(L"m_szGUID=%s", m_szGUID, 4);
  264. // Get the Name. If it is NULL or rather blank, then we use the qualifier
  265. hRetRes = GetStrProperty(pObj, L"Name", &m_szName);
  266. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  267. // Get the Description. If it is NULL then we use the qualifier
  268. hRetRes = GetStrProperty(pObj, L"Description", &m_szDescription);
  269. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  270. hRetRes = GetStrProperty(pObj, L"TargetNamespace", &m_szTargetNamespace);
  271. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  272. hRetRes = GetStrProperty(pObj, L"Local", &m_szLocal);
  273. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  274. InitContext(pObj);
  275. hRetRes = GetUint32Property(pObj, L"CollectionIntervalMsecs", &m_lCollectionIntervalMultiple);
  276. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  277. m_lCollectionIntervalMultiple /= 1000;
  278. hRetRes = GetUint32Property(pObj, L"CollectionTimeOut", &m_lCollectionTimeOut);
  279. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  280. if (m_lCollectionIntervalMultiple < m_lCollectionTimeOut)
  281. {
  282. m_lCollectionTimeOut = m_lCollectionIntervalMultiple;
  283. }
  284. hRetRes = GetUint32Property(pObj, L"StatisticsWindowSize", &m_lStatisticsWindowSize);
  285. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  286. hRetRes = GetUint8Property(pObj, L"ActiveDays", &m_iActiveDays);
  287. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  288. // The time format looks as follows "********0600**.******+***"; hh is hours and mm is minutes
  289. // All else is ignored.
  290. hRetRes = GetStrProperty(pObj, L"BeginTime", &pszTemp);
  291. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  292. pszStr = wcschr(pszTemp, '.');
  293. if (pszStr)
  294. {
  295. // Back up to look at the minute
  296. pszStr -= 2;
  297. *pszStr = '\0';
  298. pszStr -= 2;
  299. m_lBeginMinuteTime= _wtol(pszStr);
  300. // Back up to look at the hour
  301. *pszStr = '\0';
  302. pszStr -= 2;
  303. m_lBeginHourTime= _wtol(pszStr);
  304. }
  305. else
  306. {
  307. //XXXBad format, default to something
  308. m_lBeginMinuteTime= -1;
  309. m_lBeginHourTime= -1;
  310. }
  311. delete [] pszTemp;
  312. hRetRes = GetStrProperty(pObj, L"EndTime", &pszTemp);
  313. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  314. pszStr = wcschr(pszTemp, '.');
  315. if (pszStr)
  316. {
  317. // Back up to look at the minute
  318. pszStr -= 2;
  319. *pszStr = '\0';
  320. pszStr -= 2;
  321. m_lEndMinuteTime= _wtol(pszStr);
  322. // Back up to look at the hour
  323. *pszStr = '\0';
  324. pszStr -= 2;
  325. m_lEndHourTime= _wtol(pszStr);
  326. }
  327. else
  328. {
  329. //XXXBad format, default to something
  330. m_lEndMinuteTime= -1;
  331. m_lEndHourTime= -1;
  332. }
  333. delete [] pszTemp;
  334. hRetRes = GetStrProperty(pObj, L"TypeGUID", &m_szTypeGUID);
  335. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  336. hRetRes = GetBoolProperty(pObj, L"RequireReset", &m_bRequireReset);
  337. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  338. hRetRes = GetBoolProperty(pObj, L"Enabled", &m_bEnabled);
  339. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  340. hRetRes = GetStrProperty(pObj, L"Message", &m_szMessage);
  341. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  342. hRetRes = GetStrProperty(pObj, L"ResetMessage", &m_szResetMessage);
  343. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  344. //
  345. // Now load all the Thresholds that are children of this one.
  346. //
  347. if (bModifyPass == FALSE)
  348. {
  349. if (m_bEnabled==FALSE || m_pParentDG->m_bEnabled==FALSE || m_pParentDG->m_bParentEnabled==FALSE)
  350. {
  351. if (m_pParentDG->m_bEnabled==FALSE || m_pParentDG->m_bParentEnabled==FALSE)
  352. m_bParentEnabled = FALSE;
  353. // Since our parent is disabled, we will not be able to get into
  354. // our OnAgentInterval function and send the disabled status later.
  355. SetCurrState(HM_DISABLED);
  356. FireEvent(TRUE);
  357. }
  358. hRetRes = InternalizeThresholds();
  359. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  360. }
  361. else
  362. {
  363. //
  364. // Set our state to enabled, or disabled and transfer to the child thresholds
  365. //
  366. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  367. {
  368. iSize = m_thresholdList.size();
  369. for (i=0; i < iSize; i++)
  370. {
  371. MY_ASSERT(i<m_thresholdList.size());
  372. pThreshold = m_thresholdList[i];
  373. pThreshold->SetParentEnabledFlag(FALSE);
  374. }
  375. }
  376. else
  377. {
  378. iSize = m_thresholdList.size();
  379. for (i=0; i < iSize; i++)
  380. {
  381. MY_ASSERT(i<m_thresholdList.size());
  382. pThreshold = m_thresholdList[i];
  383. pThreshold->SetParentEnabledFlag(TRUE);
  384. }
  385. }
  386. }
  387. // Setup what is needed to track statistics on each property listed
  388. // (Need to do this after the Thresholds are read in, because we may
  389. // need to insert some properties that were not in the list)
  390. hRetRes = InitPropertyStatus(pObj);
  391. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  392. //
  393. // Do any initialization stuff now
  394. //
  395. // Get the pointer to the namespace used in this DataCollector
  396. hRetRes = fillInNamespacePointer();
  397. if (hRetRes != WBEM_E_INVALID_NAMESPACE)
  398. {
  399. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  400. }
  401. m_ulErrorCode = 0;
  402. m_ulErrorCodePrev = MAX_ULONG;
  403. m_bValidLoad = TRUE;
  404. //XXXXX
  405. #ifdef SAVE
  406. //static count = 0;
  407. if (count==3 || count==4 || count==5 || count==6 || count==11)
  408. {
  409. count++;
  410. hRetRes = WBEM_E_OUT_OF_MEMORY;
  411. goto error;
  412. }
  413. else
  414. {
  415. count++;
  416. }
  417. #endif
  418. MY_OUTPUT(L"EXIT ***** CDataCollector::LoadInstanceFromMOF...", 4);
  419. return S_OK;
  420. error:
  421. MY_ASSERT(FALSE);
  422. m_bValidLoad = FALSE;
  423. Cleanup(FALSE);
  424. return hRetRes;
  425. }
  426. HRESULT CDataCollector::InternalizeThresholds(void)
  427. {
  428. TCHAR szTemp[1024];
  429. HRESULT hRetRes = S_OK;
  430. ULONG uReturned;
  431. BSTR Language = NULL;
  432. BSTR Query = NULL;
  433. IWbemClassObject *pObj = NULL;
  434. IEnumWbemClassObject *pEnum = NULL;
  435. LPTSTR pszTempGUID = NULL;
  436. MY_OUTPUT(L"ENTER ***** CDataCollector::InternalizeThresholds...", 4);
  437. // Just loop through all top level Thresholds associated with the DataCollector.
  438. // Call a method of each, and have the Threshold load itself.
  439. Language = SysAllocString(L"WQL");
  440. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  441. wcscpy(szTemp, L"ASSOCIATORS OF {MicrosoftHM_DataCollectorConfiguration.GUID=\"");
  442. lstrcat(szTemp, m_szGUID);
  443. lstrcat(szTemp, L"\"} WHERE ResultClass=MicrosoftHM_ThresholdConfiguration");
  444. Query = SysAllocString(szTemp);
  445. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  446. // Issue query
  447. hRetRes = g_pIWbemServices->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY, 0, &pEnum);
  448. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  449. SysFreeString(Query);
  450. Query = NULL;
  451. SysFreeString(Language);
  452. Language = NULL;
  453. // Retrieve objects in result set
  454. while (TRUE)
  455. {
  456. pObj = NULL;
  457. uReturned = 0;
  458. hRetRes = pEnum->Next(0, 1, &pObj, &uReturned);
  459. MY_ASSERT(hRetRes==S_OK || hRetRes==WBEM_S_FALSE);
  460. if (hRetRes!=S_OK && hRetRes!=WBEM_S_FALSE)
  461. {
  462. MY_HRESASSERT(hRetRes);
  463. pEnum->Release();
  464. pEnum = NULL;
  465. return hRetRes;
  466. }
  467. if (uReturned == 0)
  468. {
  469. break;
  470. }
  471. // See if this is already read in. Need to prevent endless loop, circular references.
  472. hRetRes = GetStrProperty(pObj, L"GUID", &pszTempGUID);
  473. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  474. if (!g_pStartupSystem->FindPointerFromGUIDInMasterList(pszTempGUID))
  475. {
  476. //
  477. // Create the internal class to represent the Threshold
  478. //
  479. CThreshold* pThreshold = new CThreshold;
  480. MY_ASSERT(pThreshold); if (!pThreshold) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  481. if (m_deType == HM_PGDE)
  482. {
  483. wcscpy(szTemp, L"MicrosoftHM_PolledGetObjectDataCollectorConfiguration.GUID=\\\"");
  484. }
  485. else if (m_deType == HM_PMDE)
  486. {
  487. wcscpy(szTemp, L"MicrosoftHM_PolledMethodDataCollectorConfiguration.GUID=\\\"");
  488. }
  489. else if (m_deType == HM_PQDE)
  490. {
  491. wcscpy(szTemp, L"MicrosoftHM_PolledQueryDataCollectorConfiguration.GUID=\\\"");
  492. }
  493. else if (m_deType == HM_EQDE)
  494. {
  495. wcscpy(szTemp, L"MicrosoftHM_EventQueryDataCollectorConfiguration.GUID=\\\"");
  496. }
  497. else
  498. {
  499. MY_ASSERT(FALSE);
  500. }
  501. lstrcat(szTemp, m_szGUID);
  502. lstrcat(szTemp, L"\\\"");
  503. hRetRes = pThreshold->LoadInstanceFromMOF(pObj, this, szTemp);
  504. if (hRetRes==S_OK)
  505. {
  506. m_thresholdList.push_back(pThreshold);
  507. }
  508. else
  509. {
  510. MY_HRESASSERT(hRetRes);
  511. delete pThreshold;
  512. }
  513. }
  514. delete [] pszTempGUID;
  515. pszTempGUID = NULL;
  516. // Release it.
  517. pObj->Release();
  518. pObj = NULL;
  519. }
  520. // All done
  521. pEnum->Release();
  522. pEnum = NULL;
  523. MY_OUTPUT(L"EXIT ***** CDataCollector::InternalizeThresholds...", 4);
  524. return S_OK;
  525. error:
  526. MY_ASSERT(FALSE);
  527. if (Query)
  528. SysFreeString(Query);
  529. if (Language)
  530. SysFreeString(Language);
  531. if (pszTempGUID)
  532. delete [] pszTempGUID;
  533. if (pObj)
  534. pObj->Release();
  535. if (pEnum)
  536. pEnum->Release();
  537. m_bValidLoad = FALSE;
  538. Cleanup(FALSE);
  539. return hRetRes;
  540. }
  541. //
  542. // Create an array element for each property we are interested
  543. //
  544. BOOL CDataCollector::InitContext(IWbemClassObject* pObj)
  545. {
  546. BOOL bRetValue = TRUE;
  547. #ifdef SAVE
  548. HRESULT hRes;
  549. HRESULT hRetRes;
  550. VARIANT v;
  551. VARIANT vValue;
  552. IUnknown* vUnknown;
  553. IWbemClassObject* pCO;
  554. BSTR bstrPropName = NULL;
  555. long iLBound, iUBound;
  556. LPTSTR szName;
  557. LPTSTR szValue;
  558. long lType;
  559. VariantInit(&v);
  560. bstrPropName = SysAllocString(L"Context");
  561. if ((hRes = pObj->Get(bstrPropName, 0L, &v, NULL, NULL)) == S_OK)
  562. {
  563. if (V_VT(&v)==VT_NULL)
  564. {
  565. // MY_ASSERT(FALSE);
  566. }
  567. else
  568. {
  569. MY_ASSERT(V_VT(&v)==(VT_UNKNOWN|VT_ARRAY));
  570. SafeArrayGetLBound(v.parray, 1, &iLBound);
  571. SafeArrayGetUBound(v.parray, 1, &iUBound);
  572. if ((iUBound - iLBound + 1) == 0)
  573. {
  574. MY_ASSERT(FALSE);
  575. }
  576. else
  577. {
  578. for (long i = iLBound; i <= iUBound; i++)
  579. {
  580. if (m_pContext == NULL)
  581. {
  582. hRes = CoCreateInstance(CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER,
  583. IID_IWbemContext, (void **)&m_pContext);
  584. if (S_OK != hRes)
  585. {
  586. MY_HRESASSERT(hRes);
  587. }
  588. }
  589. VariantInit(&vValue);
  590. vUnknown = NULL;
  591. SafeArrayGetElement(v.parray, &i, &vUnknown);
  592. pCO = (IWbemClassObject *)vUnknown;
  593. hRetRes = GetStrProperty(pCO, L"Name", &szName);
  594. MY_HRESASSERT(hRetRes);
  595. hRetRes = GetUint32Property(pCO, L"Type", &lType);
  596. MY_HRESASSERT(hRetRes);
  597. hRetRes = GetStrProperty(pCO, L"Value", &szValue);
  598. MY_HRESASSERT(hRetRes);
  599. //
  600. // Set the name value pair into the IWbemContext object
  601. //
  602. if (lType == CIM_SINT8 ||
  603. lType == CIM_SINT16 ||
  604. lType == CIM_CHAR16)
  605. {
  606. V_VT(&vValue) = VT_I2;
  607. V_I2(&vValue) = _wtol(szValue);
  608. }
  609. else if (lType == CIM_SINT32 ||
  610. lType == CIM_UINT16 ||
  611. lType == CIM_UINT32)
  612. {
  613. V_VT(&vValue) = VT_I4;
  614. V_I4(&vValue) = _wtol(szValue);
  615. }
  616. else if (lType == CIM_REAL32)
  617. {
  618. V_VT(&vValue) = VT_R4;
  619. V_R4(&vValue) = wcstod(szValue, NULL);
  620. }
  621. else if (lType == CIM_BOOLEAN)
  622. {
  623. V_VT(&vValue) = VT_BOOL;
  624. V_BOOL(&vValue) = (BOOL) _wtol(szValue);
  625. }
  626. else if (lType == CIM_SINT64 ||
  627. lType == CIM_UINT64 ||
  628. //XXX lType == CIM_REF ||
  629. lType == CIM_STRING ||
  630. lType == CIM_DATETIME)
  631. {
  632. V_VT(&vValue) = VT_BSTR;
  633. V_BSTR(&vValue) = SysAllocString(szValue);
  634. }
  635. else if (lType == CIM_REAL64)
  636. {
  637. V_VT(&vValue) = VT_R8;
  638. V_R8(&vValue) = wcstod(szValue, NULL);
  639. }
  640. else if (lType == CIM_UINT8)
  641. {
  642. V_VT(&vValue) = VT_UI1;
  643. V_UI1(&vValue) = (unsigned char) _wtoi(szValue);
  644. }
  645. else
  646. {
  647. MY_ASSERT(FALSE);
  648. }
  649. hRes = m_pContext->SetValue(szName, 0L, &vValue);
  650. if (S_OK != hRes)
  651. {
  652. MY_HRESASSERT(hRes);
  653. }
  654. VariantClear(&vValue);
  655. delete [] szName;
  656. delete [] szValue;
  657. vUnknown->Release();
  658. }
  659. }
  660. }
  661. }
  662. else
  663. {
  664. bRetValue = FALSE;
  665. MY_HRESASSERT(hRes);
  666. }
  667. VariantClear(&v);
  668. SysFreeString(bstrPropName);
  669. #endif
  670. MY_OUTPUT(L"EXIT ***** GetStrProperty...", 1);
  671. return bRetValue;
  672. }
  673. //
  674. // Create an array element for each property we are interested
  675. //
  676. HRESULT CDataCollector::InitPropertyStatus(IWbemClassObject* pObj)
  677. {
  678. HRESULT hRetRes = S_OK;
  679. VARIANT v;
  680. BSTR vStr = NULL;
  681. BOOL bFound = FALSE;
  682. long iLBound, iUBound;
  683. PNSTRUCT pn;
  684. int i, iSize;
  685. CThreshold* pThreshold;
  686. pn.szPropertyName = NULL;
  687. pn.iRefCount = 1;
  688. pn.type = 0;
  689. VariantInit(&v);
  690. if ((hRetRes = pObj->Get(L"Properties", 0L, &v, NULL, NULL)) == S_OK)
  691. {
  692. if (V_VT(&v)==VT_NULL)
  693. {
  694. }
  695. else
  696. {
  697. MY_ASSERT(V_VT(&v)==(VT_BSTR|VT_ARRAY));
  698. hRetRes = SafeArrayGetLBound(v.parray, 1, &iLBound);
  699. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  700. hRetRes = SafeArrayGetUBound(v.parray, 1, &iUBound);
  701. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  702. if ((iUBound - iLBound + 1) == 0)
  703. {
  704. }
  705. else
  706. {
  707. for (long i = iLBound; i <= iUBound; i++)
  708. {
  709. vStr = NULL;
  710. hRetRes = SafeArrayGetElement(v.parray, &i, &vStr);
  711. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  712. if (_wcsicmp(vStr, L"CollectionInstanceCount") &&
  713. _wcsicmp(vStr, L"CollectionErrorCode") &&
  714. _wcsicmp(vStr, L"CollectionErrorDescription"))
  715. {
  716. pn.szPropertyName = new TCHAR[wcslen(vStr)+2];
  717. MY_ASSERT(pn.szPropertyName); if (!pn.szPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  718. wcscpy(pn.szPropertyName, vStr);
  719. m_pnList.push_back(pn);
  720. }
  721. SysFreeString(vStr);
  722. vStr = NULL;
  723. }
  724. }
  725. }
  726. }
  727. else
  728. {
  729. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  730. }
  731. VariantClear(&v);
  732. //
  733. // Insert all the properties used by Thresholds, that are not found in the list yet.
  734. // Refcount those that are in there already.
  735. //
  736. iSize = m_thresholdList.size();
  737. for (i=0; i < iSize; i++)
  738. {
  739. MY_ASSERT(i<m_thresholdList.size());
  740. pThreshold = m_thresholdList[i];
  741. if (_wcsicmp(pThreshold->m_szPropertyName, L"CollectionInstanceCount") &&
  742. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorCode") &&
  743. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorDescription"))
  744. {
  745. hRetRes = insertNewProperty(pThreshold->m_szPropertyName);
  746. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  747. }
  748. }
  749. pn.szPropertyName = new TCHAR[wcslen(L"CollectionInstanceCount")+2];
  750. MY_ASSERT(pn.szPropertyName); if (!pn.szPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  751. wcscpy(pn.szPropertyName, L"CollectionInstanceCount");
  752. m_pnList.push_back(pn);
  753. pn.szPropertyName = new TCHAR[wcslen(L"CollectionErrorCode")+2];
  754. MY_ASSERT(pn.szPropertyName); if (!pn.szPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  755. wcscpy(pn.szPropertyName, L"CollectionErrorCode");
  756. m_pnList.push_back(pn);
  757. pn.szPropertyName = new TCHAR[wcslen(L"CollectionErrorDescription")+2];
  758. MY_ASSERT(pn.szPropertyName); if (!pn.szPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  759. wcscpy(pn.szPropertyName, L"CollectionErrorDescription");
  760. m_pnList.push_back(pn);
  761. return hRetRes;
  762. error:
  763. MY_ASSERT(FALSE);
  764. // VariantClear(&v);
  765. // if (pn.szPropertyName)
  766. // pn.szPropertyName = NULL;
  767. if (vStr)
  768. SysFreeString(vStr);
  769. m_bValidLoad = FALSE;
  770. Cleanup(FALSE);
  771. return hRetRes;
  772. }
  773. //
  774. // This is the entry point for the Agents base 10 second timer. At this time we
  775. // Have each DataCollector and Threshold do its job.
  776. //
  777. BOOL CDataCollector::OnAgentInterval(void)
  778. {
  779. int i, iSize;
  780. long lIntervalCountTemp;
  781. CThreshold* pThreshold;
  782. BOOL bTimeOK;
  783. MY_OUTPUT(L"ENTER ***** CDataCollector::OnAgentInterval...", 1);
  784. //
  785. // Don't do anything if we are not loaded correctly.
  786. // Or, if a Threshold is having problems.
  787. //
  788. if (m_bValidLoad == FALSE)
  789. return FALSE;
  790. iSize = m_thresholdList.size();
  791. for (i = 0; i < iSize ; i++)
  792. {
  793. MY_ASSERT(i<m_thresholdList.size());
  794. pThreshold = m_thresholdList[i];
  795. if (pThreshold->m_bValidLoad == FALSE)
  796. return FALSE;
  797. }
  798. m_lPrevState = m_lCurrState;
  799. m_lNumberChanges = 0;
  800. m_szErrorDescription[0] = '\0';
  801. // Remember that the DISABLED state overrides SCHEDULEDOUT.
  802. if ((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState==HM_DISABLED)
  803. {
  804. return TRUE;
  805. }
  806. //
  807. // Make sure that we are in a valid time to run.
  808. //
  809. bTimeOK = checkTime();
  810. if (bTimeOK==FALSE && m_lCurrState==HM_SCHEDULEDOUT && m_bEnabled && m_bParentEnabled)
  811. {
  812. return TRUE;
  813. }
  814. else if ((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState!=HM_DISABLED ||
  815. bTimeOK==FALSE && m_lCurrState!=HM_SCHEDULEDOUT)
  816. {
  817. //
  818. // Going into Scheduled Outage OR DISABLED.
  819. // What if we are going from ScheduledOut to Disabled?
  820. // Or from Disabled to ScheduledOut?
  821. // Possible transitions:
  822. // GOOD -> Disabled
  823. // GOOD -> ScheduledOut
  824. // Disabled -> ScheduledOut
  825. // ScheduledOut -> Disabled
  826. //
  827. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  828. {
  829. //
  830. // This is where we are transitioning into the DISABLED State
  831. //
  832. EnumDone();
  833. if (m_lPrevState == HM_SCHEDULEDOUT)
  834. {
  835. iSize = m_thresholdList.size();
  836. for (i = 0; i < iSize; i++)
  837. {
  838. MY_ASSERT(i<m_thresholdList.size());
  839. pThreshold = m_thresholdList[i];
  840. pThreshold->SetParentScheduledOutFlag(FALSE);
  841. }
  842. }
  843. iSize = m_thresholdList.size();
  844. for (i = 0; i < iSize; i++)
  845. {
  846. MY_ASSERT(i<m_thresholdList.size());
  847. pThreshold = m_thresholdList[i];
  848. pThreshold->SetParentEnabledFlag(FALSE);
  849. }
  850. m_lCurrState = HM_DISABLED;
  851. CDataCollector::EvaluateThresholds(FALSE);
  852. m_lNumberChanges = 1;
  853. m_lIntervalCount = -1;
  854. FireEvent(FALSE);
  855. }
  856. else
  857. {
  858. //
  859. // This is where we are transitioning into the SCHEDULEDOUT State
  860. //
  861. EnumDone();
  862. iSize = m_thresholdList.size();
  863. for (i = 0; i < iSize; i++)
  864. {
  865. MY_ASSERT(i<m_thresholdList.size());
  866. pThreshold = m_thresholdList[i];
  867. pThreshold->SetParentScheduledOutFlag(TRUE);
  868. }
  869. m_lCurrState = HM_SCHEDULEDOUT;
  870. CDataCollector::EvaluateThresholds(FALSE);
  871. m_lNumberChanges = 1;
  872. m_lIntervalCount = -1;
  873. FireEvent(FALSE);
  874. }
  875. return TRUE;
  876. }
  877. #ifdef SAVE
  878. else if (m_lCurrState==HM_DISABLED || m_lCurrState==HM_SCHEDULEDOUT)
  879. {
  880. What was in action.cpp
  881. //
  882. // Comming out of Scheduled Outage OR DISABLED.
  883. // Might be going from ScheduledOut/Disabled to Disabled,
  884. // or disabled to ScheduledOut.
  885. //
  886. m_lCurrState = HM_GOOD;
  887. FireEvent(-1, NULL, HMRES_ACTION_ENABLE);
  888. }
  889. #endif
  890. else
  891. {
  892. if (m_lPrevState == HM_SCHEDULEDOUT)
  893. {
  894. iSize = m_thresholdList.size();
  895. for (i = 0; i < iSize; i++)
  896. {
  897. MY_ASSERT(i<m_thresholdList.size());
  898. pThreshold = m_thresholdList[i];
  899. pThreshold->SetParentScheduledOutFlag(FALSE);
  900. }
  901. }
  902. if (m_lPrevState == HM_DISABLED)
  903. {
  904. iSize = m_thresholdList.size();
  905. for (i = 0; i < iSize; i++)
  906. {
  907. MY_ASSERT(i<m_thresholdList.size());
  908. pThreshold = m_thresholdList[i];
  909. pThreshold->SetParentEnabledFlag(TRUE);
  910. }
  911. }
  912. //
  913. // We are either beginning a Collection, or in the middle of one
  914. //
  915. m_lIntervalCount++;
  916. if (m_bKeepCollectingSemiSync == FALSE)
  917. {
  918. //
  919. // Here is where we need to fire an event in advance, because we are going to be in the
  920. // collecting state until we have retrieved something, or in the case of the event based
  921. // data collector, we reach the end of the collection interval.
  922. //
  923. if (m_lIntervalCount==0 || m_lIntervalCount==1)
  924. {
  925. m_lCurrState = HM_COLLECTING;
  926. m_lPrevState = m_lCurrState;
  927. iSize = m_thresholdList.size();
  928. for (i = 0; i < iSize ; i++)
  929. {
  930. MY_ASSERT(i<m_thresholdList.size());
  931. pThreshold = m_thresholdList[i];
  932. pThreshold->SetCurrState(HM_COLLECTING);
  933. }
  934. iSize = m_thresholdList.size();
  935. for (i=0; i < iSize; i++)
  936. {
  937. MY_ASSERT(i<m_thresholdList.size());
  938. pThreshold = m_thresholdList[i];
  939. pThreshold->FireEvent(TRUE);
  940. }
  941. FireEvent(TRUE);
  942. //
  943. // In order to smooth out the CPU utilization of the HealthMon Agent,
  944. // random offset each Data Collector.
  945. //
  946. if (m_lCollectionIntervalMultiple != 0)
  947. {
  948. if (m_lIntervalCount==1)
  949. {
  950. m_lIntervalCount = rand()%m_lCollectionIntervalMultiple;
  951. if (m_lIntervalCount == 0)
  952. m_lIntervalCount++;
  953. }
  954. else
  955. {
  956. // This case we have been forced to forego the random, and do immediate
  957. m_lIntervalCount = 1;
  958. }
  959. }
  960. }
  961. //
  962. // Beginning a Collection
  963. // Check to see if this is at an interval that we need to run at.
  964. //
  965. if ((m_lCollectionIntervalMultiple == 0) ||
  966. (m_lIntervalCount!=1 && (m_lIntervalCount-1)%m_lCollectionIntervalMultiple))
  967. {
  968. return TRUE;
  969. }
  970. CollectInstance();
  971. //
  972. // Optomized, for when we know we have not recieved any events during the interval
  973. //
  974. if (m_bKeepCollectingSemiSync)
  975. {
  976. // This is for the case where this Data Collector might have been the only
  977. // reason for the parent data group to be in a CRITICAL state, and now, because
  978. // We do not push up the COLLECTING state, the data group might miss the change.
  979. if (m_lCurrState==HM_COLLECTING && m_lPrevState!=m_lCurrState)
  980. {
  981. m_lNumberChanges++;
  982. }
  983. return TRUE;
  984. }
  985. }
  986. else
  987. {
  988. //
  989. // Means that we still have not received all the instance(s) back yet!
  990. // Keep trying to collect the instance until the TimeOut has expired!
  991. // Also watch for when the next interval has been reached and we still have not
  992. // received the instance!
  993. //
  994. m_lCollectionTimeOutCount++;
  995. CollectInstanceSemiSync();
  996. if (m_bKeepCollectingSemiSync)
  997. {
  998. // Check to see if we are over the TimeOut period.
  999. if (m_lCollectionTimeOutCount == m_lCollectionTimeOut)
  1000. {
  1001. if (m_ulErrorCode != HMRES_TIMEOUT)
  1002. {
  1003. lIntervalCountTemp = m_lIntervalCount;
  1004. ResetState(FALSE, FALSE);
  1005. m_lIntervalCount = lIntervalCountTemp;
  1006. }
  1007. else
  1008. {
  1009. EnumDone();
  1010. }
  1011. MY_ASSERT(FALSE);
  1012. m_ulErrorCode = HMRES_TIMEOUT;
  1013. GetLatestAgentError(HMRES_TIMEOUT, m_szErrorDescription);
  1014. StoreStandardProperties();
  1015. }
  1016. else
  1017. {
  1018. // This is the case where we just return, and keep trying to collect
  1019. return TRUE;
  1020. }
  1021. }
  1022. }
  1023. //
  1024. // We have made it to this point because we have received all of the instance(s)
  1025. //
  1026. //
  1027. // Evaluate the instance(s) property(s) against the threshold(s).
  1028. // In the case of evnt based data collector, we do not have any events to look at
  1029. // at the start, but need to wait for the end of the interval.
  1030. //
  1031. if (m_deType!=HM_EQDE || (m_deType==HM_EQDE && (m_lIntervalCount!=1 || m_ulErrorCode!=0)))
  1032. {
  1033. wcscpy(m_szDTCollectTime, m_szDTCurrTime);
  1034. wcscpy(m_szCollectTime, m_szCurrTime);
  1035. EvaluateThresholds(FALSE, TRUE, FALSE, FALSE);
  1036. if (m_deType!=HM_EQDE)
  1037. {
  1038. EvaluateThresholds(FALSE, FALSE, TRUE, FALSE);
  1039. }
  1040. }
  1041. // Event data collector will have called to send their own event
  1042. if (m_deType!=HM_EQDE)
  1043. {
  1044. SendEvents();
  1045. FireStatisticsEvent();
  1046. }
  1047. // To sync up prev and curr states for those cases that could keep producing events
  1048. if (m_ulErrorCode != 0)
  1049. {
  1050. iSize = m_thresholdList.size();
  1051. for (i = 0; i < iSize ; i++)
  1052. {
  1053. MY_ASSERT(i<m_thresholdList.size());
  1054. pThreshold = m_thresholdList[i];
  1055. pThreshold->SetPrevState(HM_CRITICAL);
  1056. }
  1057. }
  1058. }
  1059. if (m_deType == HM_EQDE)
  1060. {
  1061. m_lNumInstancesCollected = 0;
  1062. }
  1063. iSize = m_thresholdList.size();
  1064. for (i = 0; i < iSize ; i++)
  1065. {
  1066. MY_ASSERT(i<m_thresholdList.size());
  1067. pThreshold = m_thresholdList[i];
  1068. if (pThreshold->m_bValidLoad == FALSE)
  1069. {
  1070. MY_ASSERT(FALSE);
  1071. m_bValidLoad = FALSE;
  1072. Cleanup(FALSE);
  1073. break;
  1074. }
  1075. }
  1076. m_ulErrorCodePrev = m_ulErrorCode;
  1077. MY_OUTPUT(L"EXIT ***** CDataCollector::OnAgentInterval...", 1);
  1078. return TRUE;
  1079. }
  1080. BOOL CDataCollector::SendEvents(void)
  1081. {
  1082. int i, iSize;
  1083. long state;
  1084. CThreshold* pThreshold;
  1085. long lCurrChildCount = 0;
  1086. if (m_bValidLoad == FALSE)
  1087. return FALSE;
  1088. //
  1089. // See if any Thresholds were set into the RESET state,
  1090. // This causes the DataCollector to set all Thresholds to the GOOD state, and
  1091. // re-evaluate all thresholds.
  1092. //
  1093. //XXXWith this in we can implement the RESET feature, but we still need to debug fully,
  1094. CheckForReset();
  1095. //
  1096. // Set State of the DataCollector to the worst of everything under it
  1097. //
  1098. m_lNumberNormals = 0;
  1099. m_lNumberWarnings = 0;
  1100. m_lNumberCriticals = 0;
  1101. m_lNumberChanges = 0;
  1102. iSize = m_thresholdList.size();
  1103. lCurrChildCount = iSize;
  1104. if (iSize != 0)
  1105. {
  1106. m_lCurrState = -1;
  1107. for (i = 0; i < iSize ; i++)
  1108. {
  1109. MY_ASSERT(i<m_thresholdList.size());
  1110. pThreshold = m_thresholdList[i];
  1111. state = pThreshold->GetCurrState();
  1112. MY_OUTPUT2(L"State=%d", state, 4);
  1113. if (state > m_lCurrState)
  1114. {
  1115. m_lCurrState = state;
  1116. }
  1117. if (state == HM_GOOD)
  1118. {
  1119. m_lNumberNormals++;
  1120. }
  1121. if (state == HM_WARNING)
  1122. {
  1123. m_lNumberWarnings++;
  1124. }
  1125. if (state == HM_CRITICAL)
  1126. {
  1127. m_lNumberCriticals++;
  1128. }
  1129. if (pThreshold->GetChange())
  1130. {
  1131. MY_OUTPUT(L"CHANGE", 4);
  1132. m_lNumberChanges++;
  1133. }
  1134. }
  1135. // The disabled state of things below us did not roll up
  1136. if (m_lCurrState==HM_DISABLED)
  1137. {
  1138. m_lCurrState = HM_GOOD;
  1139. if (m_lPrevState != m_lCurrState)
  1140. {
  1141. m_lNumberChanges++;
  1142. }
  1143. }
  1144. if (m_lCurrState == -1)
  1145. {
  1146. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  1147. {
  1148. m_lCurrState = HM_DISABLED;
  1149. }
  1150. else
  1151. {
  1152. m_lCurrState = HM_GOOD;
  1153. }
  1154. if (m_lPrevState != m_lCurrState)
  1155. {
  1156. m_lNumberChanges = 1;
  1157. }
  1158. }
  1159. }
  1160. else
  1161. {
  1162. m_lCurrState = HM_GOOD;
  1163. if (m_lPrevState != m_lCurrState)
  1164. {
  1165. m_lNumberChanges = 1;
  1166. }
  1167. }
  1168. // Finally if all else fails, and we have a DE that is RESET required, and we have an INIT
  1169. // state, then set things to GOOD
  1170. if (m_bRequireReset && m_lCurrState == HM_COLLECTING)
  1171. {
  1172. m_lNumberChanges = 0;
  1173. iSize = m_thresholdList.size();
  1174. for (i = 0; i < iSize; i++)
  1175. {
  1176. MY_ASSERT(i<m_thresholdList.size());
  1177. pThreshold = m_thresholdList[i];
  1178. pThreshold->SetCurrState(HM_GOOD);
  1179. if (pThreshold->GetChange())
  1180. {
  1181. m_lNumberChanges++;
  1182. }
  1183. }
  1184. m_lCurrState = HM_GOOD;
  1185. }
  1186. if (m_lPrevChildCount!=lCurrChildCount)
  1187. {
  1188. if (m_lNumberChanges==0 && m_lPrevState!=m_lCurrState)
  1189. {
  1190. m_lNumberChanges++;
  1191. }
  1192. }
  1193. m_lPrevChildCount = lCurrChildCount;
  1194. FireEvent(FALSE);
  1195. FirePerInstanceEvents();
  1196. return TRUE;
  1197. }
  1198. //
  1199. // If there has been a change in the state then send an event
  1200. //
  1201. HRESULT CDataCollector::FireEvent(BOOL bForce)
  1202. {
  1203. HRESULT hRetRes = S_OK;
  1204. IWbemClassObject* pInstance = NULL;
  1205. GUID guid;
  1206. HRESULT hRes;
  1207. MY_OUTPUT(L"ENTER ***** CDataCollector::FireEvent...", 2);
  1208. // Don't send if no-one is listening!
  1209. if (g_pDataCollectorEventSink == NULL)
  1210. {
  1211. return S_OK;
  1212. }
  1213. MY_OUTPUT2(L"m_lPrevState=%d", m_lPrevState, 4);
  1214. MY_OUTPUT2(L"m_lCurrState=%d", m_lCurrState, 4);
  1215. MY_OUTPUT2(L"m_lNumberChanges=%d", m_lNumberChanges, 4);
  1216. // A quick test to see if anything has really changed!
  1217. // Proceed if there have been changes
  1218. if (bForce || (m_lNumberChanges!=0 && m_lPrevState!=m_lCurrState))
  1219. {
  1220. }
  1221. else
  1222. {
  1223. return FALSE;
  1224. }
  1225. MY_OUTPUT2(L"EVENT: DataCollector State Change=%d", m_lCurrState, 4);
  1226. // Proceed if there have been changes
  1227. // yyyymmddhhmmss.ssssssXUtc; X = GMT(+ or -), Utc = 3 dig. offset from UTC.")]
  1228. wcscpy(m_szDTTime, m_szDTCurrTime);
  1229. wcscpy(m_szTime, m_szCurrTime);
  1230. hRetRes = CoCreateGuid(&guid);
  1231. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1232. StringFromGUID2(guid, m_szStatusGUID, 100);
  1233. hRes = GetHMDataCollectorStatusInstance(&pInstance, TRUE);
  1234. if (FAILED(hRes))
  1235. {
  1236. MY_HRESASSERT(hRes);
  1237. MY_OUTPUT(L"failed to get instance!", 1);
  1238. return FALSE;
  1239. }
  1240. else
  1241. {
  1242. //
  1243. // Place Extrinsit event in vector for sending at end of interval.
  1244. // All get sent at once.
  1245. //
  1246. mg_DCEventList.push_back(pInstance);
  1247. }
  1248. MY_OUTPUT(L"EXIT ***** CDataCollector::FireEvent...", 2);
  1249. return hRetRes;
  1250. error:
  1251. MY_ASSERT(FALSE);
  1252. m_bValidLoad = FALSE;
  1253. Cleanup(FALSE);
  1254. return hRetRes;
  1255. }
  1256. //
  1257. // Send out events for each instance that has had a change of state.
  1258. // The state of each will be the worst of all.
  1259. //
  1260. BOOL CDataCollector::FirePerInstanceEvents(void)
  1261. {
  1262. long state;
  1263. int i, iSize;
  1264. BOOL bRetValue = TRUE;
  1265. IWbemClassObject* pInstance = NULL;
  1266. ACTUALINSTSTRUCT *pActualInst;
  1267. long firstInstanceState = -1;
  1268. MY_OUTPUT(L"ENTER ***** CDataCollector::FirePerInstanceEvents...", 2);
  1269. // Don't send if no-one is listening!
  1270. if (g_pDataCollectorPerInstanceEventSink == NULL)
  1271. {
  1272. return bRetValue;
  1273. }
  1274. //
  1275. // We can loop through the set of collected instances and ask each Threshold
  1276. // to tell us if the state has changed as far as each is concerned, for the
  1277. // property they are lookin at.
  1278. //
  1279. iSize = m_actualInstList.size();
  1280. for (i=0; i < iSize; i++)
  1281. {
  1282. MY_ASSERT(i<m_actualInstList.size());
  1283. pActualInst = &m_actualInstList[i];
  1284. if ((state=PassBackStateIfChangedPerInstance(pActualInst->szInstanceID, (BOOL)i==0))!=-1)
  1285. {
  1286. if (i==0)
  1287. {
  1288. firstInstanceState = state;
  1289. }
  1290. // Update time since we had a state change
  1291. wcscpy(pActualInst->szDTTime, m_szDTCurrTime);
  1292. wcscpy(pActualInst->szTime, m_szCurrTime);
  1293. if (GetHMDataCollectorPerInstanceStatusEvent(pActualInst->szInstanceID, pActualInst, state, &pInstance, TRUE)==S_OK)
  1294. {
  1295. //
  1296. // Place Extrinsit event in vector for sending at end of interval.
  1297. // All get sent at once.
  1298. //
  1299. mg_DCPerInstanceEventList.push_back(pInstance);
  1300. }
  1301. }
  1302. }
  1303. //
  1304. // Do it for the three default properties
  1305. //
  1306. if (firstInstanceState==-1 && (state=PassBackStateIfChangedPerInstance(L"CollectionInstanceCount", FALSE))!=-1)
  1307. {
  1308. // Update time since we had a state change
  1309. wcscpy(m_szDTCICTime, m_szDTCurrTime);
  1310. wcscpy(m_szCICTime, m_szCurrTime);
  1311. if (GetHMDataCollectorPerInstanceStatusEvent(L"CollectionInstanceCount", NULL, state, &pInstance, TRUE)==S_OK)
  1312. {
  1313. //
  1314. // Place Extrinsit event in vector for sending at end of interval.
  1315. // All get sent at once.
  1316. //
  1317. mg_DCPerInstanceEventList.push_back(pInstance);
  1318. }
  1319. }
  1320. if (firstInstanceState==-1 && (state=PassBackStateIfChangedPerInstance(L"CollectionErrorCode", FALSE))!=-1)
  1321. {
  1322. // Update time since we had a state change
  1323. wcscpy(m_szDTCECTime, m_szDTCurrTime);
  1324. wcscpy(m_szCECTime, m_szCurrTime);
  1325. if (GetHMDataCollectorPerInstanceStatusEvent(L"CollectionErrorCode", NULL, state, &pInstance, TRUE)==S_OK)
  1326. {
  1327. //
  1328. // Place Extrinsit event in vector for sending at end of interval.
  1329. // All get sent at once.
  1330. //
  1331. mg_DCPerInstanceEventList.push_back(pInstance);
  1332. }
  1333. }
  1334. MY_OUTPUT(L"EXIT ***** CDataCollector::FirePerInstanceEvents...", 2);
  1335. return TRUE;
  1336. }
  1337. long CDataCollector::PassBackStateIfChangedPerInstance(LPTSTR pszInstName, BOOL bCombineWithStandardProperties)
  1338. {
  1339. int i, iSize;
  1340. long worstState, state;
  1341. CThreshold* pThreshold;
  1342. worstState = -1;
  1343. iSize = m_thresholdList.size();
  1344. for (i=0; i < iSize; i++)
  1345. {
  1346. MY_ASSERT(i<m_thresholdList.size());
  1347. pThreshold = m_thresholdList[i];
  1348. state = pThreshold->PassBackStateIfChangedPerInstance(pszInstName);
  1349. if (state != -1)
  1350. {
  1351. if (state==HM_DISABLED)
  1352. {
  1353. state = HM_GOOD;
  1354. }
  1355. if (state > worstState)
  1356. {
  1357. worstState = state;
  1358. }
  1359. }
  1360. }
  1361. if (bCombineWithStandardProperties)
  1362. {
  1363. iSize = m_thresholdList.size();
  1364. for (i=0; i < iSize; i++)
  1365. {
  1366. MY_ASSERT(i<m_thresholdList.size());
  1367. pThreshold = m_thresholdList[i];
  1368. state = pThreshold->PassBackStateIfChangedPerInstance(L"CollectionInstanceCount");
  1369. if (state != -1)
  1370. {
  1371. if (state==HM_DISABLED)
  1372. {
  1373. state = HM_GOOD;
  1374. }
  1375. if (state > worstState)
  1376. {
  1377. worstState = state;
  1378. }
  1379. }
  1380. state = pThreshold->PassBackStateIfChangedPerInstance(L"CollectionErrorCode");
  1381. if (state != -1)
  1382. {
  1383. if (state==HM_DISABLED)
  1384. {
  1385. state = HM_GOOD;
  1386. }
  1387. if (state > worstState)
  1388. {
  1389. worstState = state;
  1390. }
  1391. }
  1392. }
  1393. }
  1394. // May have had one Threshold go from CRITICAL to GOOD and have a change, while another
  1395. // Threshold was WARNING and stayed WARNING with no change, so need to go there.
  1396. if (worstState != -1)
  1397. {
  1398. iSize = m_thresholdList.size();
  1399. for (i=0; i < iSize; i++)
  1400. {
  1401. MY_ASSERT(i<m_thresholdList.size());
  1402. pThreshold = m_thresholdList[i];
  1403. state = pThreshold->PassBackWorstStatePerInstance(pszInstName);
  1404. if (state != -1)
  1405. {
  1406. if (state==HM_DISABLED)
  1407. {
  1408. state = HM_GOOD;
  1409. }
  1410. if (state > worstState)
  1411. {
  1412. worstState = state;
  1413. }
  1414. }
  1415. }
  1416. if (bCombineWithStandardProperties)
  1417. {
  1418. iSize = m_thresholdList.size();
  1419. for (i=0; i < iSize; i++)
  1420. {
  1421. MY_ASSERT(i<m_thresholdList.size());
  1422. pThreshold = m_thresholdList[i];
  1423. state = pThreshold->PassBackWorstStatePerInstance(L"CollectionInstanceCount");
  1424. if (state != -1)
  1425. {
  1426. if (state==HM_DISABLED)
  1427. {
  1428. state = HM_GOOD;
  1429. }
  1430. if (state > worstState)
  1431. {
  1432. worstState = state;
  1433. }
  1434. }
  1435. state = pThreshold->PassBackWorstStatePerInstance(L"CollectionErrorCode");
  1436. if (state != -1)
  1437. {
  1438. if (state==HM_DISABLED)
  1439. {
  1440. state = HM_GOOD;
  1441. }
  1442. if (state > worstState)
  1443. {
  1444. worstState = state;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. }
  1450. return worstState;
  1451. }
  1452. long CDataCollector::PassBackWorstStatePerInstance(LPTSTR pszInstName, BOOL bCombineWithStandardProperties)
  1453. {
  1454. int i, iSize;
  1455. long worstState, state;
  1456. CThreshold* pThreshold;
  1457. worstState = -1;
  1458. iSize = m_thresholdList.size();
  1459. for (i=0; i < iSize; i++)
  1460. {
  1461. MY_ASSERT(i<m_thresholdList.size());
  1462. pThreshold = m_thresholdList[i];
  1463. state = pThreshold->PassBackWorstStatePerInstance(pszInstName);
  1464. if (state != -1)
  1465. {
  1466. if (state==HM_DISABLED)
  1467. {
  1468. state = HM_GOOD;
  1469. }
  1470. if (state > worstState)
  1471. {
  1472. worstState = state;
  1473. }
  1474. }
  1475. }
  1476. if (bCombineWithStandardProperties)
  1477. {
  1478. iSize = m_thresholdList.size();
  1479. for (i=0; i < iSize; i++)
  1480. {
  1481. MY_ASSERT(i<m_thresholdList.size());
  1482. pThreshold = m_thresholdList[i];
  1483. state = pThreshold->PassBackWorstStatePerInstance(L"CollectionInstanceCount");
  1484. if (state != -1)
  1485. {
  1486. if (state==HM_DISABLED)
  1487. {
  1488. state = HM_GOOD;
  1489. }
  1490. if (state > worstState)
  1491. {
  1492. worstState = state;
  1493. }
  1494. }
  1495. state = pThreshold->PassBackWorstStatePerInstance(L"CollectionErrorCode");
  1496. if (state != -1)
  1497. {
  1498. if (state==HM_DISABLED)
  1499. {
  1500. state = HM_GOOD;
  1501. }
  1502. if (state > worstState)
  1503. {
  1504. worstState = state;
  1505. }
  1506. }
  1507. }
  1508. }
  1509. return worstState;
  1510. }
  1511. // Only Send statistics information on a change
  1512. BOOL CDataCollector::FireStatisticsEvent(void)
  1513. {
  1514. BOOL bRetValue = TRUE;
  1515. if (m_bValidLoad == FALSE)
  1516. return FALSE;
  1517. MY_OUTPUT(L"ENTER ***** CDataCollector::FireStatisticsEvent...", 2);
  1518. // Don't send if no-one is listening!
  1519. if (g_pDataCollectorStatisticsEventSink == NULL)
  1520. {
  1521. return bRetValue;
  1522. }
  1523. MY_OUTPUT2(L"Someone listening for statistics GUID=%s", m_szGUID, 4);
  1524. fillInPropertyStatus(m_szDTCurrTime, m_szCurrTime);
  1525. MY_OUTPUT(L"EXIT ***** CDataCollector::FireStatisticsEvent...", 2);
  1526. return bRetValue;
  1527. }
  1528. BOOL CDataCollector::fillInPropertyStatus(LPTSTR szDTTime, LPTSTR szTime)
  1529. {
  1530. MY_ASSERT(FALSE);
  1531. //Not used anymore!
  1532. return TRUE;
  1533. }
  1534. //
  1535. // Store the values for the properties that we care about.
  1536. //
  1537. BOOL CDataCollector::StoreValues(IWbemClassObject* pObj, LPTSTR pszInstID)
  1538. {
  1539. HRESULT hRetRes = S_OK;
  1540. int i, iSize;
  1541. int j, jSize;
  1542. PNSTRUCT *ppn;
  1543. INSTSTRUCT *pinst;
  1544. HRESULT hRes;
  1545. VARIANT v;
  1546. BOOL bRetValue = TRUE;
  1547. BOOL bFirstType = FALSE;
  1548. BOOL bFound;
  1549. CThreshold* pThreshold;
  1550. VariantInit(&v);
  1551. if (m_bValidLoad == FALSE)
  1552. return FALSE;
  1553. MY_OUTPUT(L"ENTER ***** CDataCollector::StoreValues...", 1);
  1554. //
  1555. // LOOP through all the properties we are suppose to collect data for into the instance(s).
  1556. // If the type is set to 0 in the PropertyStat struct, then we know that it
  1557. // is the first time we have seen this instance, so set it!
  1558. //
  1559. iSize = m_pnList.size();
  1560. if (pObj)
  1561. {
  1562. for (i=0; i < iSize-3; i++)
  1563. {
  1564. MY_ASSERT(i<m_pnList.size());
  1565. ppn = &m_pnList[i];
  1566. bFound = FALSE;
  1567. jSize = ppn->instList.size();
  1568. for (j = 0; j < jSize ; j++)
  1569. {
  1570. MY_ASSERT(j<ppn->instList.size());
  1571. pinst = &ppn->instList[j];
  1572. if (!_wcsicmp(pinst->szInstanceID, pszInstID))
  1573. {
  1574. bFound = TRUE;
  1575. break;
  1576. }
  1577. }
  1578. MY_ASSERT(bFound == TRUE);
  1579. if (bFound == TRUE)
  1580. {
  1581. if (!_wcsicmp(ppn->szPropertyName, L"CollectionInstanceCount") ||
  1582. !_wcsicmp(ppn->szPropertyName, L"CollectionErrorCode") ||
  1583. !_wcsicmp(ppn->szPropertyName, L"CollectionErrorDescription"))
  1584. {
  1585. // Don't do for the these properties
  1586. continue;
  1587. }
  1588. // Get the data from the perfmon property
  1589. VariantInit(&v);
  1590. if (ppn->type == 0)
  1591. {
  1592. bFirstType = TRUE;
  1593. }
  1594. if ((hRes = pObj->Get(ppn->szPropertyName, 0L, &v, &ppn->type, NULL)) == S_OK)
  1595. {
  1596. MY_OUTPUT(L"Property Get worked", 3);
  1597. if (bFirstType)
  1598. {
  1599. ResetInst(pinst, ppn->type);
  1600. }
  1601. if (V_VT(&v)==VT_NULL)
  1602. {
  1603. MY_OUTPUT(L"NULL TYPE", 3);
  1604. if (pinst->szCurrValue)
  1605. {
  1606. delete [] pinst->szCurrValue;
  1607. pinst->szCurrValue = NULL;
  1608. }
  1609. if (ppn->type == CIM_STRING)
  1610. {
  1611. pinst->szCurrValue = new TCHAR[5];
  1612. MY_ASSERT(pinst->szCurrValue); if (!pinst->szCurrValue) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1613. wcscpy(pinst->szCurrValue , L"");
  1614. }
  1615. pinst->bNull = TRUE;
  1616. }
  1617. else
  1618. {
  1619. // We are going from collecting NULL to actually getting something
  1620. if (bFirstType==FALSE && pinst->bNull==TRUE)
  1621. {
  1622. m_lCurrState = HM_COLLECTING;
  1623. jSize = m_thresholdList.size();
  1624. for (j=0; j<jSize; j++)
  1625. {
  1626. MY_ASSERT(j<m_thresholdList.size());
  1627. pThreshold = m_thresholdList[j];
  1628. pThreshold->SetCurrState(HM_COLLECTING);
  1629. }
  1630. }
  1631. pinst->bNull = FALSE;
  1632. if (V_VT(&v)==VT_R4)
  1633. {
  1634. pinst->currValue.fValue = V_R4(&v);
  1635. MY_ASSERT(ppn->type == CIM_REAL32);
  1636. }
  1637. else if (V_VT(&v)==VT_R8)
  1638. {
  1639. pinst->currValue.dValue = V_R8(&v);
  1640. MY_ASSERT(ppn->type == CIM_REAL64);
  1641. }
  1642. else if (V_VT(&v)==VT_I2)
  1643. {
  1644. pinst->currValue.lValue = (long) V_I2(&v);
  1645. }
  1646. else if (V_VT(&v)==VT_I4)
  1647. {
  1648. if (ppn->type == CIM_UINT32)
  1649. {
  1650. pinst->currValue.ulValue = V_UI4(&v);
  1651. }
  1652. else
  1653. {
  1654. pinst->currValue.lValue = (long) V_I4(&v);
  1655. }
  1656. }
  1657. // else if (V_VT(&v)==VT_UI4)
  1658. // {
  1659. // pinst->currValue.ulValue = (long) V_UI4(&v);
  1660. // }
  1661. else if (V_VT(&v)==VT_UI1)
  1662. {
  1663. pinst->currValue.lValue = (long) V_UI1(&v);
  1664. }
  1665. else if (V_VT(&v)==VT_BOOL)
  1666. {
  1667. pinst->currValue.lValue = (long) V_BOOL(&v);
  1668. if (pinst->currValue.lValue != 0.0)
  1669. {
  1670. pinst->currValue.lValue = 1.0;
  1671. }
  1672. }
  1673. else if (V_VT(&v)==VT_BSTR)
  1674. {
  1675. if (ppn->type == CIM_SINT64)
  1676. {
  1677. pinst->currValue.i64Value = _wtoi64(V_BSTR(&v));
  1678. }
  1679. else if (ppn->type == CIM_UINT64)
  1680. {
  1681. pinst->currValue.ui64Value = 0;
  1682. ReadUI64(V_BSTR(&v), pinst->currValue.ui64Value);
  1683. }
  1684. else
  1685. {
  1686. ppn->type = CIM_STRING;
  1687. if (pinst->szCurrValue)
  1688. {
  1689. delete [] pinst->szCurrValue;
  1690. }
  1691. pinst->szCurrValue = new TCHAR[wcslen(V_BSTR(&v))+2];
  1692. MY_ASSERT(pinst->szCurrValue); if (!pinst->szCurrValue) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1693. wcscpy(pinst->szCurrValue , V_BSTR(&v));
  1694. }
  1695. }
  1696. else
  1697. {
  1698. // If for example we had a VT_BSTR | VT_ARRAY would we end up here?
  1699. // We need to do something to detect arrays, and assert, or handle them???
  1700. MY_OUTPUT(L"UNKNOWN DATA TYPE", 3);
  1701. ppn->type = CIM_STRING;
  1702. if (pinst->szCurrValue)
  1703. {
  1704. delete [] pinst->szCurrValue;
  1705. }
  1706. pinst->szCurrValue = new TCHAR[8];
  1707. MY_ASSERT(pinst->szCurrValue); if (!pinst->szCurrValue) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1708. wcscpy(pinst->szCurrValue , L"UNKNOWN");
  1709. }
  1710. }
  1711. //
  1712. // Update the min,max and average values
  1713. //
  1714. if (ppn->type != CIM_STRING)
  1715. {
  1716. CalcStatistics(pinst, ppn->type);
  1717. }
  1718. }
  1719. else
  1720. {
  1721. m_ulErrorCode = hRes;
  1722. GetLatestWMIError(HMRES_BADDCPROP, hRes, m_szErrorDescription);
  1723. wcscat(m_szErrorDescription, L" ");
  1724. wcscat(m_szErrorDescription, ppn->szPropertyName);
  1725. bRetValue = FALSE;
  1726. MY_OUTPUT2(L"Couldn't Get instance property=%s", ppn->szPropertyName, 4);
  1727. }
  1728. VariantClear(&v);
  1729. }
  1730. }
  1731. }
  1732. else
  1733. {
  1734. if (!_wcsicmp(pszInstID, L"CollectionInstanceCount"))
  1735. {
  1736. i = iSize-3;
  1737. }
  1738. else if (!_wcsicmp(pszInstID, L"CollectionErrorCode"))
  1739. {
  1740. i = iSize-2;
  1741. }
  1742. else if (!_wcsicmp(pszInstID, L"CollectionErrorDescription"))
  1743. {
  1744. i = iSize-1;
  1745. }
  1746. else
  1747. {
  1748. MY_ASSERT(FALSE);
  1749. i = iSize-3;
  1750. }
  1751. MY_ASSERT(i<m_pnList.size());
  1752. ppn = &m_pnList[i];
  1753. bFound = FALSE;
  1754. jSize = ppn->instList.size();
  1755. for (j = 0; j < jSize ; j++)
  1756. {
  1757. MY_ASSERT(j<ppn->instList.size());
  1758. pinst = &ppn->instList[j];
  1759. if (!_wcsicmp(pinst->szInstanceID, pszInstID))
  1760. {
  1761. bFound = TRUE;
  1762. break;
  1763. }
  1764. }
  1765. MY_ASSERT(bFound == TRUE);
  1766. if (bFound == TRUE)
  1767. {
  1768. //
  1769. // Case where this is the special number of instances property!
  1770. //
  1771. if (!_wcsicmp(pszInstID, L"CollectionInstanceCount"))
  1772. {
  1773. ppn->type = CIM_UINT32;
  1774. pinst->currValue.ulValue = m_lNumInstancesCollected;
  1775. CalcStatistics(pinst, ppn->type);
  1776. }
  1777. else if (!_wcsicmp(pszInstID, L"CollectionErrorCode"))
  1778. {
  1779. ppn->type = CIM_UINT32;
  1780. pinst->currValue.ulValue = m_ulErrorCode;
  1781. CalcStatistics(pinst, ppn->type);
  1782. }
  1783. else if (!_wcsicmp(pszInstID, L"CollectionErrorDescription"))
  1784. {
  1785. ppn->type = CIM_STRING;
  1786. if (pinst->szCurrValue)
  1787. {
  1788. delete [] pinst->szCurrValue;
  1789. }
  1790. pinst->szCurrValue = new TCHAR[wcslen(m_szErrorDescription)+2];
  1791. MY_ASSERT(pinst->szCurrValue); if (!pinst->szCurrValue) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1792. wcscpy(pinst->szCurrValue , m_szErrorDescription);
  1793. }
  1794. else
  1795. {
  1796. MY_ASSERT(FALSE);
  1797. }
  1798. }
  1799. }
  1800. MY_OUTPUT(L"EXIT ***** CDataCollector::StoreValues...", 1);
  1801. return bRetValue;
  1802. error:
  1803. MY_ASSERT(FALSE);
  1804. m_ulErrorCode = HMRES_NOMEMORY;
  1805. GetLatestAgentError(HMRES_NOMEMORY, m_szErrorDescription);
  1806. m_bValidLoad = FALSE;
  1807. Cleanup(FALSE);
  1808. return FALSE;
  1809. }
  1810. BOOL CDataCollector::StoreStandardProperties(void)
  1811. {
  1812. HRESULT hRetRes;
  1813. if (m_bValidLoad == FALSE)
  1814. return FALSE;
  1815. //
  1816. // Set the standard properties
  1817. //
  1818. hRetRes = CheckInstanceExistance(NULL, L"CollectionInstanceCount");
  1819. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1820. StoreValues(NULL, L"CollectionInstanceCount");
  1821. CheckInstanceExistance(NULL, L"CollectionErrorCode");
  1822. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1823. StoreValues(NULL, L"CollectionErrorCode");
  1824. CheckInstanceExistance(NULL, L"CollectionErrorDescription");
  1825. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1826. StoreValues(NULL, L"CollectionErrorDescription");
  1827. return TRUE;
  1828. error:
  1829. MY_ASSERT(FALSE);
  1830. m_ulErrorCode = hRetRes;
  1831. GetLatestWMIError(HMRES_OBJECTNOTFOUND, hRetRes, m_szErrorDescription);
  1832. m_bValidLoad = FALSE;
  1833. Cleanup(FALSE);
  1834. return FALSE;
  1835. }
  1836. BOOL CDataCollector::CalcStatistics(INSTSTRUCT *pinst, CIMTYPE type)
  1837. {
  1838. int i;
  1839. int iSize;
  1840. VALSTRUCT val;
  1841. VALSTRUCT *pval;
  1842. VALLIST::iterator iaVAL;
  1843. union hm_datatypes value;
  1844. if (type == CIM_STRING)
  1845. {
  1846. MY_ASSERT(FALSE);
  1847. }
  1848. else if (type == CIM_DATETIME)
  1849. {
  1850. MY_ASSERT(FALSE);
  1851. }
  1852. else if (type == CIM_REAL32)
  1853. {
  1854. if (pinst->currValue.fValue < pinst->minValue.fValue)
  1855. {
  1856. pinst->minValue.fValue = pinst->currValue.fValue;
  1857. }
  1858. if (pinst->maxValue.fValue < pinst->currValue.fValue)
  1859. {
  1860. pinst->maxValue.fValue = pinst->currValue.fValue;
  1861. }
  1862. //
  1863. // Add new value to the end.
  1864. // If we are over the limit of number of samples to keep,
  1865. // drop the oldest.
  1866. //
  1867. val.value.fValue = pinst->currValue.fValue;
  1868. pinst->valList.push_back(val);
  1869. iSize = pinst->valList.size();
  1870. if (m_lStatisticsWindowSize < iSize)
  1871. {
  1872. iaVAL=pinst->valList.begin();
  1873. pinst->valList.erase(iaVAL);
  1874. }
  1875. //
  1876. // Now calculate the average from what we have.
  1877. //
  1878. value.fValue = 0;
  1879. iSize = pinst->valList.size();
  1880. for (i = 0; i < iSize ; i++)
  1881. {
  1882. MY_ASSERT(i<pinst->valList.size());
  1883. pval = &pinst->valList[i];
  1884. value.fValue += pval->value.fValue;
  1885. }
  1886. if (i==0)
  1887. pinst->avgValue.fValue = value.fValue;
  1888. else
  1889. pinst->avgValue.fValue = value.fValue/i;
  1890. }
  1891. else if (type == CIM_REAL64)
  1892. {
  1893. if (pinst->currValue.dValue < pinst->minValue.dValue)
  1894. {
  1895. pinst->minValue.dValue = pinst->currValue.dValue;
  1896. }
  1897. if (pinst->maxValue.dValue < pinst->currValue.dValue)
  1898. {
  1899. pinst->maxValue.dValue = pinst->currValue.dValue;
  1900. }
  1901. //
  1902. // Add new value to the end.
  1903. // If we are over the limit of number of samples to keep,
  1904. // drop the oldest.
  1905. //
  1906. val.value.dValue = pinst->currValue.dValue;
  1907. pinst->valList.push_back(val);
  1908. iSize = pinst->valList.size();
  1909. if (m_lStatisticsWindowSize < iSize)
  1910. {
  1911. iaVAL=pinst->valList.begin();
  1912. pinst->valList.erase(iaVAL);
  1913. }
  1914. //
  1915. // Now calculate the average from what we have.
  1916. //
  1917. value.dValue = 0;
  1918. iSize = pinst->valList.size();
  1919. for (i = 0; i < iSize ; i++)
  1920. {
  1921. MY_ASSERT(i<pinst->valList.size());
  1922. pval = &pinst->valList[i];
  1923. value.dValue += pval->value.dValue;
  1924. }
  1925. if (i==0)
  1926. pinst->avgValue.dValue = value.dValue;
  1927. else
  1928. pinst->avgValue.dValue = value.dValue/i;
  1929. }
  1930. else if (type == CIM_SINT64)
  1931. {
  1932. if (pinst->currValue.i64Value < pinst->minValue.i64Value)
  1933. {
  1934. pinst->minValue.i64Value = pinst->currValue.i64Value;
  1935. }
  1936. if (pinst->maxValue.i64Value < pinst->currValue.i64Value)
  1937. {
  1938. pinst->maxValue.i64Value = pinst->currValue.i64Value;
  1939. }
  1940. //
  1941. // Add new value to the end.
  1942. // If we are over the limit of number of samples to keep,
  1943. // drop the oldest.
  1944. //
  1945. val.value.i64Value = pinst->currValue.i64Value;
  1946. pinst->valList.push_back(val);
  1947. iSize = pinst->valList.size();
  1948. if (m_lStatisticsWindowSize < iSize)
  1949. {
  1950. iaVAL=pinst->valList.begin();
  1951. pinst->valList.erase(iaVAL);
  1952. }
  1953. //
  1954. // Now calculate the average from what we have.
  1955. //
  1956. value.i64Value = 0;
  1957. iSize = pinst->valList.size();
  1958. for (i = 0; i < iSize ; i++)
  1959. {
  1960. MY_ASSERT(i<pinst->valList.size());
  1961. pval = &pinst->valList[i];
  1962. value.i64Value += pval->value.i64Value;
  1963. }
  1964. if (i==0)
  1965. pinst->avgValue.i64Value = value.i64Value;
  1966. else
  1967. pinst->avgValue.i64Value = value.i64Value/i;
  1968. }
  1969. else if (type == CIM_UINT64)
  1970. {
  1971. if (pinst->currValue.ui64Value < pinst->minValue.ui64Value)
  1972. {
  1973. pinst->minValue.ui64Value = pinst->currValue.ui64Value;
  1974. }
  1975. if (pinst->maxValue.ui64Value < pinst->currValue.ui64Value)
  1976. {
  1977. pinst->maxValue.ui64Value = pinst->currValue.ui64Value;
  1978. }
  1979. //
  1980. // Add new value to the end.
  1981. // If we are over the limit of number of samples to keep,
  1982. // drop the oldest.
  1983. //
  1984. val.value.ui64Value = pinst->currValue.ui64Value;
  1985. pinst->valList.push_back(val);
  1986. iSize = pinst->valList.size();
  1987. if (m_lStatisticsWindowSize < iSize)
  1988. {
  1989. iaVAL=pinst->valList.begin();
  1990. pinst->valList.erase(iaVAL);
  1991. }
  1992. //
  1993. // Now calculate the average from what we have.
  1994. //
  1995. value.ui64Value = 0;
  1996. iSize = pinst->valList.size();
  1997. for (i = 0; i < iSize ; i++)
  1998. {
  1999. MY_ASSERT(i<pinst->valList.size());
  2000. pval = &pinst->valList[i];
  2001. value.ui64Value += pval->value.ui64Value;
  2002. }
  2003. if (i==0)
  2004. pinst->avgValue.ui64Value = value.ui64Value;
  2005. else
  2006. pinst->avgValue.ui64Value = value.ui64Value/i;
  2007. }
  2008. else if (type == CIM_UINT32)
  2009. {
  2010. // Must be an integer type
  2011. if (pinst->currValue.ulValue < pinst->minValue.ulValue)
  2012. {
  2013. pinst->minValue.ulValue = pinst->currValue.ulValue;
  2014. }
  2015. if (pinst->maxValue.ulValue < pinst->currValue.ulValue)
  2016. {
  2017. pinst->maxValue.ulValue = pinst->currValue.ulValue;
  2018. }
  2019. //
  2020. // Add new value to the end.
  2021. // If we are over the limit of number of samples to keep,
  2022. // drop the oldest.
  2023. //
  2024. val.value.ulValue = pinst->currValue.ulValue;
  2025. pinst->valList.push_back(val);
  2026. iSize = pinst->valList.size();
  2027. if (m_lStatisticsWindowSize < iSize)
  2028. {
  2029. iaVAL=pinst->valList.begin();
  2030. pinst->valList.erase(iaVAL);
  2031. }
  2032. //
  2033. // Now calculate the average from what we have.
  2034. //
  2035. value.ulValue = 0;
  2036. iSize = pinst->valList.size();
  2037. for (i = 0; i < iSize ; i++)
  2038. {
  2039. MY_ASSERT(i<pinst->valList.size());
  2040. pval = &pinst->valList[i];
  2041. value.ulValue += pval->value.ulValue;
  2042. }
  2043. if (i==0)
  2044. pinst->avgValue.ulValue = value.ulValue;
  2045. else
  2046. pinst->avgValue.ulValue = value.ulValue/i;
  2047. }
  2048. else
  2049. {
  2050. // Must be an integer type
  2051. if (pinst->currValue.lValue < pinst->minValue.lValue)
  2052. {
  2053. pinst->minValue.lValue = pinst->currValue.lValue;
  2054. }
  2055. if (pinst->maxValue.lValue < pinst->currValue.lValue)
  2056. {
  2057. pinst->maxValue.lValue = pinst->currValue.lValue;
  2058. }
  2059. //
  2060. // Add new value to the end.
  2061. // If we are over the limit of number of samples to keep,
  2062. // drop the oldest.
  2063. //
  2064. val.value.lValue = pinst->currValue.lValue;
  2065. pinst->valList.push_back(val);
  2066. iSize = pinst->valList.size();
  2067. if (m_lStatisticsWindowSize < iSize)
  2068. {
  2069. iaVAL=pinst->valList.begin();
  2070. pinst->valList.erase(iaVAL);
  2071. }
  2072. //
  2073. // Now calculate the average from what we have.
  2074. //
  2075. value.lValue = 0;
  2076. iSize = pinst->valList.size();
  2077. for (i = 0; i < iSize ; i++)
  2078. {
  2079. MY_ASSERT(i<pinst->valList.size());
  2080. pval = &pinst->valList[i];
  2081. value.lValue += pval->value.lValue;
  2082. }
  2083. if (i==0)
  2084. pinst->avgValue.lValue = value.lValue;
  2085. else
  2086. pinst->avgValue.lValue = value.lValue/i;
  2087. }
  2088. return TRUE;
  2089. }
  2090. BOOL CDataCollector::EvaluateThresholds(BOOL bIgnoreReset, BOOL bSkipStandard/*=FALSE*/, BOOL bSkipOthers/*=FALSE*/, BOOL bDoThresholdSkipClean/*=TRUE*/)
  2091. {
  2092. LPTSTR pszPropertyName;
  2093. int iSize;
  2094. int jSize;
  2095. int i;
  2096. int j;
  2097. CThreshold* pThreshold;
  2098. PNSTRUCT *ppn = NULL;
  2099. BOOL bFound = FALSE;
  2100. INSTSTRUCT *pinst;
  2101. if (m_bValidLoad == FALSE)
  2102. return FALSE;
  2103. //
  2104. // For each threshold associated with this DataCollector, find the property status
  2105. // structure, and have the threshold evaluate against the current values.
  2106. //
  2107. iSize = m_thresholdList.size();
  2108. for (i = 0; i < iSize; i++)
  2109. {
  2110. MY_ASSERT(i<m_thresholdList.size());
  2111. pThreshold = m_thresholdList[i];
  2112. if (pThreshold->m_bValidLoad == FALSE)
  2113. break;
  2114. pszPropertyName = pThreshold->GetPropertyName();
  2115. if (bSkipStandard && (!_wcsicmp(pszPropertyName, L"CollectionInstanceCount") ||
  2116. !_wcsicmp(pszPropertyName, L"CollectionErrorCode") ||
  2117. !_wcsicmp(pszPropertyName, L"CollectionErrorDescription")))
  2118. {
  2119. if (bDoThresholdSkipClean)
  2120. pThreshold->SkipClean();
  2121. continue;
  2122. }
  2123. if (bSkipOthers && (_wcsicmp(pszPropertyName, L"CollectionInstanceCount") &&
  2124. _wcsicmp(pszPropertyName, L"CollectionErrorCode") &&
  2125. _wcsicmp(pszPropertyName, L"CollectionErrorDescription")))
  2126. {
  2127. if (bDoThresholdSkipClean)
  2128. pThreshold->SkipClean();
  2129. continue;
  2130. }
  2131. jSize = m_pnList.size();
  2132. for (j = 0; j < jSize ; j++)
  2133. {
  2134. MY_ASSERT(j<m_pnList.size());
  2135. ppn = &m_pnList[j];
  2136. if (!_wcsicmp(ppn->szPropertyName, pszPropertyName))
  2137. {
  2138. bFound = TRUE;
  2139. break;
  2140. }
  2141. }
  2142. //
  2143. // If the type is still equal to zero, that means that the threshold is probably looking
  2144. // at a property that does not exist.
  2145. // Also remember that if we are transitioning to DISABLED, or SCHEDULEDOUT we need to
  2146. // go into the Threshold evaluation do disable them.
  2147. //
  2148. if ((m_lCurrState==HM_DISABLED || m_lCurrState==HM_SCHEDULEDOUT) ||
  2149. ((m_ulErrorCode==0 || (m_ulErrorCode!=0 && !wcscmp(pszPropertyName, L"CollectionErrorCode"))) &&
  2150. (bFound && ppn->type!=0)))
  2151. {
  2152. //
  2153. // Also need to watch for case where we can't do evaluation yet.
  2154. // If AVERAGE is used, then wait until full window of samples has been collected.
  2155. // If difference, then must wait for the second one.
  2156. //
  2157. if (pThreshold->m_bUseDifference)
  2158. {
  2159. if (m_lIntervalCount < 2)
  2160. {
  2161. continue;
  2162. }
  2163. }
  2164. else if (pThreshold->m_bUseAverage)
  2165. {
  2166. // Need to find out how many samples we have
  2167. MY_ASSERT(ppn);
  2168. if (ppn->instList.size())
  2169. {
  2170. pinst = &ppn->instList[0];
  2171. if (pinst->valList.size() < m_lStatisticsWindowSize)
  2172. {
  2173. continue;
  2174. }
  2175. }
  2176. else
  2177. {
  2178. }
  2179. }
  2180. // If this threshold has already been violated and the RequireReset is TRUE
  2181. // then we don't need to test for re-arm.
  2182. if (bIgnoreReset == TRUE)
  2183. {
  2184. if (pThreshold->GetCurrState() != HM_RESET)
  2185. {
  2186. pThreshold->SetCurrState(HM_COLLECTING);
  2187. pThreshold->SetBackPrev(ppn);
  2188. pThreshold->OnAgentInterval(&m_actualInstList, ppn, m_bRequireReset);
  2189. }
  2190. }
  2191. else
  2192. {
  2193. pThreshold->OnAgentInterval(&m_actualInstList, ppn, m_bRequireReset);
  2194. }
  2195. }
  2196. else
  2197. {
  2198. if (pThreshold->m_bEnabled==FALSE || pThreshold->m_bParentEnabled==FALSE || pThreshold->m_bParentScheduledOut)
  2199. {
  2200. pThreshold->OnAgentInterval(&m_actualInstList, ppn, m_bRequireReset);
  2201. }
  2202. else if (m_ulErrorCode!=0)
  2203. {
  2204. // Case where had an error in the collection process that needs to take priority.
  2205. pThreshold->SetCurrState(HM_CRITICAL, m_ulErrorCode!=m_ulErrorCodePrev, HMRES_DCUNKNOWN);
  2206. pThreshold->FireEvent(m_ulErrorCode!=m_ulErrorCodePrev);
  2207. }
  2208. else if (ppn->type==0)
  2209. {
  2210. // Having zero instances is not a crime if we are certain types of DataColectors.
  2211. if (m_lNumInstancesCollected>0)
  2212. {
  2213. // Case where the property to collect did not exist
  2214. m_ulErrorCode = HMRES_BADTHRESHPROP;
  2215. pThreshold->SetCurrState(HM_CRITICAL, m_ulErrorCode!=m_ulErrorCodePrev, HMRES_BADTHRESHPROP);
  2216. pThreshold->FireEvent(m_ulErrorCode!=m_ulErrorCodePrev);
  2217. GetLatestAgentError(HMRES_BADTHRESHPROP, m_szErrorDescription);
  2218. wcscat(m_szErrorDescription, L" ");
  2219. wcscat(m_szErrorDescription, pszPropertyName);
  2220. StoreValues(NULL, L"CollectionErrorCode");
  2221. StoreValues(NULL, L"CollectionErrorDescription");
  2222. }
  2223. else
  2224. {
  2225. pThreshold->SetCurrState(HM_GOOD, m_ulErrorCode!=m_ulErrorCodePrev, HMRES_DCUNKNOWN);
  2226. pThreshold->FireEvent(m_ulErrorCode!=m_ulErrorCodePrev);
  2227. }
  2228. }
  2229. else
  2230. {
  2231. }
  2232. }
  2233. }
  2234. return TRUE;
  2235. }
  2236. HRESULT CDataCollector::SendHMDataCollectorStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  2237. {
  2238. MY_ASSERT(pSink!=NULL);
  2239. //
  2240. // Is this the one we are looking for?
  2241. //
  2242. if (!_wcsicmp(m_szGUID, pszGUID))
  2243. {
  2244. //
  2245. // Don't do anything if we are not loaded correctly.
  2246. //
  2247. //XXX if (m_bValidLoad == FALSE)
  2248. //XXX return WBEM_E_INVALID_OBJECT;
  2249. return SendHMDataCollectorStatusInstances(pSink);
  2250. }
  2251. else
  2252. {
  2253. return WBEM_S_DIFFERENT;
  2254. }
  2255. }
  2256. HRESULT CDataCollector::SendHMDataCollectorStatusInstances(IWbemObjectSink* pSink)
  2257. {
  2258. HRESULT hRes = S_OK;
  2259. IWbemClassObject* pInstance = NULL;
  2260. MY_OUTPUT(L"ENTER ***** SendHMDataCollectorStatusInstances...", 2);
  2261. //XXX if (m_bValidLoad == FALSE)
  2262. //XXX return WBEM_E_INVALID_OBJECT;
  2263. if (pSink == NULL)
  2264. {
  2265. MY_OUTPUT(L"CDC::SendInitialHMMachStatInstances-Invalid Sink", 1);
  2266. return WBEM_E_FAILED;
  2267. }
  2268. hRes = GetHMDataCollectorStatusInstance(&pInstance, FALSE);
  2269. if (SUCCEEDED(hRes))
  2270. {
  2271. hRes = pSink->Indicate(1, &pInstance);
  2272. if (FAILED(hRes) && hRes!=WBEM_E_SERVER_TOO_BUSY && hRes!=WBEM_E_CALL_CANCELLED && hRes!=WBEM_E_TRANSPORT_FAILURE)
  2273. {
  2274. MY_OUTPUT(L"SendHMDataCollectorStatusInstances-failed to send status!", 1);
  2275. }
  2276. pInstance->Release();
  2277. pInstance = NULL;
  2278. }
  2279. else
  2280. {
  2281. MY_OUTPUT(L":SendHMDataCollectorStatusInstances-failed to get instance!", 1);
  2282. }
  2283. MY_OUTPUT(L"EXIT ***** SendHMDataCollectorStatusInstances...", 2);
  2284. return hRes;
  2285. }
  2286. HRESULT CDataCollector::SendHMDataCollectorPerInstanceStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  2287. {
  2288. MY_ASSERT(pSink!=NULL);
  2289. //
  2290. // Is this the one we are looking for?
  2291. //
  2292. if (!_wcsicmp(m_szGUID, pszGUID))
  2293. {
  2294. if (m_bValidLoad == FALSE)
  2295. return WBEM_E_INVALID_OBJECT;
  2296. return SendHMDataCollectorPerInstanceStatusInstances(pSink);
  2297. }
  2298. else
  2299. {
  2300. return WBEM_S_DIFFERENT;
  2301. }
  2302. }
  2303. // This one is for enumeration of all Instances outside of the hierarchy.
  2304. // Just the flat list.
  2305. HRESULT CDataCollector::SendHMDataCollectorPerInstanceStatusInstances(IWbemObjectSink* pSink)
  2306. {
  2307. HRESULT hRes;
  2308. long state;
  2309. int i, iSize;
  2310. BOOL bRetValue = TRUE;
  2311. IWbemClassObject* pInstance = NULL;
  2312. ACTUALINSTSTRUCT *pActualInst;
  2313. long firstInstanceState = -1;
  2314. MY_OUTPUT(L"ENTER ***** CDataCollector::SendHMDataCollectorPerInstanceStatusInstance...", 2);
  2315. if (m_bValidLoad == FALSE)
  2316. return WBEM_E_INVALID_OBJECT;
  2317. if (pSink == NULL)
  2318. {
  2319. MY_OUTPUT(L"-Invalid Sink", 1);
  2320. return WBEM_E_FAILED;
  2321. }
  2322. //
  2323. // We can loop through the set of collected instances and ask each Threshold
  2324. // to tell us if the state has changed as far as each is concerned, for the
  2325. // property they are lookin at.
  2326. //
  2327. iSize = m_actualInstList.size();
  2328. for (i=0; i < iSize; i++)
  2329. {
  2330. MY_ASSERT(i<m_actualInstList.size());
  2331. pActualInst = &m_actualInstList[i];
  2332. state = PassBackWorstStatePerInstance(pActualInst->szInstanceID, (BOOL)i==0);
  2333. if (state==-1) state = HM_COLLECTING;
  2334. if (i==0)
  2335. {
  2336. firstInstanceState = state;
  2337. }
  2338. hRes = GetHMDataCollectorPerInstanceStatusEvent(pActualInst->szInstanceID, pActualInst, state, &pInstance, FALSE);
  2339. if (SUCCEEDED(hRes))
  2340. {
  2341. hRes = pSink->Indicate(1, &pInstance);
  2342. if (FAILED(hRes) && hRes!=WBEM_E_SERVER_TOO_BUSY && hRes!=WBEM_E_CALL_CANCELLED && hRes!=WBEM_E_TRANSPORT_FAILURE)
  2343. {
  2344. MY_OUTPUT(L"SendHMDataCollectorStatusInstances-failed to send status!", 1);
  2345. }
  2346. pInstance->Release();
  2347. pInstance = NULL;
  2348. }
  2349. else
  2350. {
  2351. MY_OUTPUT(L":SendHMDataCollectorStatusInstances-failed to get instance!", 1);
  2352. }
  2353. }
  2354. //
  2355. // Do it for the three default properties
  2356. //
  2357. if (firstInstanceState==-1)
  2358. {
  2359. state = PassBackWorstStatePerInstance(L"CollectionInstanceCount", FALSE);
  2360. if (state==-1) state = HM_COLLECTING;
  2361. hRes = GetHMDataCollectorPerInstanceStatusEvent(L"CollectionInstanceCount", NULL, state, &pInstance, FALSE);
  2362. if (SUCCEEDED(hRes))
  2363. {
  2364. hRes = pSink->Indicate(1, &pInstance);
  2365. if (FAILED(hRes) && hRes!=WBEM_E_SERVER_TOO_BUSY && hRes!=WBEM_E_CALL_CANCELLED && hRes!=WBEM_E_TRANSPORT_FAILURE)
  2366. {
  2367. MY_OUTPUT(L"SendHMDataCollectorStatusInstances-failed to send status!", 1);
  2368. }
  2369. pInstance->Release();
  2370. pInstance = NULL;
  2371. }
  2372. else
  2373. {
  2374. MY_OUTPUT(L":SendHMDataCollectorStatusInstances-failed to get instance!", 1);
  2375. }
  2376. }
  2377. if (firstInstanceState==-1)
  2378. {
  2379. state = PassBackWorstStatePerInstance(L"CollectionErrorCode", FALSE);
  2380. if (state==-1) state = HM_COLLECTING;
  2381. hRes = GetHMDataCollectorPerInstanceStatusEvent(L"CollectionErrorCode", NULL, state, &pInstance, FALSE);
  2382. if (SUCCEEDED(hRes))
  2383. {
  2384. hRes = pSink->Indicate(1, &pInstance);
  2385. if (FAILED(hRes) && hRes!=WBEM_E_SERVER_TOO_BUSY && hRes!=WBEM_E_CALL_CANCELLED && hRes!=WBEM_E_TRANSPORT_FAILURE)
  2386. {
  2387. MY_OUTPUT(L"SendHMDataCollectorStatusInstances-failed to send status!", 1);
  2388. }
  2389. pInstance->Release();
  2390. pInstance = NULL;
  2391. }
  2392. else
  2393. {
  2394. MY_OUTPUT(L":SendHMDataCollectorStatusInstances-failed to get instance!", 1);
  2395. }
  2396. }
  2397. #ifdef SAVE
  2398. state = PassBackWorstStatePerInstance(L"CollectionErrorDescription");
  2399. if (state==-1) state = HM_COLLECTING;
  2400. hRes = GetHMDataCollectorPerInstanceStatusEvent(L"CollectionErrorDescription", NULL, state, &pInstance, FALSE);
  2401. if (SUCCEEDED(hRes))
  2402. {
  2403. hRes = pSink->Indicate(1, &pInstance);
  2404. if (FAILED(hRes) && hRes!=WBEM_E_SERVER_TOO_BUSY && hRes!=WBEM_E_CALL_CANCELLED && hRes!=WBEM_E_TRANSPORT_FAILURE)
  2405. {
  2406. MY_OUTPUT(L"SendHMDataCollectorStatusInstances-failed to send status!", 1);
  2407. }
  2408. pInstance->Release();
  2409. pInstance = NULL;
  2410. }
  2411. else
  2412. {
  2413. MY_OUTPUT(L":SendHMDataCollectorStatusInstances-failed to get instance!", 1);
  2414. }
  2415. #endif
  2416. MY_OUTPUT(L"EXIT ***** CDataCollector::FirePerInstanceEvents...", 2);
  2417. return S_OK;
  2418. }
  2419. HRESULT CDataCollector::SendHMDataCollectorStatisticsInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  2420. {
  2421. MY_ASSERT(pSink!=NULL);
  2422. //
  2423. // Is this the one we are looking for?
  2424. //
  2425. if (!_wcsicmp(m_szGUID, pszGUID))
  2426. {
  2427. if (m_bValidLoad == FALSE)
  2428. return WBEM_E_INVALID_OBJECT;
  2429. return SendHMDataCollectorStatisticsInstances(pSink);
  2430. }
  2431. else
  2432. {
  2433. return WBEM_S_DIFFERENT;
  2434. }
  2435. }
  2436. HRESULT CDataCollector::SendHMDataCollectorStatisticsInstances(IWbemObjectSink* pSink)
  2437. {
  2438. HRESULT hRes = S_OK;
  2439. MY_OUTPUT(L"ENTER ***** SendHMDataCollectorStatisticsInstances...", 2);
  2440. if (m_bValidLoad == FALSE)
  2441. return WBEM_E_INVALID_OBJECT;
  2442. if (pSink == NULL)
  2443. {
  2444. MY_OUTPUT(L"CDC::SendInitialHMMachStatInstances-Invalid Sink", 1);
  2445. return WBEM_E_FAILED;
  2446. }
  2447. hRes = GetHMDataCollectorStatisticsInstances(m_szDTCollectTime, m_szCollectTime);
  2448. MY_OUTPUT(L"EXIT ***** SendHMDataCollectorStatisticsInstances...", 2);
  2449. return hRes;
  2450. }
  2451. HRESULT CDataCollector::SendHMThresholdStatusInstances(IWbemObjectSink* pSink)
  2452. {
  2453. int i;
  2454. int iSize;
  2455. CThreshold *pThreshold;
  2456. PNSTRUCT *ppn = NULL;
  2457. BOOL bFound = FALSE;
  2458. MY_OUTPUT(L"ENTER ***** SendHMThresholdStatusInstances...", 1);
  2459. // Have all Thresholds of this DataCollector send their status
  2460. iSize = m_thresholdList.size();
  2461. for (i = 0; i < iSize ; i++)
  2462. {
  2463. MY_ASSERT(i<m_thresholdList.size());
  2464. pThreshold = m_thresholdList[i];
  2465. pThreshold->SendHMThresholdStatusInstances(pSink);
  2466. }
  2467. MY_OUTPUT(L"EXIT ***** SendHMThresholdStatusInstances...", 1);
  2468. return S_OK;
  2469. }
  2470. HRESULT CDataCollector::SendHMThresholdStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  2471. {
  2472. int i;
  2473. int iSize;
  2474. CThreshold *pThreshold;
  2475. PNSTRUCT *ppn = NULL;
  2476. HRESULT hRetRes = S_OK;
  2477. MY_OUTPUT(L"ENTER ***** SendHMThresholdStatusInstance...", 1);
  2478. // Try to find the one that needs sending
  2479. iSize = m_thresholdList.size();
  2480. for (i = 0; i < iSize ; i++)
  2481. {
  2482. MY_ASSERT(i<m_thresholdList.size());
  2483. pThreshold = m_thresholdList[i];
  2484. hRetRes = pThreshold->SendHMThresholdStatusInstance(pSink, pszGUID);
  2485. if (hRetRes==S_OK)
  2486. {
  2487. return S_OK;
  2488. }
  2489. else if (hRetRes!=WBEM_S_DIFFERENT)
  2490. {
  2491. return hRetRes;
  2492. }
  2493. }
  2494. MY_OUTPUT(L"EXIT ***** SendHMThresholdStatusInstance...", 1);
  2495. return WBEM_S_DIFFERENT;
  2496. }
  2497. HRESULT CDataCollector::GetHMDataCollectorStatusInstance(IWbemClassObject** ppInstance, BOOL bEventBased)
  2498. {
  2499. TCHAR szTemp[1024];
  2500. IWbemClassObject* pClass = NULL;
  2501. BSTR bsString = NULL;
  2502. HRESULT hRetRes = S_OK;
  2503. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 2;
  2504. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 2];
  2505. MY_OUTPUT(L"ENTER ***** GetHMSystemStatusInstance...", 1);
  2506. if (bEventBased)
  2507. {
  2508. bsString = SysAllocString(L"MicrosoftHM_DataCollectorStatusEvent");
  2509. MY_ASSERT(bsString); if (!bsString) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2510. }
  2511. else
  2512. {
  2513. bsString = SysAllocString(L"MicrosoftHM_DataCollectorStatus");
  2514. MY_ASSERT(bsString); if (!bsString) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2515. }
  2516. hRetRes = g_pIWbemServices->GetObject(bsString, 0L, NULL, &pClass, NULL);
  2517. SysFreeString(bsString);
  2518. bsString = NULL;
  2519. if (FAILED(hRetRes))
  2520. {
  2521. return hRetRes;
  2522. }
  2523. hRetRes = pClass->SpawnInstance(0, ppInstance);
  2524. pClass->Release();
  2525. pClass = NULL;
  2526. if (FAILED(hRetRes))
  2527. return hRetRes;
  2528. if (m_bValidLoad == FALSE)
  2529. {
  2530. hRetRes = PutStrProperty(*ppInstance, L"GUID", m_szGUID);
  2531. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2532. hRetRes = PutStrProperty(*ppInstance, L"ParentGUID", m_pParentDG->m_szGUID);
  2533. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2534. hRetRes = PutUint32Property(*ppInstance, L"State", HM_CRITICAL);
  2535. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2536. if (g_hResLib == NULL || !LoadString(g_hResLib, HMRES_DC_LOADFAIL, szTemp, 1024))
  2537. {
  2538. wcscpy(szTemp, L"Data Collector failed to load.");
  2539. }
  2540. hRetRes = PutStrProperty(*ppInstance, L"Message", szTemp);
  2541. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2542. if (GetComputerName(szComputerName, &dwNameLen))
  2543. {
  2544. hRetRes = PutStrProperty(*ppInstance, L"SystemName", szComputerName);
  2545. }
  2546. else
  2547. {
  2548. hRetRes = PutStrProperty(*ppInstance, L"SystemName", L"LocalMachine");
  2549. }
  2550. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", m_szDTTime);
  2551. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", m_szTime);
  2552. hRetRes = PutStrProperty(*ppInstance, L"Name", L"...");
  2553. }
  2554. else
  2555. {
  2556. hRetRes = PutStrProperty(*ppInstance, L"GUID", m_szGUID);
  2557. hRetRes = PutStrProperty(*ppInstance, L"ParentGUID", m_pParentDG->m_szGUID);
  2558. hRetRes = PutStrProperty(*ppInstance, L"Name", m_szName);
  2559. if (GetComputerName(szComputerName, &dwNameLen))
  2560. {
  2561. hRetRes = PutStrProperty(*ppInstance, L"SystemName", szComputerName);
  2562. }
  2563. else
  2564. {
  2565. hRetRes = PutStrProperty(*ppInstance, L"SystemName", L"LocalMachine");
  2566. }
  2567. hRetRes = PutUint32Property(*ppInstance, L"State", m_lCurrState);
  2568. hRetRes = PutUint32Property(*ppInstance, L"CollectionInstanceCount", m_lNumInstancesCollected);
  2569. hRetRes = PutUUint32Property(*ppInstance, L"CollectionErrorCode", m_ulErrorCode);
  2570. hRetRes = PutStrProperty(*ppInstance, L"CollectionErrorDescription", m_szErrorDescription);
  2571. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", m_szDTTime);
  2572. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", m_szTime);
  2573. hRetRes = PutStrProperty(*ppInstance, L"StatusGUID", m_szStatusGUID);
  2574. if (m_lCurrState==HM_SCHEDULEDOUT)
  2575. {
  2576. if (g_hResLib == NULL || !LoadString(g_hResLib, HMRES_OUTAGE, szTemp, 1024))
  2577. {
  2578. wcscpy(szTemp, L"Data Collector in Scheduled Outage State");
  2579. }
  2580. hRetRes = PutStrProperty(*ppInstance, L"Message", szTemp);
  2581. }
  2582. else if (m_lCurrState==HM_DISABLED)
  2583. {
  2584. if (g_hResLib == NULL || !LoadString(g_hResLib, HMRES_DISABLE, szTemp, 1024))
  2585. {
  2586. wcscpy(szTemp, L"Data Collector in Disabled State");
  2587. }
  2588. hRetRes = PutStrProperty(*ppInstance, L"Message", szTemp);
  2589. }
  2590. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2591. }
  2592. MY_OUTPUT(L"EXIT ***** GetHMSystemStatusInstance...", 1);
  2593. return hRetRes;
  2594. error:
  2595. MY_ASSERT(FALSE);
  2596. if (bsString)
  2597. SysFreeString(bsString);
  2598. if (pClass)
  2599. pClass->Release();
  2600. m_bValidLoad = FALSE;
  2601. Cleanup(FALSE);
  2602. return hRetRes;
  2603. }
  2604. HRESULT CDataCollector::GetHMDataCollectorStatisticsInstances(LPTSTR szDTTime, LPTSTR szTime)
  2605. {
  2606. HRESULT hRetRes = S_OK;
  2607. PNSTRUCT *ppn = NULL;
  2608. INSTSTRUCT *pinst = NULL;
  2609. int i, iSize;
  2610. int j, jSize;
  2611. TCHAR szTemp[128] = {0};
  2612. IWbemClassObject* pClass = NULL;
  2613. IWbemClassObject* pInstance = NULL;
  2614. BSTR bsString = NULL;
  2615. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 2;
  2616. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 2];
  2617. int rc = 0;
  2618. char buffer[50];
  2619. iSize = m_pnList.size();
  2620. for (i = 0; i < iSize ; i++)
  2621. {
  2622. MY_ASSERT(i<m_pnList.size());
  2623. ppn = &m_pnList[i];
  2624. jSize = ppn->instList.size();
  2625. for (j=0; j < jSize ; j++)
  2626. {
  2627. MY_ASSERT(j<ppn->instList.size());
  2628. pinst = &ppn->instList[j];
  2629. bsString = SysAllocString(L"MicrosoftHM_DataCollectorStatistics");
  2630. MY_ASSERT(bsString); if (!bsString) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2631. hRetRes = g_pIWbemServices->GetObject(bsString, 0L, NULL, &pClass, NULL);
  2632. SysFreeString(bsString);
  2633. bsString = NULL;
  2634. if (FAILED(hRetRes))
  2635. {
  2636. return hRetRes;
  2637. }
  2638. hRetRes = pClass->SpawnInstance(0, &pInstance);
  2639. pClass->Release();
  2640. pClass = NULL;
  2641. if (FAILED(hRetRes))
  2642. return hRetRes;
  2643. hRetRes = PutStrProperty(pInstance, L"GUID", m_szGUID);
  2644. if (GetComputerName(szComputerName, &dwNameLen))
  2645. {
  2646. hRetRes = PutStrProperty(pInstance, L"SystemName", szComputerName);
  2647. }
  2648. else
  2649. {
  2650. hRetRes = PutStrProperty(pInstance, L"SystemName", L"LocalMachine");
  2651. }
  2652. hRetRes = PutStrProperty(pInstance, L"PropertyName", ppn->szPropertyName);
  2653. hRetRes = PutStrProperty(pInstance, L"InstanceName", pinst->szInstanceID);
  2654. hRetRes = PutStrProperty(pInstance, L"TimeGeneratedGMT", szDTTime);
  2655. hRetRes = PutStrProperty(pInstance, L"LocalTimeFormatted", szTime);
  2656. if (pinst->bNull==TRUE)
  2657. {
  2658. hRetRes = PutStrProperty(pInstance, L"CurrentValue", L"NULL");
  2659. }
  2660. else if (ppn->type==CIM_STRING || ppn->type==CIM_DATETIME)
  2661. {
  2662. if (pinst->szCurrValue)
  2663. {
  2664. hRetRes = PutStrProperty(pInstance, L"CurrentValue", pinst->szCurrValue);
  2665. }
  2666. else
  2667. {
  2668. hRetRes = PutStrProperty(pInstance, L"CurrentValue", L"");
  2669. }
  2670. }
  2671. else if (ppn->type == CIM_REAL32)
  2672. {
  2673. _gcvt((double)pinst->currValue.fValue, 7, buffer);
  2674. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2675. szTemp[rc] = NULL;
  2676. hRetRes = PutStrProperty(pInstance, L"CurrentValue", szTemp);
  2677. }
  2678. else if (ppn->type == CIM_REAL64)
  2679. {
  2680. _gcvt(pinst->currValue.dValue, 7, buffer);
  2681. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2682. szTemp[rc] = NULL;
  2683. hRetRes = PutStrProperty(pInstance, L"CurrentValue", szTemp);
  2684. }
  2685. else if (ppn->type == CIM_SINT64)
  2686. {
  2687. _i64tow(pinst->currValue.i64Value, szTemp, 10 );
  2688. hRetRes = PutStrProperty(pInstance, L"CurrentValue", szTemp);
  2689. }
  2690. else if (ppn->type == CIM_UINT64)
  2691. {
  2692. _ui64tow(pinst->currValue.ui64Value, szTemp, 10 );
  2693. hRetRes = PutStrProperty(pInstance, L"CurrentValue", szTemp);
  2694. }
  2695. else if (ppn->type == CIM_UINT32)
  2696. {
  2697. // Must be an integer type
  2698. _ultow(pinst->currValue.ulValue, szTemp, 10 );
  2699. hRetRes = PutStrProperty(pInstance, L"CurrentValue", szTemp);
  2700. }
  2701. else
  2702. {
  2703. // Must be an integer type
  2704. _ltow(pinst->currValue.lValue, szTemp, 10 );
  2705. hRetRes = PutStrProperty(pInstance, L"CurrentValue", szTemp);
  2706. }
  2707. if (pinst->bNull==TRUE)
  2708. {
  2709. hRetRes = PutStrProperty(pInstance, L"MinValue", L"");
  2710. hRetRes = PutStrProperty(pInstance, L"MaxValue", L"");
  2711. hRetRes = PutStrProperty(pInstance, L"AvgValue", L"");
  2712. }
  2713. else if (ppn->type==CIM_STRING || ppn->type==CIM_DATETIME)
  2714. {
  2715. hRetRes = PutStrProperty(pInstance, L"MinValue", L"");
  2716. hRetRes = PutStrProperty(pInstance, L"MaxValue", L"");
  2717. hRetRes = PutStrProperty(pInstance, L"AvgValue", L"");
  2718. }
  2719. else if (ppn->type == CIM_REAL32)
  2720. {
  2721. _gcvt((double)pinst->minValue.fValue, 7, buffer);
  2722. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2723. szTemp[rc] = NULL;
  2724. hRetRes = PutStrProperty(pInstance, L"MinValue", szTemp);
  2725. _gcvt((double)pinst->maxValue.fValue, 7, buffer);
  2726. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2727. szTemp[rc] = NULL;
  2728. hRetRes = PutStrProperty(pInstance, L"MaxValue", szTemp);
  2729. _gcvt((double)pinst->avgValue.fValue, 7, buffer);
  2730. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2731. szTemp[rc] = NULL;
  2732. hRetRes = PutStrProperty(pInstance, L"AvgValue", szTemp);
  2733. }
  2734. else if (ppn->type == CIM_REAL64)
  2735. {
  2736. _gcvt(pinst->minValue.dValue, 7, buffer);
  2737. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2738. szTemp[rc] = NULL;
  2739. hRetRes = PutStrProperty(pInstance, L"MinValue", szTemp);
  2740. _gcvt(pinst->maxValue.dValue, 7, buffer);
  2741. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2742. szTemp[rc] = NULL;
  2743. hRetRes = PutStrProperty(pInstance, L"MaxValue", szTemp);
  2744. _gcvt(pinst->avgValue.dValue, 7, buffer);
  2745. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2746. szTemp[rc] = NULL;
  2747. hRetRes = PutStrProperty(pInstance, L"AvgValue", szTemp);
  2748. }
  2749. else if (ppn->type == CIM_SINT64)
  2750. {
  2751. _i64tow(pinst->minValue.i64Value, szTemp, 10 );
  2752. hRetRes = PutStrProperty(pInstance, L"MinValue", szTemp);
  2753. _i64tow(pinst->maxValue.i64Value, szTemp, 10 );
  2754. hRetRes = PutStrProperty(pInstance, L"MaxValue", szTemp);
  2755. _i64tow(pinst->avgValue.i64Value, szTemp, 10 );
  2756. hRetRes = PutStrProperty(pInstance, L"AvgValue", szTemp);
  2757. }
  2758. else if (ppn->type == CIM_UINT64)
  2759. {
  2760. _ui64tow(pinst->minValue.ui64Value, szTemp, 10 );
  2761. hRetRes = PutStrProperty(pInstance, L"MinValue", szTemp);
  2762. _ui64tow(pinst->maxValue.ui64Value, szTemp, 10 );
  2763. hRetRes = PutStrProperty(pInstance, L"MaxValue", szTemp);
  2764. _ui64tow(pinst->avgValue.ui64Value, szTemp, 10 );
  2765. hRetRes = PutStrProperty(pInstance, L"AvgValue", szTemp);
  2766. }
  2767. else if (ppn->type == CIM_UINT32)
  2768. {
  2769. // Must be an integer type
  2770. _ultow(pinst->minValue.ulValue, szTemp, 10 );
  2771. hRetRes = PutStrProperty(pInstance, L"MinValue", szTemp);
  2772. _ultow(pinst->maxValue.ulValue, szTemp, 10 );
  2773. hRetRes = PutStrProperty(pInstance, L"MaxValue", szTemp);
  2774. _ultow(pinst->avgValue.ulValue, szTemp, 10 );
  2775. hRetRes = PutStrProperty(pInstance, L"AvgValue", szTemp);
  2776. }
  2777. else
  2778. {
  2779. // Must be an integer type
  2780. _ltow(pinst->minValue.lValue, szTemp, 10 );
  2781. hRetRes = PutStrProperty(pInstance, L"MinValue", szTemp);
  2782. _ltow(pinst->maxValue.lValue, szTemp, 10 );
  2783. hRetRes = PutStrProperty(pInstance, L"MaxValue", szTemp);
  2784. _ltow(pinst->avgValue.lValue, szTemp, 10 );
  2785. hRetRes = PutStrProperty(pInstance, L"AvgValue", szTemp);
  2786. }
  2787. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2788. // If we do not have all our samples, then don't show the average yet
  2789. if (pinst->valList.size() < m_lStatisticsWindowSize)
  2790. {
  2791. hRetRes = PutStrProperty(pInstance, L"AvgValue", L"-");
  2792. }
  2793. mg_DCStatsInstList.push_back(pInstance);
  2794. }
  2795. }
  2796. return S_OK;
  2797. error:
  2798. MY_ASSERT(FALSE);
  2799. if (bsString)
  2800. SysFreeString(bsString);
  2801. if (pClass)
  2802. pClass->Release();
  2803. iSize = mg_DCStatsInstList.size();
  2804. for (i=0; i < iSize; i++)
  2805. {
  2806. MY_ASSERT(i<mg_DCStatsInstList.size());
  2807. pInstance = mg_DCStatsInstList[i];
  2808. pInstance->Release();
  2809. }
  2810. mg_DCStatsInstList.clear();
  2811. m_bValidLoad = FALSE;
  2812. Cleanup(FALSE);
  2813. return hRetRes;
  2814. }
  2815. long CDataCollector::GetCurrState(void)
  2816. {
  2817. return m_lCurrState;
  2818. }
  2819. HRESULT CDataCollector::FindAndModDataCollector(BSTR szGUID, IWbemClassObject* pObj)
  2820. {
  2821. HRESULT hRetRes = S_OK;
  2822. //
  2823. // Is this us we are looking for?
  2824. //
  2825. if (!_wcsicmp(m_szGUID, szGUID))
  2826. {
  2827. hRetRes = LoadInstanceFromMOF(pObj, NULL, L"", TRUE);
  2828. return hRetRes;
  2829. }
  2830. return WBEM_S_DIFFERENT;
  2831. }
  2832. HRESULT CDataCollector::FindAndModThreshold(BSTR szGUID, IWbemClassObject* pObj)
  2833. {
  2834. TCHAR szTemp[1024];
  2835. HRESULT hRetRes = S_OK;
  2836. int i, iSize;
  2837. CThreshold* pThreshold;
  2838. if (m_bValidLoad == FALSE)
  2839. return WBEM_E_INVALID_OBJECT;
  2840. //
  2841. // Look at Threshold of this DataDataCollector
  2842. //
  2843. iSize = m_thresholdList.size();
  2844. for (i = 0; i < iSize ; i++)
  2845. {
  2846. MY_ASSERT(i<m_thresholdList.size());
  2847. pThreshold = m_thresholdList[i];
  2848. if (pThreshold->m_bValidLoad == FALSE)
  2849. return WBEM_E_INVALID_OBJECT;
  2850. hRetRes = pThreshold->FindAndModThreshold(szGUID, pObj);
  2851. if (hRetRes==S_OK)
  2852. {
  2853. wcsncpy(szTemp, pThreshold->m_szPropertyName, 1023);
  2854. szTemp[1023] = '\0';
  2855. // Check to see if the Threshold is looking at a different property!
  2856. if (_wcsicmp(szTemp, pThreshold->m_szPropertyName))
  2857. {
  2858. if (_wcsicmp(szTemp, L"CollectionInstanceCount") &&
  2859. _wcsicmp(szTemp, L"CollectionErrorCode") &&
  2860. _wcsicmp(szTemp, L"CollectionErrorDescription"))
  2861. {
  2862. propertyNotNeeded(szTemp);
  2863. }
  2864. if (_wcsicmp(pThreshold->m_szPropertyName, L"CollectionInstanceCount") &&
  2865. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorCode") &&
  2866. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorDescription"))
  2867. {
  2868. hRetRes = insertNewProperty(pThreshold->m_szPropertyName);
  2869. if (hRetRes != S_OK)
  2870. return hRetRes;
  2871. }
  2872. }
  2873. ResetState(TRUE, TRUE);
  2874. return S_OK;
  2875. }
  2876. else if (hRetRes!=WBEM_S_DIFFERENT)
  2877. {
  2878. MY_ASSERT(FALSE);
  2879. m_bValidLoad = FALSE;
  2880. Cleanup(FALSE);
  2881. return hRetRes;
  2882. }
  2883. }
  2884. return WBEM_S_DIFFERENT;
  2885. }
  2886. HRESULT CDataCollector::AddThreshold(BSTR szParentGUID, BSTR szChildGUID)
  2887. {
  2888. int i, iSize;
  2889. TCHAR szTemp[1024];
  2890. CThreshold* pThreshold = NULL;
  2891. IWbemClassObject *pObj = NULL;
  2892. BSTR Path = NULL;
  2893. HRESULT hRetRes;
  2894. LPTSTR pszTempGUID = NULL;
  2895. //
  2896. // Are we the parent DataGroup that we want to add under?
  2897. //
  2898. if (!_wcsicmp(m_szGUID, szParentGUID))
  2899. {
  2900. //
  2901. // First check to see if is in there already!
  2902. //
  2903. iSize = m_thresholdList.size();
  2904. for (i = 0; i < iSize ; i++)
  2905. {
  2906. MY_ASSERT(i<m_thresholdList.size());
  2907. pThreshold = m_thresholdList[i];
  2908. if (!_wcsicmp(szChildGUID, pThreshold->GetGUID()))
  2909. {
  2910. return S_OK;
  2911. }
  2912. }
  2913. //
  2914. // Add in the Threshold
  2915. //
  2916. wcscpy(szTemp, L"MicrosoftHM_ThresholdConfiguration.GUID=\"");
  2917. lstrcat(szTemp, szChildGUID);
  2918. lstrcat(szTemp, L"\"");
  2919. Path = SysAllocString(szTemp);
  2920. MY_ASSERT(Path); if (!Path) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2921. hRetRes = GetWbemObjectInst(&g_pIWbemServices, Path, NULL, &pObj);
  2922. if (!pObj)
  2923. {
  2924. SysFreeString(Path);
  2925. Path = NULL;
  2926. return hRetRes;
  2927. }
  2928. TCHAR msgbuf[1024];
  2929. wsprintf(msgbuf, L"ASSOCIATION: Threshold to DataCollector ParentDCGUID=%s ChildTGUID=%s", szParentGUID, szChildGUID);
  2930. MY_OUTPUT(msgbuf, 4);
  2931. // See if this is already read in. Need to prevent endless loop, circular references.
  2932. hRetRes = GetStrProperty(pObj, L"GUID", &pszTempGUID);
  2933. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2934. if (!g_pStartupSystem->FindPointerFromGUIDInMasterList(pszTempGUID))
  2935. {
  2936. //
  2937. // Create the internal class to represent the DataGroup
  2938. //
  2939. pThreshold = new CThreshold;
  2940. MY_ASSERT(pThreshold); if (!pThreshold) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2941. if (m_deType == HM_PGDE)
  2942. {
  2943. wcscpy(szTemp, L"MicrosoftHM_PolledGetObjectDataCollectorConfiguration.GUID=\\\"");
  2944. }
  2945. else if (m_deType == HM_PMDE)
  2946. {
  2947. wcscpy(szTemp, L"MicrosoftHM_PolledMethodDataCollectorConfiguration.GUID=\\\"");
  2948. }
  2949. else if (m_deType == HM_PQDE)
  2950. {
  2951. wcscpy(szTemp, L"MicrosoftHM_PolledQueryDataCollectorConfiguration.GUID=\\\"");
  2952. }
  2953. else if (m_deType == HM_EQDE)
  2954. {
  2955. wcscpy(szTemp, L"MicrosoftHM_EventQueryDataCollectorConfiguration.GUID=\\\"");
  2956. }
  2957. lstrcat(szTemp, m_szGUID);
  2958. lstrcat(szTemp, L"\\\"");
  2959. if (pThreshold->LoadInstanceFromMOF(pObj, this, szTemp)==S_OK)
  2960. {
  2961. if (_wcsicmp(pThreshold->m_szPropertyName, L"CollectionInstanceCount") &&
  2962. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorCode") &&
  2963. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorDescription"))
  2964. {
  2965. hRetRes = insertNewProperty(pThreshold->m_szPropertyName);
  2966. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2967. }
  2968. //
  2969. // Get Threshold and DataCollector synced up. Plus we may have been in the middle of a
  2970. // collection interval as this came in.
  2971. //
  2972. ResetState(TRUE, TRUE);
  2973. m_thresholdList.push_back(pThreshold);
  2974. }
  2975. else
  2976. {
  2977. delete pThreshold;
  2978. }
  2979. }
  2980. delete [] pszTempGUID;
  2981. pszTempGUID = NULL;
  2982. pObj->Release();
  2983. pObj = NULL;
  2984. SysFreeString(Path);
  2985. Path = NULL;
  2986. return S_OK;
  2987. }
  2988. return WBEM_S_DIFFERENT;
  2989. error:
  2990. MY_ASSERT(FALSE);
  2991. if (pszTempGUID)
  2992. delete [] pszTempGUID;
  2993. if (Path)
  2994. SysFreeString(Path);
  2995. if (pObj)
  2996. pObj->Release();
  2997. m_bValidLoad = FALSE;
  2998. Cleanup(FALSE);
  2999. return hRetRes;
  3000. }
  3001. LPTSTR CDataCollector::GetGUID(void)
  3002. {
  3003. return m_szGUID;
  3004. }
  3005. BOOL CDataCollector::ResetResetThresholdStates(void)
  3006. {
  3007. int i, iSize;
  3008. CThreshold* pThreshold;
  3009. iSize = m_thresholdList.size();
  3010. for (i = 0; i < iSize ; i++)
  3011. {
  3012. MY_ASSERT(i<m_thresholdList.size());
  3013. pThreshold = m_thresholdList[i];
  3014. pThreshold->ResetResetThreshold();
  3015. }
  3016. return TRUE;
  3017. }
  3018. BOOL CDataCollector::GetChange(void)
  3019. {
  3020. if (m_lNumberChanges!=0 && m_lPrevState!=m_lCurrState)
  3021. {
  3022. return TRUE;
  3023. }
  3024. else
  3025. {
  3026. return FALSE;
  3027. }
  3028. }
  3029. //
  3030. // Called By the Delete method that the HMSystemConfiguration class exposes.
  3031. // We search down the hierarchy until we find what we need to delete.
  3032. // We are only search down form where we are, as the object above already verified
  3033. // that we are not what was being looked for.
  3034. //
  3035. HRESULT CDataCollector::FindAndDeleteByGUID(LPTSTR pszGUID)
  3036. {
  3037. BOOL bDeleted = FALSE;
  3038. int i, iSize;
  3039. CThreshold* pThreshold;
  3040. RLIST::iterator iaR;
  3041. //
  3042. // Traverse the complete hierarchy to find the object to delete.
  3043. //
  3044. iSize = m_thresholdList.size();
  3045. iaR=m_thresholdList.begin();
  3046. for (i=0; i<iSize; i++, iaR++)
  3047. {
  3048. MY_ASSERT(i<m_thresholdList.size());
  3049. pThreshold = m_thresholdList[i];
  3050. if (pThreshold->m_bValidLoad == FALSE)
  3051. return WBEM_E_INVALID_OBJECT;
  3052. if (!_wcsicmp(pszGUID, pThreshold->GetGUID()))
  3053. {
  3054. if (_wcsicmp(pThreshold->m_szPropertyName, L"CollectionInstanceCount") &&
  3055. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorCode") &&
  3056. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorDescription"))
  3057. {
  3058. propertyNotNeeded(pThreshold->m_szPropertyName);
  3059. }
  3060. pThreshold->DeleteThresholdConfig();
  3061. delete pThreshold;
  3062. m_thresholdList.erase(iaR);
  3063. bDeleted = TRUE;
  3064. TCHAR msgbuf[1024];
  3065. wsprintf(msgbuf, L"DELETION: TGUID=%s", pszGUID);
  3066. MY_OUTPUT(msgbuf, 4);
  3067. //
  3068. // Get Threshold and DataCollector synced up. Plus we may have been in the middle of a
  3069. // collection interval as this came in.
  3070. //
  3071. ResetState(TRUE, TRUE);
  3072. break;
  3073. }
  3074. }
  3075. if (bDeleted == FALSE)
  3076. {
  3077. return S_FALSE;
  3078. }
  3079. else
  3080. {
  3081. return S_OK;
  3082. }
  3083. }
  3084. //
  3085. // HMSystemConfiguration class exposes this method.
  3086. //
  3087. HRESULT CDataCollector::FindAndEnableByGUID(LPTSTR pszGUID, BOOL bEnable)
  3088. {
  3089. BOOL bFound = FALSE;
  3090. int i, iSize;
  3091. CThreshold* pThreshold;
  3092. //
  3093. // Traverse the complete hierarchy to find the object to enable/disable.
  3094. //
  3095. iSize = m_thresholdList.size();
  3096. for (i=0; i<iSize; i++)
  3097. {
  3098. MY_ASSERT(i<m_thresholdList.size());
  3099. pThreshold = m_thresholdList[i];
  3100. if (!_wcsicmp(pszGUID, pThreshold->GetGUID()))
  3101. {
  3102. bFound = TRUE;
  3103. break;
  3104. }
  3105. }
  3106. if (bFound == FALSE)
  3107. {
  3108. return S_FALSE;
  3109. }
  3110. else
  3111. {
  3112. return S_OK;
  3113. }
  3114. }
  3115. //
  3116. // HMSystemConfiguration class exposes this method.
  3117. //
  3118. // Get rid of the data that was collected, so we can be clean,
  3119. // just as if we just started running.
  3120. //
  3121. //
  3122. HRESULT CDataCollector::ResetState(BOOL bPreserveThresholdStates, BOOL bDoImmediate)
  3123. {
  3124. CThreshold* pThreshold;
  3125. PNSTRUCT *ppn = NULL;
  3126. INSTSTRUCT *pinst;
  3127. InstIDSTRUCT *pInstID;
  3128. int i, j;
  3129. int iSize, jSize;
  3130. ACTUALINSTSTRUCT *pActualInst;
  3131. MY_OUTPUT(L"ENTER ***** CDataCollector::ResetState...", 1);
  3132. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  3133. {
  3134. return S_OK;
  3135. }
  3136. CleanupSemiSync();
  3137. m_ulErrorCodePrev = MAX_ULONG;
  3138. m_lIntervalCount = 0;
  3139. if (bDoImmediate)
  3140. {
  3141. m_lIntervalCount = -1;
  3142. }
  3143. else
  3144. {
  3145. m_lIntervalCount = 0;
  3146. }
  3147. m_lCollectionTimeOutCount = 0;
  3148. m_lNumInstancesCollected = 0;
  3149. if (bPreserveThresholdStates == FALSE)
  3150. {
  3151. m_lCurrState = HM_COLLECTING;
  3152. }
  3153. m_bKeepCollectingSemiSync = FALSE;
  3154. iSize = m_pnList.size();
  3155. for (i = 0; i < iSize ; i++)
  3156. {
  3157. MY_ASSERT(i<m_pnList.size());
  3158. ppn = &m_pnList[i];
  3159. jSize = ppn->instList.size();
  3160. for (j = 0; j < jSize ; j++)
  3161. {
  3162. MY_ASSERT(j<ppn->instList.size());
  3163. pinst = &ppn->instList[j];
  3164. if (pinst->szCurrValue)
  3165. {
  3166. delete [] pinst->szCurrValue;
  3167. }
  3168. if (pinst->szInstanceID)
  3169. {
  3170. delete [] pinst->szInstanceID;
  3171. }
  3172. pinst->valList.clear();
  3173. }
  3174. ppn->instList.clear();
  3175. }
  3176. iSize = m_thresholdList.size();
  3177. for (i = 0; i < iSize ; i++)
  3178. {
  3179. MY_ASSERT(i<m_thresholdList.size());
  3180. pThreshold = m_thresholdList[i];
  3181. pThreshold->ClearInstList();
  3182. if (bPreserveThresholdStates == FALSE)
  3183. {
  3184. pThreshold->SetCurrState(HM_COLLECTING);
  3185. }
  3186. }
  3187. iSize = m_actualInstList.size();
  3188. for (i=0; i < iSize; i++)
  3189. {
  3190. MY_ASSERT(i<m_actualInstList.size());
  3191. pActualInst = &m_actualInstList[i];
  3192. if (pActualInst->szInstanceID)
  3193. {
  3194. delete [] pActualInst->szInstanceID;
  3195. }
  3196. if (pActualInst->pInst)
  3197. {
  3198. pActualInst->pInst->Release();
  3199. pActualInst->pInst = NULL;
  3200. }
  3201. }
  3202. m_actualInstList.clear();
  3203. //
  3204. // Need this for sure with PMDC, does it adversly affect other DataCollectors
  3205. //
  3206. iSize = m_instIDList.size();
  3207. for (i=0; i < iSize; i++)
  3208. {
  3209. MY_ASSERT(i<m_instIDList.size());
  3210. pInstID = &m_instIDList[i];
  3211. delete [] pInstID->szInstanceIDPropertyName;
  3212. }
  3213. m_instIDList.clear();
  3214. MY_OUTPUT(L"EXIT ***** CDataCollector::ResetState...", 1);
  3215. return S_OK;
  3216. }
  3217. //
  3218. // HMSystemConfiguration class exposes this method.
  3219. //
  3220. HRESULT CDataCollector::ResetStatistics(void)
  3221. {
  3222. INSTSTRUCT *pinst;
  3223. PNSTRUCT *ppn;
  3224. int i, j;
  3225. int iSize, jSize;
  3226. MY_OUTPUT(L"ENTER ***** CDataCollector::ResetStatistics...", 1);
  3227. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  3228. {
  3229. return S_OK;
  3230. }
  3231. iSize = m_pnList.size();
  3232. for (i = 0; i < iSize ; i++)
  3233. {
  3234. MY_ASSERT(i<m_pnList.size());
  3235. ppn = &m_pnList[i];
  3236. jSize = ppn->instList.size();
  3237. for (j = 0; j < jSize ; j++)
  3238. {
  3239. MY_ASSERT(j<ppn->instList.size());
  3240. pinst = &ppn->instList[j];
  3241. if (pinst->szCurrValue)
  3242. {
  3243. delete [] pinst->szCurrValue;
  3244. }
  3245. pinst->szCurrValue = NULL;
  3246. ResetInst(pinst, ppn->type);
  3247. pinst->valList.clear();
  3248. }
  3249. }
  3250. EvaluateNow(TRUE);
  3251. MY_OUTPUT(L"EXIT ***** CDataCollector::ResetStatistics...", 1);
  3252. return S_OK;
  3253. }
  3254. //
  3255. // HMSystemConfiguration class exposes this method.
  3256. // Set the increment count back to zero temporarily, so it will
  3257. // run at the next second interval, then set back!
  3258. //
  3259. HRESULT CDataCollector::EvaluateNow(BOOL bDoImmediate)
  3260. {
  3261. MY_OUTPUT(L"ENTER ***** CDataCollector::EvaluateNow...", 1);
  3262. if (m_bValidLoad == FALSE)
  3263. return WBEM_E_INVALID_OBJECT;
  3264. EnumDone();
  3265. if (bDoImmediate)
  3266. {
  3267. m_lIntervalCount = -1;
  3268. }
  3269. else
  3270. {
  3271. m_lIntervalCount = 0;
  3272. }
  3273. m_lCollectionTimeOutCount = 0;
  3274. if (m_deType != HM_EQDE)
  3275. {
  3276. m_lNumInstancesCollected = 0;
  3277. }
  3278. MY_OUTPUT(L"EXIT ***** CDataCollector::EvaluateNow...", 1);
  3279. return S_OK;
  3280. }
  3281. BOOL CDataCollector::SetParentEnabledFlag(BOOL bEnabled)
  3282. {
  3283. int i, iSize;
  3284. CThreshold* pThreshold;
  3285. m_bParentEnabled = bEnabled;
  3286. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  3287. {
  3288. }
  3289. else
  3290. {
  3291. m_lIntervalCount = 0;
  3292. }
  3293. //
  3294. // Now traverse children and call for everything below
  3295. //
  3296. iSize = m_thresholdList.size();
  3297. for (i=0; i < iSize; i++)
  3298. {
  3299. MY_ASSERT(i<m_thresholdList.size());
  3300. pThreshold = m_thresholdList[i];
  3301. pThreshold->SetParentEnabledFlag(m_bEnabled && m_bParentEnabled);
  3302. }
  3303. return TRUE;
  3304. }
  3305. BOOL CDataCollector::Init(void)
  3306. {
  3307. MY_OUTPUT(L"ENTER ***** CDataCollector::Init...", 1);
  3308. m_lIntervalCount = 0;
  3309. m_lCollectionTimeOutCount = 0;
  3310. m_lNumberNormals = 0;
  3311. m_lNumberWarnings = 0;
  3312. m_lNumberCriticals = 0;
  3313. m_lNumberChanges = 0;
  3314. m_lNumInstancesCollected = 0;
  3315. m_lCurrState = HM_COLLECTING;
  3316. m_lPrevState = HM_COLLECTING;
  3317. m_ulErrorCode = 0;
  3318. m_ulErrorCodePrev = MAX_ULONG;
  3319. m_lCollectionTimeOut = 0;
  3320. m_szGUID = NULL;
  3321. m_szParentObjPath = NULL;
  3322. m_pParentDG = NULL;
  3323. m_szName = NULL;
  3324. m_szDescription = NULL;
  3325. m_szUserName = NULL;
  3326. m_szPassword = NULL;
  3327. m_szTargetNamespace = NULL;
  3328. m_szLocal = NULL;
  3329. m_szTypeGUID = NULL;
  3330. m_pContext = NULL;
  3331. m_pCallResult = NULL;
  3332. m_bKeepCollectingSemiSync = FALSE;
  3333. m_bEnabled = TRUE;
  3334. m_bParentEnabled = TRUE;
  3335. m_pIWbemServices = NULL;
  3336. m_lCollectionIntervalMultiple = 60;
  3337. m_lStatisticsWindowSize = 6;
  3338. m_iActiveDays = 0;
  3339. m_lBeginHourTime = 0;
  3340. m_lBeginMinuteTime = 0;
  3341. m_lEndHourTime = 0;
  3342. m_lEndMinuteTime = 0;
  3343. m_lTypeGUID = 0;
  3344. m_bRequireReset = FALSE;
  3345. m_bReplicate = FALSE;
  3346. m_lId = 0;
  3347. m_szErrorDescription[0] = '\0';
  3348. m_szMessage = NULL;
  3349. m_szResetMessage = NULL;
  3350. m_lPrevChildCount = 0;
  3351. // yyyymmddhhmmss.ssssssXUtc; X = GMT(+ or -), Utc = 3 dig. offset from UTC.")]
  3352. wcscpy(m_szTime, m_szCurrTime);
  3353. wcscpy(m_szCollectTime, m_szCurrTime);
  3354. wcscpy(m_szCICTime, m_szCurrTime);
  3355. wcscpy(m_szCECTime, m_szCurrTime);
  3356. wcscpy(m_szDTTime, m_szDTCurrTime);
  3357. wcscpy(m_szDTCollectTime, m_szDTCurrTime);
  3358. wcscpy(m_szDTCICTime, m_szDTCurrTime);
  3359. wcscpy(m_szDTCECTime, m_szDTCurrTime);
  3360. MY_OUTPUT(L"EXIT ***** CDataCollector::Init...", 1);
  3361. return TRUE;
  3362. }
  3363. BOOL CDataCollector::Cleanup(BOOL bSavePrevSettings)
  3364. {
  3365. PNSTRUCT *ppn;
  3366. INSTSTRUCT *pinst;
  3367. int i, iSize;
  3368. int j, jSize;
  3369. CThreshold* pThreshold;
  3370. InstIDSTRUCT *pInstID;
  3371. ACTUALINSTSTRUCT *pActualInst;
  3372. IWbemClassObject* pInstance = NULL;
  3373. MY_OUTPUT(L"ENTER ***** CDataCollector::Cleanup...", 1);
  3374. if (bSavePrevSettings == FALSE)
  3375. {
  3376. // if (m_szParentObjPath)
  3377. // {
  3378. // delete [] m_szParentObjPath;
  3379. // m_szParentObjPath = NULL;
  3380. // }
  3381. }
  3382. if (m_szName)
  3383. {
  3384. delete [] m_szName;
  3385. m_szName = NULL;
  3386. }
  3387. if (m_szDescription)
  3388. {
  3389. delete [] m_szDescription;
  3390. m_szDescription = NULL;
  3391. }
  3392. if (m_szMessage)
  3393. {
  3394. delete [] m_szMessage;
  3395. m_szMessage = NULL;
  3396. }
  3397. if (m_szResetMessage)
  3398. {
  3399. delete [] m_szResetMessage;
  3400. m_szResetMessage = NULL;
  3401. }
  3402. if (m_szUserName)
  3403. {
  3404. delete [] m_szUserName;
  3405. m_szUserName = NULL;
  3406. }
  3407. if (m_szPassword)
  3408. {
  3409. delete [] m_szPassword;
  3410. m_szPassword = NULL;
  3411. }
  3412. if (m_szTargetNamespace)
  3413. {
  3414. delete [] m_szTargetNamespace;
  3415. m_szTargetNamespace = NULL;
  3416. }
  3417. if (m_szLocal)
  3418. {
  3419. delete [] m_szLocal;
  3420. m_szLocal = NULL;
  3421. }
  3422. iSize = m_instIDList.size();
  3423. for (i=0; i < iSize; i++)
  3424. {
  3425. MY_ASSERT(i<m_instIDList.size());
  3426. pInstID = &m_instIDList[i];
  3427. delete [] pInstID->szInstanceIDPropertyName;
  3428. }
  3429. m_instIDList.clear();
  3430. if (m_szTypeGUID)
  3431. {
  3432. delete [] m_szTypeGUID;
  3433. m_szTypeGUID = NULL;
  3434. }
  3435. if (m_pContext != NULL)
  3436. {
  3437. m_pContext->Release();
  3438. m_pContext = NULL;
  3439. }
  3440. if (m_pCallResult != NULL)
  3441. {
  3442. m_pCallResult->Release();
  3443. m_pCallResult = NULL;
  3444. }
  3445. if (bSavePrevSettings)
  3446. {
  3447. ResetState(TRUE, TRUE);
  3448. //
  3449. // Need to also get rid of the Property names,
  3450. // As ResetState does not do that.
  3451. //
  3452. iSize = m_pnList.size();
  3453. for (i = 0; i < iSize ; i++)
  3454. {
  3455. MY_ASSERT(i<m_pnList.size());
  3456. ppn = &m_pnList[i];
  3457. if (ppn->szPropertyName)
  3458. {
  3459. delete [] ppn->szPropertyName;
  3460. }
  3461. }
  3462. m_pnList.clear();
  3463. }
  3464. else
  3465. {
  3466. iSize = m_pnList.size();
  3467. for (i = 0; i < iSize ; i++)
  3468. {
  3469. MY_ASSERT(i<m_pnList.size());
  3470. ppn = &m_pnList[i];
  3471. if (ppn->szPropertyName)
  3472. {
  3473. delete [] ppn->szPropertyName;
  3474. }
  3475. jSize = ppn->instList.size();
  3476. for (j = 0; j < jSize ; j++)
  3477. {
  3478. MY_ASSERT(j<ppn->instList.size());
  3479. pinst = &ppn->instList[j];
  3480. if (pinst->szCurrValue)
  3481. {
  3482. delete [] pinst->szCurrValue;
  3483. }
  3484. if (pinst->szInstanceID)
  3485. {
  3486. delete [] pinst->szInstanceID;
  3487. }
  3488. pinst->valList.clear();
  3489. }
  3490. ppn->instList.clear();
  3491. }
  3492. m_pnList.clear();
  3493. //
  3494. // Clean up everything under this DataCollector
  3495. //
  3496. if (m_bValidLoad == TRUE)
  3497. {
  3498. iSize = m_thresholdList.size();
  3499. for (i = 0; i < iSize ; i++)
  3500. {
  3501. MY_ASSERT(i<m_thresholdList.size());
  3502. pThreshold = m_thresholdList[i];
  3503. delete pThreshold;
  3504. }
  3505. m_thresholdList.clear();
  3506. }
  3507. iSize = m_actualInstList.size();
  3508. for (i=0; i < iSize; i++)
  3509. {
  3510. MY_ASSERT(i<m_actualInstList.size());
  3511. pActualInst = &m_actualInstList[i];
  3512. if (pActualInst->szInstanceID)
  3513. {
  3514. delete [] pActualInst->szInstanceID;
  3515. }
  3516. if (pActualInst->pInst)
  3517. {
  3518. pActualInst->pInst->Release();
  3519. pActualInst->pInst = NULL;
  3520. }
  3521. }
  3522. m_actualInstList.clear();
  3523. }
  3524. if (m_bValidLoad == FALSE)
  3525. {
  3526. EnumDone();
  3527. if (GetHMDataCollectorStatusInstance(&pInstance, TRUE) == S_OK)
  3528. {
  3529. mg_DCEventList.push_back(pInstance);
  3530. }
  3531. }
  3532. MY_OUTPUT(L"EXIT ***** CDataCollector::Cleanup...", 1);
  3533. return TRUE;
  3534. }
  3535. #ifdef SAVE
  3536. //
  3537. // For when moving from one parent to another
  3538. //
  3539. BOOL CDataCollector::ModifyAssocForMove(CBase *pNewParentBase)
  3540. {
  3541. HRESULT hRes;
  3542. TCHAR szTemp[1024];
  3543. TCHAR szNewTemp[1024];
  3544. BSTR instName;
  3545. IWbemContext *pCtx = 0;
  3546. IWbemCallResult *pResult = 0;
  3547. IWbemClassObject* pObj = NULL;
  3548. IWbemClassObject* pNewObj = NULL;
  3549. MY_OUTPUT(L"ENTER ***** CDataGroup::ModifyAssocForMove...", 4);
  3550. MY_OUTPUT2(L"m_szGUID=%s", m_szGUID, 4);
  3551. //
  3552. // Figure out the new parent path
  3553. //
  3554. if (pNewParentBase->m_hmStatusType == HMSTATUS_DATAGROUP)
  3555. {
  3556. wcscpy(szNewTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_DataGroupConfiguration.GUID=\"");
  3557. }
  3558. else
  3559. {
  3560. MY_ASSERT(FALSE);
  3561. }
  3562. lstrcat(szNewTemp, pNewParentBase->m_szGUID);
  3563. lstrcat(szNewTemp, L"\"");
  3564. //
  3565. // Delete the association from my parent to me.
  3566. //
  3567. if (m_deType == HM_PGDE)
  3568. {
  3569. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_PolledGetObjectDataCollectorConfiguration.GUID=\"");
  3570. }
  3571. else if (m_deType == HM_PMDE)
  3572. {
  3573. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_PolledMethodDataCollectorConfiguration.GUID=\"");
  3574. }
  3575. else if (m_deType == HM_PQDE)
  3576. {
  3577. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_PolledQueryDataCollectorConfiguration.GUID=\"");
  3578. }
  3579. else if (m_deType == HM_EQDE)
  3580. {
  3581. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHealthMonitor:MicrosoftHM_EventQueryDataCollectorConfiguration.GUID=\\\"");
  3582. }
  3583. lstrcat(szTemp, m_szGUID);
  3584. lstrcat(szTemp, L"\"");
  3585. instName = SysAllocString(L"MicrosoftHM_ConfigurationAssociation");
  3586. if ((hRes = g_pIWbemServices->GetObject(instName, 0L, NULL, &pObj, NULL)) != S_OK)
  3587. {
  3588. }
  3589. SysFreeString(instName);
  3590. if (pObj)
  3591. {
  3592. hRes = pObj->SpawnInstance(0, &pNewObj);
  3593. pObj->Release();
  3594. PutStrProperty(pNewObj, L"ChildPath", szTemp);
  3595. PutStrProperty(pNewObj, L"ParentPath", szNewTemp);
  3596. hRes = g_pIWbemServices->PutInstance(pNewObj, 0, NULL, &pResult);
  3597. pNewObj->Release();
  3598. pNewObj = NULL;
  3599. }
  3600. DeleteDEConfig(TRUE);
  3601. if (pNewParentBase->m_hmStatusType == HMSTATUS_DATAGROUP)
  3602. {
  3603. wcscpy(szNewTemp, L"MicrosoftHM_DataGroupConfiguration.GUID=\\\"");
  3604. lstrcat(szNewTemp, pNewParentBase->m_szGUID);
  3605. lstrcat(szNewTemp, L"\\\"");
  3606. }
  3607. else
  3608. {
  3609. MY_ASSERT(FALSE);
  3610. }
  3611. if (m_szParentObjPath)
  3612. {
  3613. delete [] m_szParentObjPath;
  3614. }
  3615. m_szParentObjPath = new TCHAR[wcslen(szNewTemp)+1];
  3616. wcscpy(m_szParentObjPath, szNewTemp);
  3617. m_pParentDG = (CDataGroup *) pNewParentBase;
  3618. MY_OUTPUT(L"EXIT ***** CDataGroup::ModifyAssocForMove...", 4);
  3619. return TRUE;
  3620. }
  3621. #endif
  3622. BOOL CDataCollector::ReceiveNewChildForMove(CBase *pBase)
  3623. {
  3624. //XXX seems to be some code missing here,
  3625. //did we clean up from the old place things like m_pnList, and add to the new one if it is a
  3626. //new property.
  3627. // Like what we do in -> CDataCollector::AddThreshold()
  3628. MY_ASSERT(FALSE);
  3629. MY_ASSERT(pBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR);
  3630. m_thresholdList.push_back((CThreshold *)pBase);
  3631. // (CThreshold *)pBase->SetParentEnabledFlag(m_bEnabled);
  3632. if (_wcsicmp(((CThreshold *)pBase)->m_szPropertyName, L"CollectionInstanceCount") &&
  3633. _wcsicmp(((CThreshold *)pBase)->m_szPropertyName, L"CollectionErrorCode") &&
  3634. _wcsicmp(((CThreshold *)pBase)->m_szPropertyName, L"CollectionErrorDescription"))
  3635. {
  3636. insertNewProperty(((CThreshold *)pBase)->m_szPropertyName);
  3637. // MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3638. }
  3639. //
  3640. // Get Threshold and DataCollector synced up. Plus we may have been in the middle of a
  3641. // collection interval as this came in.
  3642. //
  3643. ResetState(TRUE, TRUE);
  3644. return TRUE;
  3645. }
  3646. BOOL CDataCollector::DeleteChildFromList(LPTSTR pszGUID)
  3647. {
  3648. int i, iSize;
  3649. CThreshold* pThreshold;
  3650. RLIST::iterator iaR;
  3651. BOOL bFound = FALSE;
  3652. iSize = m_thresholdList.size();
  3653. iaR=m_thresholdList.begin();
  3654. for (i=0; i<iSize; i++, iaR++)
  3655. {
  3656. MY_ASSERT(i<m_thresholdList.size());
  3657. pThreshold = m_thresholdList[i];
  3658. if (pThreshold->m_bValidLoad == FALSE)
  3659. return FALSE;
  3660. if (!_wcsicmp(pszGUID, pThreshold->GetGUID()))
  3661. {
  3662. if (_wcsicmp(pThreshold->m_szPropertyName, L"CollectionInstanceCount") &&
  3663. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorCode") &&
  3664. _wcsicmp(pThreshold->m_szPropertyName, L"CollectionErrorDescription"))
  3665. {
  3666. propertyNotNeeded(pThreshold->m_szPropertyName);
  3667. }
  3668. m_thresholdList.erase(iaR);
  3669. bFound = TRUE;
  3670. break;
  3671. }
  3672. }
  3673. return bFound;
  3674. }
  3675. BOOL CDataCollector::DeleteDEConfig(BOOL bDeleteAssocOnly)
  3676. {
  3677. int i, iSize;
  3678. CThreshold* pThreshold;
  3679. HRESULT hRetRes = S_OK;
  3680. TCHAR szTemp[1024];
  3681. BSTR instName = NULL;
  3682. MY_OUTPUT(L"ENTER ***** CDataCollector::DeleteDEConfig...", 4);
  3683. MY_OUTPUT2(L"m_szGUID=%s", m_szGUID, 4);
  3684. //
  3685. // Delete the association from my parent to me.
  3686. //
  3687. if (m_deType == HM_PGDE)
  3688. {
  3689. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_PolledGetObjectDataCollectorConfiguration.GUID=\\\"");
  3690. }
  3691. else if (m_deType == HM_PMDE)
  3692. {
  3693. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_PolledMethodDataCollectorConfiguration.GUID=\\\"");
  3694. }
  3695. else if (m_deType == HM_PQDE)
  3696. {
  3697. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_PolledQueryDataCollectorConfiguration.GUID=\\\"");
  3698. }
  3699. else if (m_deType == HM_EQDE)
  3700. {
  3701. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_EventQueryDataCollectorConfiguration.GUID=\\\"");
  3702. }
  3703. lstrcat(szTemp, m_szGUID);
  3704. lstrcat(szTemp, L"\\\"\",ParentPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:");
  3705. lstrcat(szTemp, m_szParentObjPath);
  3706. lstrcat(szTemp, L"\"");
  3707. instName = SysAllocString(szTemp);
  3708. MY_ASSERT(instName); if (!instName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3709. if ((hRetRes = g_pIWbemServices->DeleteInstance(instName, 0L, NULL, NULL)) != S_OK)
  3710. {
  3711. SysFreeString(instName);
  3712. instName = NULL;
  3713. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_DataCollectorConfiguration.GUID=\\\"");
  3714. lstrcat(szTemp, m_szGUID);
  3715. lstrcat(szTemp, L"\\\"\",ParentPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:");
  3716. lstrcat(szTemp, m_szParentObjPath);
  3717. lstrcat(szTemp, L"\"");
  3718. instName = SysAllocString(szTemp);
  3719. MY_ASSERT(instName); if (!instName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3720. if ((hRetRes = g_pIWbemServices->DeleteInstance(instName, 0L, NULL, NULL)) != S_OK)
  3721. {
  3722. // MY_HRESASSERT(hRes);
  3723. }
  3724. }
  3725. SysFreeString(instName);
  3726. instName = NULL;
  3727. if (bDeleteAssocOnly)
  3728. {
  3729. return TRUE;
  3730. }
  3731. //
  3732. // Delete our exact instance
  3733. //
  3734. wcscpy(szTemp, L"MicrosoftHM_DataCollectorConfiguration.GUID=\"");
  3735. lstrcat(szTemp, m_szGUID);
  3736. lstrcat(szTemp, L"\"");
  3737. instName = SysAllocString(szTemp);
  3738. MY_ASSERT(instName); if (!instName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3739. if ((hRetRes = g_pIWbemServices->DeleteInstance(instName, 0L, NULL, NULL)) != S_OK)
  3740. {
  3741. // MY_HRESASSERT(hRes);
  3742. }
  3743. SysFreeString(instName);
  3744. instName = NULL;
  3745. //
  3746. // Traverse the complete hierarchy and delete
  3747. //
  3748. iSize = m_thresholdList.size();
  3749. for (i=0; i<iSize; i++)
  3750. {
  3751. MY_ASSERT(i<m_thresholdList.size());
  3752. pThreshold = m_thresholdList[i];
  3753. pThreshold->DeleteThresholdConfig();
  3754. delete pThreshold;
  3755. }
  3756. m_thresholdList.clear();
  3757. //
  3758. // Get rid of any associations to actions for this
  3759. //
  3760. g_pSystem->DeleteAllConfigActionAssoc(m_szGUID);
  3761. MY_OUTPUT(L"EXIT ***** CDataCollector::DeleteDEConfig...", 4);
  3762. return TRUE;
  3763. error:
  3764. MY_ASSERT(FALSE);
  3765. if (instName)
  3766. SysFreeString(instName);
  3767. m_bValidLoad = FALSE;
  3768. Cleanup(FALSE);
  3769. return FALSE;
  3770. }
  3771. BOOL CDataCollector::DeleteDEInternal(void)
  3772. {
  3773. int i, iSize;
  3774. CThreshold* pThreshold;
  3775. MY_OUTPUT(L"ENTER ***** CDataCollector::DeleteDEInternal...", 4);
  3776. //
  3777. // Traverse the complete hierarchy and delete
  3778. //
  3779. iSize = m_thresholdList.size();
  3780. for (i=0; i<iSize; i++)
  3781. {
  3782. MY_ASSERT(i<m_thresholdList.size());
  3783. pThreshold = m_thresholdList[i];
  3784. delete pThreshold;
  3785. }
  3786. m_thresholdList.clear();
  3787. //
  3788. // Get rid of any associations to actions for this
  3789. //
  3790. // g_pSystem->DeleteAllConfigActionAssoc(m_szGUID);
  3791. MY_OUTPUT(L"EXIT ***** CDataCollector::DeleteDEInternal...", 4);
  3792. return TRUE;
  3793. }
  3794. HRESULT CDataCollector::FindAndCopyByGUID(LPTSTR pszGUID, ILIST* pConfigList, LPTSTR *pszOriginalParentGUID)
  3795. {
  3796. int i, iSize;
  3797. CThreshold* pThreshold;
  3798. HRESULT hRetRes = S_OK;
  3799. //
  3800. // Find what to copy
  3801. //
  3802. iSize = m_thresholdList.size();
  3803. for (i=0; i<iSize; i++)
  3804. {
  3805. MY_ASSERT(i<m_thresholdList.size());
  3806. pThreshold = m_thresholdList[i];
  3807. if (!_wcsicmp(pszGUID, pThreshold->GetGUID()))
  3808. {
  3809. hRetRes = pThreshold->Copy(pConfigList, NULL, NULL);
  3810. *pszOriginalParentGUID = m_szGUID;
  3811. return hRetRes;
  3812. }
  3813. }
  3814. return WBEM_S_DIFFERENT;
  3815. }
  3816. HRESULT CDataCollector::Copy(ILIST* pConfigList, LPTSTR pszOldParentGUID, LPTSTR pszNewParentGUID)
  3817. {
  3818. GUID guid;
  3819. TCHAR szTemp[1024];
  3820. TCHAR szNewGUID[1024];
  3821. IWbemClassObject* pInst = NULL;
  3822. IWbemClassObject* pInstCopy = NULL;
  3823. IWbemClassObject* pInstAssocCopy = NULL;
  3824. IWbemClassObject* pObj = NULL;
  3825. int i, iSize;
  3826. CThreshold* pThreshold;
  3827. BSTR Language = NULL;
  3828. BSTR Query = NULL;
  3829. IEnumWbemClassObject *pEnum;
  3830. ULONG uReturned;
  3831. IWbemContext *pCtx = 0;
  3832. LPTSTR pszParentPath = NULL;
  3833. LPTSTR pszChildPath = NULL;
  3834. LPTSTR pStr;
  3835. HRESULT hRetRes = S_OK;
  3836. MY_OUTPUT(L"ENTER ***** CDataCollector::Copy...", 1);
  3837. if (m_bValidLoad == FALSE)
  3838. return WBEM_E_INVALID_OBJECT;
  3839. //
  3840. // Get the origional starting point HMConfiguration instance.
  3841. //
  3842. wcscpy(szTemp, L"MicrosoftHM_Configuration.GUID=\"");
  3843. lstrcat(szTemp, m_szGUID);
  3844. lstrcat(szTemp, L"\"");
  3845. hRetRes = GetWbemObjectInst(&g_pIWbemServices, szTemp, NULL, &pInst);
  3846. if (!pInst)
  3847. {
  3848. return hRetRes;
  3849. }
  3850. //
  3851. // Clone the instance, and change the GUID
  3852. //
  3853. hRetRes = pInst->Clone(&pInstCopy);
  3854. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3855. hRetRes = CoCreateGuid(&guid);
  3856. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3857. StringFromGUID2(guid, szNewGUID, 100);
  3858. hRetRes = PutStrProperty(pInstCopy, L"GUID", szNewGUID);
  3859. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3860. pConfigList->push_back(pInstCopy);
  3861. //
  3862. // Add instance of HMConfigurationAssociation where we are the child,
  3863. // using the parent GUID passed in.
  3864. // Change the GUIDs of both the Parent and Child.
  3865. // also make sure that the machine name is not in the path, and is relative!
  3866. //
  3867. if (pszOldParentGUID != NULL)
  3868. {
  3869. Language = SysAllocString(L"WQL");
  3870. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3871. wcscpy(szTemp, L"REFERENCES OF {MicrosoftHM_Configuration.GUID=\"");
  3872. lstrcat(szTemp, m_szGUID);
  3873. lstrcat(szTemp, L"\"} WHERE ResultClass=MicrosoftHM_ConfigurationAssociation Role=ChildPath");
  3874. Query = SysAllocString(szTemp);
  3875. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3876. // Initialize IEnumWbemClassObject pointer
  3877. pEnum = 0;
  3878. // Issue query
  3879. hRetRes = g_pIWbemServices->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY, 0, &pEnum);
  3880. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3881. SysFreeString(Query);
  3882. Query = NULL;
  3883. SysFreeString(Language);
  3884. Language = NULL;
  3885. // Retrieve object in result set
  3886. pObj = NULL;
  3887. uReturned = 0;
  3888. hRetRes = pEnum->Next(0, 1, &pObj, &uReturned);
  3889. if (uReturned == 0)
  3890. {
  3891. hRetRes = WBEM_E_INVALID_OBJECT_PATH; goto error;
  3892. }
  3893. //
  3894. // Change the GUIDs
  3895. //
  3896. hRetRes = GetStrProperty(pObj, L"ParentPath", &pszParentPath);
  3897. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3898. hRetRes = GetStrProperty(pObj, L"ChildPath", &pszChildPath);
  3899. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3900. pStr = wcschr(pszParentPath, '\"');
  3901. if (pStr)
  3902. {
  3903. pStr++;
  3904. wcsncpy(pStr, pszNewParentGUID, wcslen(pszNewParentGUID));
  3905. }
  3906. else
  3907. {
  3908. hRetRes = WBEM_E_INVALID_OBJECT_PATH; goto error;
  3909. }
  3910. pStr = wcschr(pszChildPath, '\"');
  3911. if (pStr)
  3912. {
  3913. pStr++;
  3914. wcsncpy(pStr, szNewGUID, wcslen(szNewGUID));
  3915. }
  3916. else
  3917. {
  3918. hRetRes = WBEM_E_INVALID_OBJECT_PATH; goto error;
  3919. }
  3920. hRetRes = pObj->Clone(&pInstAssocCopy);
  3921. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3922. hRetRes = PutStrProperty(pInstAssocCopy, L"ParentPath", pszParentPath);
  3923. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3924. hRetRes = PutStrProperty(pInstAssocCopy, L"ChildPath", pszChildPath);
  3925. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3926. pConfigList->push_back(pInstAssocCopy);
  3927. // Release it.
  3928. pObj->Release();
  3929. pObj = NULL;
  3930. pEnum->Release();
  3931. pEnum = NULL;
  3932. delete [] pszParentPath;
  3933. pszParentPath = NULL;
  3934. delete [] pszChildPath;
  3935. pszChildPath = NULL;
  3936. }
  3937. //
  3938. // Add in all children
  3939. //
  3940. iSize = m_thresholdList.size();
  3941. for (i=0; i<iSize; i++)
  3942. {
  3943. MY_ASSERT(i<m_thresholdList.size());
  3944. pThreshold = m_thresholdList[i];
  3945. hRetRes = pThreshold->Copy(pConfigList, m_szGUID, szNewGUID);
  3946. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3947. }
  3948. pInst->Release();
  3949. pInst = NULL;
  3950. MY_OUTPUT(L"EXIT ***** CDataCollector::Copy...", 1);
  3951. return S_OK;
  3952. error:
  3953. MY_ASSERT(FALSE);
  3954. if (pInst)
  3955. pInst->Release();
  3956. if (pObj)
  3957. pObj->Release();
  3958. if (pEnum)
  3959. pEnum->Release();
  3960. if (Query)
  3961. SysFreeString(Query);
  3962. if (Language)
  3963. SysFreeString(Language);
  3964. if (pszParentPath)
  3965. delete [] pszParentPath;
  3966. if (pszChildPath)
  3967. delete [] pszChildPath;
  3968. m_bValidLoad = FALSE;
  3969. Cleanup(FALSE);
  3970. return hRetRes;
  3971. }
  3972. CBase *CDataCollector::GetParentPointerFromGUID(LPTSTR pszGUID)
  3973. {
  3974. int i, iSize;
  3975. CThreshold* pThreshold;
  3976. BOOL bFound = FALSE;
  3977. CBase *pBase;
  3978. iSize = m_thresholdList.size();
  3979. for (i=0; i<iSize; i++)
  3980. {
  3981. MY_ASSERT(i<m_thresholdList.size());
  3982. pThreshold = m_thresholdList[i];
  3983. if (!_wcsicmp(pszGUID, pThreshold->GetGUID()))
  3984. {
  3985. pBase = pThreshold;
  3986. bFound = TRUE;
  3987. break;
  3988. }
  3989. }
  3990. if (bFound == TRUE)
  3991. {
  3992. return pBase;
  3993. }
  3994. else
  3995. {
  3996. return NULL;
  3997. }
  3998. }
  3999. CBase *CDataCollector::FindImediateChildByName(LPTSTR pszName)
  4000. {
  4001. int i, iSize;
  4002. CThreshold* pThreshold;
  4003. BOOL bFound = FALSE;
  4004. CBase *pBase;
  4005. iSize = m_thresholdList.size();
  4006. for (i=0; i<iSize; i++)
  4007. {
  4008. MY_ASSERT(i<m_thresholdList.size());
  4009. pThreshold = m_thresholdList[i];
  4010. if (pThreshold->m_bValidLoad == FALSE)
  4011. return NULL;
  4012. if (!_wcsicmp(pszName, pThreshold->m_szName))
  4013. {
  4014. pBase = pThreshold;
  4015. bFound = TRUE;
  4016. break;
  4017. }
  4018. }
  4019. if (bFound == TRUE)
  4020. {
  4021. return pBase;
  4022. }
  4023. else
  4024. {
  4025. return NULL;
  4026. }
  4027. }
  4028. BOOL CDataCollector::GetNextChildName(LPTSTR pszChildName, LPTSTR pszOutName)
  4029. {
  4030. TCHAR szTemp[1024];
  4031. TCHAR szIndex[1024];
  4032. int i, iSize;
  4033. BOOL bFound;
  4034. CThreshold* pThreshold;
  4035. int index;
  4036. // We are here because we know that one exists already with the same name.
  4037. // So, lets start off trying to guess what the next name should be and get one.
  4038. index = 0;
  4039. bFound = TRUE;
  4040. while (bFound == TRUE)
  4041. {
  4042. wcscpy(szTemp, pszChildName);
  4043. _itow(index, szIndex, 10);
  4044. lstrcat(szTemp, L" ");
  4045. lstrcat(szTemp, szIndex);
  4046. bFound = FALSE;
  4047. iSize = m_thresholdList.size();
  4048. for (i=0; i<iSize; i++)
  4049. {
  4050. MY_ASSERT(i<m_thresholdList.size());
  4051. pThreshold = m_thresholdList[i];
  4052. if (pThreshold->m_bValidLoad == FALSE)
  4053. break;
  4054. if (!_wcsicmp(szTemp, pThreshold->m_szName))
  4055. {
  4056. bFound = TRUE;
  4057. break;
  4058. }
  4059. }
  4060. index++;
  4061. }
  4062. wcscpy(pszOutName, szTemp);
  4063. return TRUE;
  4064. }
  4065. CBase *CDataCollector::FindPointerFromName(LPTSTR pszName)
  4066. {
  4067. int i, iSize;
  4068. CThreshold* pThreshold;
  4069. BOOL bFound = FALSE;
  4070. CBase *pBase;
  4071. iSize = m_thresholdList.size();
  4072. for (i=0; i<iSize; i++)
  4073. {
  4074. MY_ASSERT(i<m_thresholdList.size());
  4075. pThreshold = m_thresholdList[i];
  4076. if (!_wcsicmp(pszName, pThreshold->GetGUID()))
  4077. {
  4078. pBase = pThreshold;
  4079. bFound = TRUE;
  4080. break;
  4081. }
  4082. }
  4083. if (bFound == TRUE)
  4084. {
  4085. return pBase;
  4086. }
  4087. else
  4088. {
  4089. return NULL;
  4090. }
  4091. }
  4092. HRESULT CDataCollector::GetInstanceID(IWbemClassObject* pObj, LPTSTR *pszID)
  4093. {
  4094. HRESULT hRetRes = NULL;
  4095. TCHAR szTemp[1024];
  4096. LPTSTR pszTemp = NULL;
  4097. InstIDSTRUCT InstID;
  4098. SAFEARRAY *psaNames = NULL;
  4099. BSTR PropName = NULL;
  4100. long lLower, lUpper;
  4101. int i, iSize;
  4102. InstIDSTRUCT *pInstID;
  4103. if (m_bValidLoad == FALSE)
  4104. return FALSE;
  4105. iSize = m_instIDList.size();
  4106. if (iSize == 0)
  4107. {
  4108. hRetRes = pObj->GetNames(NULL, WBEM_FLAG_KEYS_ONLY | WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
  4109. if (SUCCEEDED(hRetRes))
  4110. {
  4111. // Get the number of properties.
  4112. hRetRes = SafeArrayGetLBound(psaNames, 1, &lLower);
  4113. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4114. hRetRes = SafeArrayGetUBound(psaNames, 1, &lUpper);
  4115. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4116. if ((lUpper - lLower + 1) == 0)
  4117. {
  4118. InstID.szInstanceIDPropertyName = new TCHAR[3];
  4119. MY_ASSERT(InstID.szInstanceIDPropertyName); if (!InstID.szInstanceIDPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4120. wcscpy(InstID.szInstanceIDPropertyName , L"@");
  4121. m_instIDList.push_back(InstID);
  4122. }
  4123. else
  4124. {
  4125. // For each property...
  4126. for (long k=lLower; k<=lUpper; k++)
  4127. {
  4128. // Get this property.
  4129. hRetRes = SafeArrayGetElement(psaNames, &k, &PropName);
  4130. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4131. if (SUCCEEDED(hRetRes))
  4132. {
  4133. InstID.szInstanceIDPropertyName = new TCHAR[wcslen(PropName)+2];
  4134. MY_ASSERT(InstID.szInstanceIDPropertyName); if (!InstID.szInstanceIDPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4135. wcscpy(InstID.szInstanceIDPropertyName , PropName);
  4136. SysFreeString(PropName);
  4137. PropName = NULL;
  4138. m_instIDList.push_back(InstID);
  4139. }
  4140. }
  4141. }
  4142. SafeArrayDestroy(psaNames);
  4143. psaNames = NULL;
  4144. }
  4145. }
  4146. MY_ASSERT(m_instIDList.size());
  4147. //
  4148. // Add it as a new instance if necessary
  4149. // All PropertyNames have the same list of instances.
  4150. // Just look at the first PropertyName, and search through
  4151. // its list of instances.
  4152. //
  4153. MY_ASSERT(m_instIDList.size());
  4154. pInstID = &m_instIDList[0];
  4155. if (!wcscmp(pInstID->szInstanceIDPropertyName, L"@"))
  4156. {
  4157. *pszID = new TCHAR[3];
  4158. MY_ASSERT(pszID); if (!pszID) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4159. wcscpy(*pszID , L"@");
  4160. }
  4161. else
  4162. {
  4163. szTemp[0] = '\0';
  4164. iSize = m_instIDList.size();
  4165. for (i=0; i < iSize; i++)
  4166. {
  4167. if (i != 0)
  4168. wcscat(szTemp, L";");
  4169. MY_ASSERT(i<m_instIDList.size());
  4170. pInstID = &m_instIDList[i];
  4171. hRetRes = GetAsStrProperty(pObj, pInstID->szInstanceIDPropertyName, &pszTemp);
  4172. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4173. wcscat(szTemp, pszTemp);
  4174. delete [] pszTemp;
  4175. pszTemp = NULL;
  4176. }
  4177. *pszID = new TCHAR[wcslen(szTemp)+2];
  4178. MY_ASSERT(pszID); if (!pszID) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4179. wcscpy(*pszID , szTemp);
  4180. }
  4181. return hRetRes;
  4182. error:
  4183. MY_ASSERT(FALSE);
  4184. if (PropName)
  4185. SysFreeString(PropName);
  4186. if (pszTemp)
  4187. delete [] pszTemp;
  4188. if (psaNames)
  4189. SafeArrayDestroy(psaNames);
  4190. m_bValidLoad = FALSE;
  4191. Cleanup(FALSE);
  4192. return hRetRes;
  4193. }
  4194. //
  4195. // Adds new instances that have not been seen before, and makes ones seen alread as
  4196. // needed again. If pObj is NULL, that means it is one of the special Agent provided
  4197. // properties - CollectionInstanceCount, CollectionErrorCode or CollectionErrorDescription.
  4198. //
  4199. HRESULT CDataCollector::CheckInstanceExistance(IWbemClassObject *pObj, LPTSTR pszInstanceID)
  4200. {
  4201. HRESULT hRetRes = S_OK;
  4202. BOOL bFound;
  4203. PNSTRUCT *ppn;
  4204. INSTSTRUCT *pinst;
  4205. int i, j, iSize, jSize;
  4206. int foundInstID;
  4207. CThreshold *pThreshold;
  4208. IRSSTRUCT *pirs;
  4209. INSTSTRUCT inst;
  4210. LPTSTR pszPropertyName;
  4211. // BOOL bRetValue;
  4212. if (m_bValidLoad == FALSE)
  4213. return FALSE;
  4214. // Just need to look at the instance list of the first property to tell if the
  4215. // instance has been seen yet.
  4216. if (pObj)
  4217. {
  4218. bFound = FALSE;
  4219. iSize = m_pnList.size();
  4220. if (4 <= iSize)
  4221. {
  4222. i = 0;
  4223. MY_ASSERT(i<m_pnList.size());
  4224. ppn = &m_pnList[i];
  4225. jSize = ppn->instList.size();
  4226. for (j=0; j < jSize ; j++)
  4227. {
  4228. MY_ASSERT(j<ppn->instList.size());
  4229. pinst = &ppn->instList[j];
  4230. if (!_wcsicmp(pinst->szInstanceID, pszInstanceID))
  4231. {
  4232. bFound = TRUE;
  4233. foundInstID = j;
  4234. break;
  4235. }
  4236. }
  4237. }
  4238. }
  4239. else
  4240. {
  4241. bFound = FALSE;
  4242. iSize = m_pnList.size();
  4243. if (3 <= iSize)
  4244. {
  4245. if (!_wcsicmp(pszInstanceID, L"CollectionInstanceCount"))
  4246. {
  4247. i = iSize-3;
  4248. }
  4249. else if (!_wcsicmp(pszInstanceID, L"CollectionErrorCode"))
  4250. {
  4251. i = iSize-2;
  4252. }
  4253. else if (!_wcsicmp(pszInstanceID, L"CollectionErrorDescription"))
  4254. {
  4255. i = iSize-1;
  4256. }
  4257. else
  4258. {
  4259. MY_ASSERT(FALSE);
  4260. i = iSize-3;
  4261. }
  4262. MY_ASSERT(i<m_pnList.size());
  4263. ppn = &m_pnList[i];
  4264. jSize = ppn->instList.size();
  4265. for (j=0; j < jSize ; j++)
  4266. {
  4267. MY_ASSERT(j<ppn->instList.size());
  4268. pinst = &ppn->instList[j];
  4269. if (!_wcsicmp(pinst->szInstanceID, pszInstanceID))
  4270. {
  4271. bFound = TRUE;
  4272. foundInstID = j;
  4273. break;
  4274. }
  4275. }
  4276. }
  4277. }
  4278. if (bFound == FALSE)
  4279. {
  4280. // Add an instance to each property name.
  4281. // Only add the CollectionInstanceCount instance to the CollectionInstanceCount property.
  4282. // and the CollectionErrorCode instance to the CollectionErrorCode property.
  4283. // and the CollectionErrorDescription instance to the CollectionErrorDescription property.
  4284. iSize = m_pnList.size();
  4285. if (pObj)
  4286. {
  4287. for (i=0; i < iSize-3; i++)
  4288. {
  4289. MY_ASSERT(i<m_pnList.size());
  4290. ppn = &m_pnList[i];
  4291. inst.szInstanceID = new TCHAR[wcslen(pszInstanceID)+2];
  4292. MY_ASSERT(inst.szInstanceID); if (!inst.szInstanceID) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4293. wcscpy(inst.szInstanceID, pszInstanceID);
  4294. inst.szCurrValue = NULL;
  4295. ResetInst(&inst, ppn->type);
  4296. inst.bNull = FALSE;
  4297. inst.bNeeded = TRUE;
  4298. ppn->instList.push_back(inst);
  4299. }
  4300. // Also add instance for all thresholds under this DataCollector
  4301. // Only add the CollectionInstanceCount instance to the Threshold looking at
  4302. // the CollectionInstanceCount property. Same for CollectionErrorCode and CollectionErrorDescription.
  4303. iSize = m_thresholdList.size();
  4304. for (i=0; i < iSize; i++)
  4305. {
  4306. MY_ASSERT(i<m_thresholdList.size());
  4307. pThreshold = m_thresholdList[i];
  4308. pszPropertyName = pThreshold->GetPropertyName();
  4309. if (_wcsicmp(pszPropertyName, L"CollectionInstanceCount") &&
  4310. _wcsicmp(pszPropertyName, L"CollectionErrorCode") &&
  4311. _wcsicmp(pszPropertyName, L"CollectionErrorDescription"))
  4312. {
  4313. hRetRes = pThreshold->AddInstance(pszInstanceID);
  4314. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4315. }
  4316. }
  4317. }
  4318. else
  4319. {
  4320. if (!_wcsicmp(pszInstanceID, L"CollectionInstanceCount"))
  4321. {
  4322. i = iSize-3;
  4323. }
  4324. else if (!_wcsicmp(pszInstanceID, L"CollectionErrorCode"))
  4325. {
  4326. i = iSize-2;
  4327. }
  4328. else if (!_wcsicmp(pszInstanceID, L"CollectionErrorDescription"))
  4329. {
  4330. i = iSize-1;
  4331. }
  4332. else
  4333. {
  4334. MY_ASSERT(FALSE);
  4335. i = iSize-3;
  4336. }
  4337. MY_ASSERT(i<m_pnList.size());
  4338. ppn = &m_pnList[i];
  4339. inst.szInstanceID = new TCHAR[wcslen(pszInstanceID)+2];
  4340. MY_ASSERT(inst.szInstanceID); if (!inst.szInstanceID) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4341. wcscpy(inst.szInstanceID, pszInstanceID);
  4342. inst.szCurrValue = NULL;
  4343. ResetInst(&inst, ppn->type);
  4344. inst.bNull = FALSE;
  4345. inst.bNeeded = TRUE;
  4346. ppn->instList.push_back(inst);
  4347. // Also add instance for all thresholds under this DataCollector
  4348. // Only add the CollectionInstanceCount instance to the Threshold looking at
  4349. // the CollectionInstanceCount property. Same for CollectionErrorCode and CollectionErrorDescription.
  4350. iSize = m_thresholdList.size();
  4351. for (i=0; i < iSize; i++)
  4352. {
  4353. MY_ASSERT(i<m_thresholdList.size());
  4354. pThreshold = m_thresholdList[i];
  4355. pszPropertyName = pThreshold->GetPropertyName();
  4356. if (!_wcsicmp(pszPropertyName, pszInstanceID) ||
  4357. !_wcsicmp(pszPropertyName, pszInstanceID) ||
  4358. !_wcsicmp(pszPropertyName, pszInstanceID))
  4359. {
  4360. hRetRes = pThreshold->AddInstance(pszInstanceID);
  4361. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4362. }
  4363. }
  4364. }
  4365. }
  4366. else
  4367. {
  4368. iSize = m_pnList.size();
  4369. if (pObj)
  4370. {
  4371. for (i=0; i < iSize-3 ; i++)
  4372. {
  4373. MY_ASSERT(i<m_pnList.size());
  4374. ppn = &m_pnList[i];
  4375. MY_ASSERT(foundInstID<ppn->instList.size());
  4376. pinst = &ppn->instList[foundInstID];
  4377. pinst->bNull = FALSE;
  4378. pinst->bNeeded = TRUE;
  4379. }
  4380. //Also for all thresholds under this DataCollector
  4381. iSize = m_thresholdList.size();
  4382. for (i=0; i < iSize ; i++)
  4383. {
  4384. MY_ASSERT(i<m_thresholdList.size());
  4385. pThreshold = m_thresholdList[i];
  4386. pszPropertyName = pThreshold->GetPropertyName();
  4387. if (_wcsicmp(pszPropertyName, L"CollectionInstanceCount") &&
  4388. _wcsicmp(pszPropertyName, L"CollectionErrorCode") &&
  4389. _wcsicmp(pszPropertyName, L"CollectionErrorDescription"))
  4390. {
  4391. MY_ASSERT(foundInstID<pThreshold->m_irsList.size());
  4392. pirs = &pThreshold->m_irsList[foundInstID];
  4393. pirs->bNeeded = TRUE;
  4394. }
  4395. }
  4396. }
  4397. else
  4398. {
  4399. if (!_wcsicmp(pszInstanceID, L"CollectionInstanceCount"))
  4400. {
  4401. i = iSize-3;
  4402. }
  4403. else if (!_wcsicmp(pszInstanceID, L"CollectionErrorCode"))
  4404. {
  4405. i = iSize-2;
  4406. }
  4407. else if (!_wcsicmp(pszInstanceID, L"CollectionErrorDescription"))
  4408. {
  4409. i = iSize-1;
  4410. }
  4411. else
  4412. {
  4413. MY_ASSERT(FALSE);
  4414. i = iSize-3;
  4415. }
  4416. MY_ASSERT(i<m_pnList.size());
  4417. ppn = &m_pnList[i];
  4418. MY_ASSERT(foundInstID<ppn->instList.size());
  4419. pinst = &ppn->instList[foundInstID];
  4420. pinst->bNull = FALSE;
  4421. pinst->bNeeded = TRUE;
  4422. // Also for all thresholds under this DataCollector
  4423. // Only add the CollectionInstanceCount instance to the Threshold looking at
  4424. // the CollectionInstanceCount property. Same for CollectionErrorCode and CollectionErrorDescription.
  4425. iSize = m_thresholdList.size();
  4426. for (i=0; i < iSize ; i++)
  4427. {
  4428. MY_ASSERT(i<m_thresholdList.size());
  4429. pThreshold = m_thresholdList[i];
  4430. pszPropertyName = pThreshold->GetPropertyName();
  4431. if (!_wcsicmp(pszPropertyName, pszInstanceID) ||
  4432. !_wcsicmp(pszPropertyName, pszInstanceID) ||
  4433. !_wcsicmp(pszPropertyName, pszInstanceID))
  4434. {
  4435. MY_ASSERT(foundInstID<pThreshold->m_irsList.size());
  4436. pirs = &pThreshold->m_irsList[foundInstID];
  4437. pirs->bNeeded = TRUE;
  4438. }
  4439. }
  4440. }
  4441. }
  4442. if (pObj)
  4443. {
  4444. hRetRes = CheckActualInstanceExistance(pObj, pszInstanceID);
  4445. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4446. }
  4447. return hRetRes;
  4448. error:
  4449. MY_ASSERT(FALSE);
  4450. m_bValidLoad = FALSE;
  4451. Cleanup(FALSE);
  4452. return hRetRes;
  4453. }
  4454. HRESULT CDataCollector::CheckActualInstanceExistance(IWbemClassObject *pObj, LPTSTR pszInstanceID)
  4455. {
  4456. HRESULT hRetRes = S_OK;
  4457. BOOL bFound;
  4458. int i, iSize;
  4459. INSTSTRUCT inst;
  4460. ACTUALINSTSTRUCT actualInst;
  4461. ACTUALINSTSTRUCT *pActualInst;
  4462. if (m_bValidLoad == FALSE)
  4463. return FALSE;
  4464. //
  4465. // Check the list of actual instances that the Data Collector is collecting.
  4466. // We keep around the latest one(s) for the DataCollector.
  4467. //
  4468. bFound = FALSE;
  4469. iSize = m_actualInstList.size();
  4470. for (i=0; i < iSize; i++)
  4471. {
  4472. MY_ASSERT(i<m_actualInstList.size());
  4473. pActualInst = &m_actualInstList[i];
  4474. if (!_wcsicmp(pActualInst->szInstanceID, pszInstanceID))
  4475. {
  4476. pActualInst->bNeeded = TRUE;
  4477. if (pActualInst->pInst)
  4478. {
  4479. pActualInst->pInst->Release();
  4480. pActualInst->pInst = NULL;
  4481. }
  4482. hRetRes = pObj->Clone(&pActualInst->pInst);
  4483. if (FAILED(hRetRes))
  4484. {
  4485. MY_HRESASSERT(hRetRes);
  4486. return hRetRes;
  4487. }
  4488. bFound = TRUE;
  4489. break;
  4490. }
  4491. }
  4492. if (bFound == FALSE)
  4493. {
  4494. actualInst.szInstanceID = new TCHAR[wcslen(pszInstanceID)+2];
  4495. MY_ASSERT(actualInst.szInstanceID); if (!actualInst.szInstanceID) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4496. wcscpy(actualInst.szInstanceID, pszInstanceID);
  4497. actualInst.pInst = NULL;
  4498. actualInst.bNeeded = TRUE;
  4499. wcscpy(actualInst.szDTTime, m_szDTCurrTime);
  4500. wcscpy(actualInst.szTime, m_szCurrTime);
  4501. hRetRes = pObj->Clone(&actualInst.pInst);
  4502. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4503. m_actualInstList.push_back(actualInst);
  4504. }
  4505. return hRetRes;
  4506. error:
  4507. MY_ASSERT(FALSE);
  4508. m_bValidLoad = FALSE;
  4509. Cleanup(FALSE);
  4510. return hRetRes;
  4511. }
  4512. BOOL CDataCollector::GetEnabledChange(void)
  4513. {
  4514. BOOL bChanged = FALSE;
  4515. if ((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState!=HM_DISABLED)
  4516. {
  4517. bChanged = TRUE;
  4518. }
  4519. if ((m_bEnabled==TRUE && m_bParentEnabled==TRUE) && m_lCurrState==HM_DISABLED)
  4520. {
  4521. bChanged = TRUE;
  4522. }
  4523. return bChanged;
  4524. }
  4525. BOOL CDataCollector::SetCurrState(HM_STATE state, BOOL bCheckChanges/*FALSE*/)
  4526. {
  4527. m_lCurrState = state;
  4528. return TRUE;
  4529. }
  4530. BOOL CDataCollector::checkTime(void)
  4531. {
  4532. BOOL bTimeOK;
  4533. SYSTEMTIME st; // system time
  4534. //
  4535. // Make sure that we are in a valid time to run.
  4536. // NULL (-1) means run all the time.
  4537. //
  4538. bTimeOK = FALSE;
  4539. if (m_bEnabled==TRUE && m_bParentEnabled==TRUE)
  4540. {
  4541. GetLocalTime(&st);
  4542. bTimeOK = FALSE;
  4543. // Check the Day of the Week
  4544. if (!(m_iActiveDays&(1<<st.wDayOfWeek)))
  4545. {
  4546. }
  4547. else if (m_lBeginHourTime<0 || m_lEndHourTime<0)
  4548. {
  4549. bTimeOK = TRUE;
  4550. }
  4551. else if (m_lBeginHourTime==m_lEndHourTime && m_lBeginMinuteTime==m_lEndMinuteTime)
  4552. {
  4553. // Check the Hours of operation
  4554. // First see if we are doing an inclusive time tests, or an exclusive time test
  4555. //XXXStill need work here. What happens when we have the collection interval set
  4556. //to go off every 10 seconds. We will keep doing this
  4557. // Case where the time is exactly equal, and that means run this once per day
  4558. if (st.wHour==m_lBeginHourTime && st.wMinute==m_lBeginMinuteTime)
  4559. {
  4560. if (st.wSecond <= HM_POLLING_INTERVAL)
  4561. {
  4562. bTimeOK = TRUE;
  4563. }
  4564. }
  4565. }
  4566. else if ((m_lBeginHourTime < m_lEndHourTime) ||
  4567. ((m_lBeginHourTime==m_lEndHourTime) && m_lBeginMinuteTime < m_lEndMinuteTime))
  4568. {
  4569. // Inclusive case
  4570. if ((m_lBeginHourTime < st.wHour) ||
  4571. ((m_lBeginHourTime == st.wHour) && m_lBeginMinuteTime <= st.wMinute))
  4572. {
  4573. if ((st.wHour < m_lEndHourTime) ||
  4574. ((st.wHour == m_lEndHourTime) && st.wMinute < m_lEndMinuteTime))
  4575. {
  4576. bTimeOK = TRUE;
  4577. }
  4578. }
  4579. }
  4580. else
  4581. {
  4582. // Exclusive case
  4583. if ((m_lEndHourTime > st.wHour) ||
  4584. ((m_lEndHourTime == st.wHour) && m_lEndMinuteTime > st.wMinute))
  4585. {
  4586. bTimeOK = TRUE;
  4587. }
  4588. else if ((st.wHour > m_lBeginHourTime) ||
  4589. ((st.wHour == m_lBeginHourTime) && st.wMinute >= m_lBeginMinuteTime))
  4590. {
  4591. bTimeOK = TRUE;
  4592. }
  4593. }
  4594. }
  4595. return bTimeOK;
  4596. }
  4597. HRESULT CDataCollector::GetHMDataCollectorPerInstanceStatusEvent(LPTSTR pszInstanceID, ACTUALINSTSTRUCT *pActualInst, long state, IWbemClassObject** ppInstance, BOOL bEventBased)
  4598. {
  4599. HRESULT hRetRes = S_OK;
  4600. GUID guid;
  4601. BSTR bsName = NULL;
  4602. VARIANT v;
  4603. IWbemClassObject* pEmbeddedDataCollectorInst = NULL;
  4604. IWbemClassObject* pClass = NULL;
  4605. BSTR bsString = NULL;
  4606. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 2;
  4607. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 2];
  4608. TCHAR szStatusGUID[1024];
  4609. VariantInit(&v);
  4610. MY_OUTPUT(L"ENTER *****CDataCollector::GetHMDataCollectorPerInstanceStatusEvent...", 1);
  4611. if (bEventBased)
  4612. {
  4613. bsString = SysAllocString(L"MicrosoftHM_DataCollectorPerInstanceStatusEvent");
  4614. MY_ASSERT(bsString); if (!bsString) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4615. }
  4616. else
  4617. {
  4618. bsString = SysAllocString(L"MicrosoftHM_DataCollectorPerInstanceStatus");
  4619. MY_ASSERT(bsString); if (!bsString) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4620. }
  4621. hRetRes = g_pIWbemServices->GetObject(bsString, 0L, NULL, &pClass, NULL);
  4622. SysFreeString(bsString);
  4623. bsString = NULL;
  4624. if (FAILED(hRetRes))
  4625. {
  4626. MY_HRESASSERT(hRetRes);
  4627. return hRetRes;
  4628. }
  4629. hRetRes = pClass->SpawnInstance(0, ppInstance);
  4630. pClass->Release();
  4631. pClass = NULL;
  4632. if (FAILED(hRetRes))
  4633. {
  4634. MY_HRESASSERT(hRetRes);
  4635. return hRetRes;
  4636. }
  4637. hRetRes = CoCreateGuid(&guid);
  4638. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4639. StringFromGUID2(guid, szStatusGUID, 100);
  4640. hRetRes = PutStrProperty(*ppInstance, L"GUID", m_szGUID);
  4641. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4642. hRetRes = PutStrProperty(*ppInstance, L"InstanceName", pszInstanceID);
  4643. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4644. hRetRes = PutStrProperty(*ppInstance, L"Name", m_szName);
  4645. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4646. hRetRes = PutStrProperty(*ppInstance, L"ParentGUID", m_pParentDG->m_szGUID);
  4647. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4648. hRetRes = PutUint32Property(*ppInstance, L"State", state);
  4649. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4650. hRetRes = PutUint32Property(*ppInstance, L"CollectionInstanceCount", m_lNumInstancesCollected);
  4651. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4652. hRetRes = PutUUint32Property(*ppInstance, L"CollectionErrorCode", m_ulErrorCode);
  4653. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4654. hRetRes = PutStrProperty(*ppInstance, L"CollectionErrorDescription", m_szErrorDescription);
  4655. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4656. hRetRes = PutStrProperty(*ppInstance, L"StatusGUID", szStatusGUID);
  4657. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4658. if (pActualInst)
  4659. {
  4660. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", pActualInst->szDTTime);
  4661. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4662. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", pActualInst->szTime);
  4663. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4664. }
  4665. else if (!wcscmp(pszInstanceID, L"CollectionInstanceCount"))
  4666. {
  4667. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", m_szDTCICTime);
  4668. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4669. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", m_szCICTime);
  4670. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4671. }
  4672. else if (!wcscmp(pszInstanceID, L"CollectionErrorCode"))
  4673. {
  4674. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", m_szDTCECTime);
  4675. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4676. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", m_szCECTime);
  4677. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4678. }
  4679. else
  4680. {
  4681. MY_ASSERT(FALSE);
  4682. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", m_szDTCurrTime);
  4683. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4684. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", m_szCurrTime);
  4685. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4686. }
  4687. // Get the computer name of the machine
  4688. if (GetComputerName(szComputerName, &dwNameLen))
  4689. {
  4690. hRetRes = PutStrProperty(*ppInstance, L"SystemName", szComputerName);
  4691. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4692. }
  4693. else
  4694. {
  4695. hRetRes = PutStrProperty(*ppInstance, L"SystemName", L"LocalMachine");
  4696. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4697. }
  4698. if (state != HM_GOOD)
  4699. {
  4700. hRetRes = PutStrProperty(*ppInstance, L"Message", m_szMessage);
  4701. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4702. }
  4703. else
  4704. {
  4705. hRetRes = PutStrProperty(*ppInstance, L"Message", m_szResetMessage);
  4706. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4707. }
  4708. if (pActualInst)
  4709. {
  4710. hRetRes = FormatMessage(*ppInstance, pActualInst->pInst);
  4711. }
  4712. else
  4713. {
  4714. hRetRes = FormatMessage(*ppInstance, NULL);
  4715. }
  4716. //XXX
  4717. //Make sure that this code is correct
  4718. if (pActualInst && hRetRes==S_OK && m_bValidLoad)
  4719. {
  4720. hRetRes = pActualInst->pInst->Clone(&pEmbeddedDataCollectorInst);
  4721. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4722. if (pEmbeddedDataCollectorInst)
  4723. {
  4724. bsName = SysAllocString(L"EmbeddedCollectedInstance");
  4725. MY_ASSERT(bsName); if (!bsName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4726. VariantInit(&v);
  4727. V_VT(&v) = VT_UNKNOWN;
  4728. V_UNKNOWN(&v) = (IUnknown*)pEmbeddedDataCollectorInst;
  4729. (V_UNKNOWN(&v))->AddRef();
  4730. hRetRes = (*ppInstance)->Put(bsName, 0L, &v, 0L);
  4731. VariantClear(&v);
  4732. SysFreeString(bsName);
  4733. bsName = NULL;
  4734. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4735. pEmbeddedDataCollectorInst->Release();
  4736. pEmbeddedDataCollectorInst = NULL;
  4737. }
  4738. }
  4739. MY_OUTPUT(L"EXIT *****CDataCollector::GetHMDataCollectorPerInstanceStatusEvent...", 1);
  4740. return hRetRes;
  4741. error:
  4742. MY_ASSERT(FALSE);
  4743. if (bsString)
  4744. SysFreeString(bsString);
  4745. if (bsName)
  4746. SysFreeString(bsName);
  4747. if (pClass)
  4748. pClass->Release();
  4749. if (pEmbeddedDataCollectorInst)
  4750. pEmbeddedDataCollectorInst->Release();
  4751. m_bValidLoad = FALSE;
  4752. Cleanup(FALSE);
  4753. return hRetRes;
  4754. }
  4755. //
  4756. // Do string replacement for the Message property
  4757. //
  4758. HRESULT CDataCollector::FormatMessage(IWbemClassObject* pIRSInstance, IWbemClassObject *pEmbeddedInstance)
  4759. {
  4760. HRESULT hRetRes = S_OK;
  4761. BSTR PropName = NULL;
  4762. LPTSTR pszMsg = NULL;
  4763. SAFEARRAY *psaNames = NULL;
  4764. long lNum;
  4765. LPTSTR pszDest = NULL;
  4766. LPTSTR pszUpperMsg = NULL;
  4767. LPTSTR pszNewMsg = NULL;
  4768. LPTSTR pStr = NULL;
  4769. LPTSTR pStr2 = NULL;
  4770. LPTSTR pStrStart = NULL;
  4771. TOKENSTRUCT tokenElmnt;
  4772. TOKENSTRUCT *pTokenElmnt;
  4773. REPSTRUCT repElmnt;
  4774. REPSTRUCT *pRepElmnt;
  4775. REPSTRUCT *pRepElmnt2;
  4776. REPLIST replacementList;
  4777. int i, iSize, iSizeNeeded, j;
  4778. long lLower, lUpper;
  4779. static TOKENLIST tokenList;
  4780. TOKENLIST embeddedInstTokenList;
  4781. if (m_bValidLoad == FALSE)
  4782. return FALSE;
  4783. //
  4784. // We only need to build the set of tokens one time, then from then on
  4785. // we just need to fill in the values for what the replacement strings are.
  4786. //
  4787. if (tokenList.size() == 0)
  4788. {
  4789. //
  4790. // First we build the set of tokens that we are looking for. Each property that
  4791. // is in the ThresholdStatusInstance. We build that set of strings,
  4792. // and the values to replace with.
  4793. //
  4794. //
  4795. // Now go through ThresholdInstance, which is where the Message String
  4796. // actually lives. Get that set of properties for the Instances.
  4797. //
  4798. hRetRes = pIRSInstance->GetNames(NULL, WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
  4799. if (SUCCEEDED(hRetRes))
  4800. {
  4801. // Get the number of properties.
  4802. SafeArrayGetLBound(psaNames, 1, &lLower);
  4803. SafeArrayGetUBound(psaNames, 1, &lUpper);
  4804. // For each property...
  4805. for (long l=lLower; l<=lUpper; l++)
  4806. {
  4807. // Get this property.
  4808. hRetRes = SafeArrayGetElement(psaNames, &l, &PropName);
  4809. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4810. // Will want to skip some that don't make sense.
  4811. if (!wcscmp(PropName, L"Message"))
  4812. {
  4813. SysFreeString(PropName);
  4814. PropName = NULL;
  4815. continue;
  4816. }
  4817. else if (!wcscmp(PropName, L"ResetMessage"))
  4818. {
  4819. SysFreeString(PropName);
  4820. PropName = NULL;
  4821. continue;
  4822. }
  4823. else if (!wcscmp(PropName, L"EmbeddedCollectedInstance"))
  4824. {
  4825. SysFreeString(PropName);
  4826. PropName = NULL;
  4827. continue;
  4828. }
  4829. tokenElmnt.szOrigToken = new TCHAR[wcslen(PropName)+1];
  4830. MY_ASSERT(tokenElmnt.szOrigToken); if (!tokenElmnt.szOrigToken) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4831. wcscpy(tokenElmnt.szOrigToken, PropName);
  4832. tokenElmnt.szToken = new TCHAR[wcslen(PropName)+3];
  4833. MY_ASSERT(tokenElmnt.szToken); if (!tokenElmnt.szToken) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4834. wcscpy(tokenElmnt.szToken, L"%");
  4835. wcscat(tokenElmnt.szToken, PropName);
  4836. wcscat(tokenElmnt.szToken, L"%");
  4837. _wcsupr(tokenElmnt.szToken);
  4838. tokenElmnt.szReplacementText = NULL;
  4839. tokenList.push_back(tokenElmnt);
  4840. SysFreeString(PropName);
  4841. PropName = NULL;
  4842. }
  4843. SafeArrayDestroy(psaNames);
  4844. psaNames = NULL;
  4845. }
  4846. }
  4847. //
  4848. // Populate the list of properties on the embedded instance that came from the
  4849. // Data Collector.
  4850. //
  4851. if (pEmbeddedInstance)
  4852. {
  4853. MY_ASSERT(pEmbeddedInstance);
  4854. hRetRes = pEmbeddedInstance->GetNames(NULL, WBEM_FLAG_ALWAYS, NULL, &psaNames);
  4855. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4856. // Get the number of properties.
  4857. SafeArrayGetLBound(psaNames, 1, &lLower);
  4858. SafeArrayGetUBound(psaNames, 1, &lUpper);
  4859. // For each property...
  4860. for (long l=lLower; l<=lUpper; l++)
  4861. {
  4862. // Get this property.
  4863. hRetRes = SafeArrayGetElement(psaNames, &l, &PropName);
  4864. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4865. tokenElmnt.szOrigToken = new TCHAR[wcslen(PropName)+1];
  4866. MY_ASSERT(tokenElmnt.szOrigToken); if (!tokenElmnt.szOrigToken) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4867. wcscpy(tokenElmnt.szOrigToken, PropName);
  4868. tokenElmnt.szToken = new TCHAR[wcslen(PropName)+29];
  4869. MY_ASSERT(tokenElmnt.szToken); if (!tokenElmnt.szToken) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4870. wcscpy(tokenElmnt.szToken, L"%");
  4871. wcscat(tokenElmnt.szToken, L"EmbeddedCollectedInstance.");
  4872. wcscat(tokenElmnt.szToken, PropName);
  4873. wcscat(tokenElmnt.szToken, L"%");
  4874. _wcsupr(tokenElmnt.szToken);
  4875. tokenElmnt.szReplacementText = NULL;
  4876. embeddedInstTokenList.push_back(tokenElmnt);
  4877. SysFreeString(PropName);
  4878. PropName = NULL;
  4879. }
  4880. SafeArrayDestroy(psaNames);
  4881. psaNames = NULL;
  4882. }
  4883. //
  4884. // Now we can fill in the values to use for the replacement strings.
  4885. //
  4886. //
  4887. // Now go through each ThresholdInstance, which is where the Message String
  4888. // actually lives. Get that set of properties of the Instance,
  4889. // And do the message formatting while there.
  4890. //
  4891. //
  4892. // Get the replacement strings for this instance
  4893. //
  4894. iSize = tokenList.size();
  4895. for (i=0; i<iSize; i++)
  4896. {
  4897. MY_ASSERT(i<tokenList.size());
  4898. pTokenElmnt = &tokenList[i];
  4899. if (pTokenElmnt->szReplacementText != NULL)
  4900. {
  4901. delete [] pTokenElmnt->szReplacementText;
  4902. pTokenElmnt->szReplacementText = NULL;
  4903. }
  4904. if (!wcscmp(pTokenElmnt->szToken, L"%TESTCONDITION%"))
  4905. {
  4906. hRetRes = GetUint32Property(pIRSInstance, pTokenElmnt->szOrigToken, &lNum);
  4907. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4908. MY_ASSERT(lNum<9);
  4909. pStr = new TCHAR[wcslen(conditionLocStr[lNum])+1];
  4910. MY_ASSERT(pStr); if (!pStr) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4911. wcscpy(pStr, conditionLocStr[lNum]);
  4912. }
  4913. else if (!wcscmp(pTokenElmnt->szToken, L"%STATE%"))
  4914. {
  4915. hRetRes = GetUint32Property(pIRSInstance, pTokenElmnt->szOrigToken, &lNum);
  4916. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4917. MY_ASSERT(lNum<10);
  4918. pStr = new TCHAR[wcslen(stateLocStr[lNum])+1];
  4919. MY_ASSERT(pStr); if (!pStr) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4920. wcscpy(pStr, stateLocStr[lNum]);
  4921. }
  4922. else
  4923. {
  4924. hRetRes = GetAsStrProperty(pIRSInstance, pTokenElmnt->szOrigToken, &pStr);
  4925. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4926. }
  4927. pTokenElmnt->szReplacementText = pStr;
  4928. }
  4929. //
  4930. // Get the replacement strings for this instance - Embedded
  4931. //
  4932. iSize = embeddedInstTokenList.size();
  4933. for (i=0; i<iSize; i++)
  4934. {
  4935. MY_ASSERT(i<embeddedInstTokenList.size());
  4936. pTokenElmnt = &embeddedInstTokenList[i];
  4937. if (pTokenElmnt->szReplacementText != NULL)
  4938. {
  4939. delete [] pTokenElmnt->szReplacementText;
  4940. pTokenElmnt->szReplacementText = NULL;
  4941. }
  4942. MY_ASSERT(pEmbeddedInstance);
  4943. hRetRes = GetAsStrProperty(pEmbeddedInstance, pTokenElmnt->szOrigToken, &pStr);
  4944. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4945. pTokenElmnt->szReplacementText = pStr;
  4946. }
  4947. //
  4948. // Now we have both lists of tokens that have replacement
  4949. // strings that go with them and the replacement strings
  4950. // that go with them
  4951. //
  4952. //
  4953. // Do formatting of Message. We replace all Variable Tags.
  4954. // Sample string -
  4955. // "Drive %InstanceName% is full. Currently at %CurrentValue%%."
  4956. //
  4957. //
  4958. // Get the origional un-formatted message first.
  4959. // To make case in-sensitive, do a _strdup and then a _wcsupr on the string
  4960. // to scan run the code on it, and then free the duplicated string.
  4961. //
  4962. // If it uses resource IDs, then get that string first, then format that!!!
  4963. hRetRes = GetStrProperty(pIRSInstance, L"Message", &pszMsg);
  4964. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4965. pszUpperMsg = _wcsdup(pszMsg);
  4966. MY_ASSERT(pszUpperMsg); if (!pszUpperMsg) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4967. _wcsupr(pszUpperMsg);
  4968. //
  4969. // First loop through and find every token that needs replacing.
  4970. // Put that info into the replacement list.
  4971. //
  4972. // We will do strstr() for each special token until there are no more to find
  4973. // for each. At each find we will store the offset into the string of what
  4974. // we found. Then we sort by what came first.
  4975. //
  4976. // Quick test to see if it is worth searching
  4977. if (wcschr(pszUpperMsg, '%'))
  4978. {
  4979. iSize = tokenList.size();
  4980. pStrStart = pszUpperMsg;
  4981. for (i=0; i<iSize; i++)
  4982. {
  4983. MY_ASSERT(i<tokenList.size());
  4984. pTokenElmnt = &tokenList[i];
  4985. pStr = wcsstr(pStrStart, pTokenElmnt->szToken);
  4986. if (pStr != NULL)
  4987. {
  4988. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  4989. repElmnt.len = wcslen(pTokenElmnt->szToken);
  4990. repElmnt.pszReplacementText = pTokenElmnt->szReplacementText;
  4991. replacementList.push_back(repElmnt);
  4992. i--;
  4993. pStrStart = pStr+1;
  4994. }
  4995. else
  4996. {
  4997. pStrStart = pszUpperMsg;
  4998. }
  4999. }
  5000. // Embedded stuff
  5001. iSize = embeddedInstTokenList.size();
  5002. pStrStart = pszUpperMsg;
  5003. for (i=0; i<iSize; i++)
  5004. {
  5005. MY_ASSERT(i<embeddedInstTokenList.size());
  5006. pTokenElmnt = &embeddedInstTokenList[i];
  5007. pStr = wcsstr(pStrStart, pTokenElmnt->szToken);
  5008. if (pStr != NULL)
  5009. {
  5010. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  5011. repElmnt.len = wcslen(pTokenElmnt->szToken);
  5012. repElmnt.pszReplacementText = pTokenElmnt->szReplacementText;
  5013. replacementList.push_back(repElmnt);
  5014. i--;
  5015. pStrStart = pStr+1;
  5016. }
  5017. else
  5018. {
  5019. pStrStart = pszUpperMsg;
  5020. }
  5021. }
  5022. //
  5023. // Need to look for replacement strings that have not been replaced.
  5024. // Simply search for %EmbeddedCollectedInstance. and find the end % for each
  5025. // Replace them with <null>
  5026. //
  5027. if (!pEmbeddedInstance)
  5028. {
  5029. pStrStart = pszUpperMsg;
  5030. while (TRUE)
  5031. {
  5032. pStr = wcsstr(pStrStart, L"%EMBEDDEDCOLLECTEDINSTANCE.");
  5033. if (pStr != NULL)
  5034. {
  5035. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  5036. pStr2 = pStr;
  5037. while (pStr2++)
  5038. {
  5039. if (*pStr2=='%' || iswspace(*pStr2))
  5040. break;
  5041. }
  5042. if (*pStr2=='%')
  5043. {
  5044. repElmnt.len = (pStr2-pStr)+1;
  5045. repElmnt.pszReplacementText = L"<null>";
  5046. replacementList.push_back(repElmnt);
  5047. }
  5048. pStrStart = pStr+1;
  5049. }
  5050. else
  5051. {
  5052. break;
  5053. }
  5054. }
  5055. }
  5056. }
  5057. iSize = replacementList.size();
  5058. if (iSize != 0)
  5059. {
  5060. //
  5061. // Next, sort the replacement list from the first string to
  5062. // be replaced, to the last. Shell sort, Knuth, Vol13, pg. 84.
  5063. //
  5064. for (int gap=iSize/2; 0<gap; gap/=2)
  5065. {
  5066. for (i=gap; i<iSize; i++)
  5067. {
  5068. for (j=i-gap; 0<=j; j-=gap)
  5069. {
  5070. MY_ASSERT(j+gap<replacementList.size());
  5071. pRepElmnt = &replacementList[j+gap];
  5072. MY_ASSERT(j<replacementList.size());
  5073. pRepElmnt2 = &replacementList[j];
  5074. if (pRepElmnt->pStartStr < pRepElmnt2->pStartStr)
  5075. {
  5076. MY_ASSERT(j<replacementList.size());
  5077. repElmnt = replacementList[j];
  5078. MY_ASSERT(j+gap<replacementList.size());
  5079. replacementList[j] = replacementList[j+gap];
  5080. MY_ASSERT(j+gap<replacementList.size());
  5081. replacementList[j+gap] = repElmnt;
  5082. }
  5083. }
  5084. }
  5085. }
  5086. //
  5087. // Next, figure out the size needed for the Message with
  5088. // everything replaced.
  5089. //
  5090. iSizeNeeded = wcslen(pszMsg)+1;
  5091. iSize = replacementList.size();
  5092. for (i=0; i<iSize; i++)
  5093. {
  5094. MY_ASSERT(i<replacementList.size());
  5095. pRepElmnt = &replacementList[i];
  5096. iSizeNeeded -= pRepElmnt->len;
  5097. iSizeNeeded += wcslen(pRepElmnt->pszReplacementText);
  5098. }
  5099. pszNewMsg = new TCHAR[iSizeNeeded];
  5100. MY_ASSERT(pszNewMsg); if (!pszNewMsg) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  5101. *pszNewMsg = '\0';
  5102. //
  5103. // Next, we loop through and do the actual replacements.
  5104. // "Drive %InstanceName% is full. Currently at %CurrentValue%%."
  5105. //
  5106. pszDest = pszMsg;
  5107. iSize = replacementList.size();
  5108. for (i=0; i<iSize; i++)
  5109. {
  5110. MY_ASSERT(i<replacementList.size());
  5111. pRepElmnt = &replacementList[i];
  5112. *(pRepElmnt->pStartStr) = '\0';
  5113. wcscat(pszNewMsg, pszDest);
  5114. wcscat(pszNewMsg, pRepElmnt->pszReplacementText);
  5115. //XXXWould memcpy be faster??? memcpy(pszDest, source, charCnt*sizeof(TCHAR));
  5116. pszDest = pRepElmnt->pStartStr+pRepElmnt->len;
  5117. }
  5118. wcscat(pszNewMsg, pszDest);
  5119. PutStrProperty(pIRSInstance, L"Message", pszNewMsg);
  5120. delete [] pszNewMsg;
  5121. pszNewMsg = NULL;
  5122. replacementList.clear();
  5123. }
  5124. else
  5125. {
  5126. PutStrProperty(pIRSInstance, L"Message", pszMsg);
  5127. }
  5128. delete [] pszMsg;
  5129. pszMsg = NULL;
  5130. free(pszUpperMsg);
  5131. pszUpperMsg = NULL;
  5132. // Free up the temporary token list
  5133. iSize = embeddedInstTokenList.size();
  5134. for (i=0; i<iSize; i++)
  5135. {
  5136. MY_ASSERT(i<embeddedInstTokenList.size());
  5137. pTokenElmnt = &embeddedInstTokenList[i];
  5138. if (pTokenElmnt->szToken)
  5139. delete [] pTokenElmnt->szToken;
  5140. if (pTokenElmnt->szOrigToken)
  5141. delete [] pTokenElmnt->szOrigToken;
  5142. if (pTokenElmnt->szReplacementText)
  5143. delete [] pTokenElmnt->szReplacementText;
  5144. }
  5145. embeddedInstTokenList.clear();
  5146. return hRetRes;
  5147. error:
  5148. MY_ASSERT(FALSE);
  5149. if (PropName)
  5150. SysFreeString(PropName);
  5151. if (psaNames)
  5152. SafeArrayDestroy(psaNames);
  5153. if (pszNewMsg)
  5154. delete [] pszNewMsg;
  5155. if (pszMsg)
  5156. delete [] pszMsg;
  5157. if (pszUpperMsg)
  5158. free(pszUpperMsg);
  5159. iSize = embeddedInstTokenList.size();
  5160. for (i=0; i<iSize; i++)
  5161. {
  5162. MY_ASSERT(i<embeddedInstTokenList.size());
  5163. pTokenElmnt = &embeddedInstTokenList[i];
  5164. if (pTokenElmnt->szToken)
  5165. delete [] pTokenElmnt->szToken;
  5166. if (pTokenElmnt->szOrigToken)
  5167. delete [] pTokenElmnt->szOrigToken;
  5168. if (pTokenElmnt->szReplacementText)
  5169. delete [] pTokenElmnt->szReplacementText;
  5170. }
  5171. embeddedInstTokenList.clear();
  5172. m_bValidLoad = FALSE;
  5173. Cleanup(FALSE);
  5174. return hRetRes;
  5175. }
  5176. BOOL CDataCollector::SendReminderActionIfStateIsSame(IWbemObjectSink* pActionEventSink, IWbemObjectSink* pActionTriggerEventSink, IWbemClassObject* pActionInstance, IWbemClassObject* pActionTriggerInstance, unsigned long ulTriggerStates)
  5177. {
  5178. HRESULT hRetRes = S_OK;
  5179. IWbemClassObject* pInstance = NULL;
  5180. BSTR bsName = NULL;
  5181. VARIANT v;
  5182. long state;
  5183. int i, iSize;
  5184. BOOL bRetValue = TRUE;
  5185. ACTUALINSTSTRUCT *pActualInst;
  5186. long firstInstanceState = -1;
  5187. GUID guid;
  5188. TCHAR szStatusGUID[100];
  5189. VariantInit(&v);
  5190. MY_OUTPUT(L"ENTER ***** CDataCollector::SendReminderActionIfStateIsSame...", 2);
  5191. if (m_bValidLoad == FALSE)
  5192. return FALSE;
  5193. //
  5194. // We can loop through the set of collected instances and ask each Threshold
  5195. // to tell us if the state has changed as far as each is concerned, for the
  5196. // property they are lookin at.
  5197. //
  5198. iSize = m_actualInstList.size();
  5199. for (i=0; i < iSize; i++)
  5200. {
  5201. MY_ASSERT(i<m_actualInstList.size());
  5202. pActualInst = &m_actualInstList[i];
  5203. state = PassBackWorstStatePerInstance(pActualInst->szInstanceID, (BOOL)i==0);
  5204. if (state==-1) state = HM_COLLECTING;
  5205. if (i==0)
  5206. {
  5207. firstInstanceState = state;
  5208. }
  5209. // Check to see if still in the desired state
  5210. if (!(ulTriggerStates&(1<<state)))
  5211. {
  5212. continue;
  5213. }
  5214. hRetRes = GetHMDataCollectorPerInstanceStatusEvent(pActualInst->szInstanceID, pActualInst, state, &pInstance, TRUE);
  5215. if (SUCCEEDED(hRetRes))
  5216. {
  5217. PutUint32Property(pActionTriggerInstance, L"State", m_lCurrState);
  5218. bsName = SysAllocString(L"EmbeddedStatusEvent");
  5219. MY_ASSERT(bsName); if (!bsName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  5220. VariantInit(&v);
  5221. V_VT(&v) = VT_UNKNOWN;
  5222. V_UNKNOWN(&v) = (IUnknown*)pInstance;
  5223. (V_UNKNOWN(&v))->AddRef();
  5224. hRetRes = (pActionTriggerInstance)->Put(bsName, 0L, &v, 0L);
  5225. VariantClear(&v);
  5226. SysFreeString(bsName);
  5227. bsName = NULL;
  5228. MY_HRESASSERT(hRetRes);
  5229. if (pActionEventSink)
  5230. {
  5231. hRetRes = CoCreateGuid(&guid);
  5232. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  5233. StringFromGUID2(guid, szStatusGUID, 100);
  5234. hRetRes = PutStrProperty(pActionInstance, L"StatusGUID", szStatusGUID);
  5235. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  5236. hRetRes = pActionEventSink->Indicate(1, &pActionInstance);
  5237. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  5238. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  5239. {
  5240. MY_HRESASSERT(hRetRes);
  5241. MY_OUTPUT(L"Failed on Indicate!", 4);
  5242. }
  5243. }
  5244. if (pActionTriggerEventSink)
  5245. {
  5246. hRetRes = pActionTriggerEventSink->Indicate(1, &pActionTriggerInstance);
  5247. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  5248. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  5249. {
  5250. MY_HRESASSERT(hRetRes);
  5251. MY_OUTPUT(L"Failed on Indicate!", 4);
  5252. }
  5253. }
  5254. pInstance->Release();
  5255. pInstance = NULL;
  5256. }
  5257. else
  5258. {
  5259. MY_HRESASSERT(hRetRes);
  5260. MY_OUTPUT(L"failed to get instance!", 4);
  5261. }
  5262. }
  5263. //
  5264. // Do it for the three default properties
  5265. //
  5266. if (firstInstanceState==-1)
  5267. {
  5268. state = PassBackWorstStatePerInstance(L"CollectionInstanceCount", FALSE);
  5269. if (state==-1) state = HM_COLLECTING;
  5270. // Check to see if still in the desired state
  5271. if ((ulTriggerStates&(1<<state)))
  5272. {
  5273. hRetRes = GetHMDataCollectorPerInstanceStatusEvent(L"CollectionInstanceCount", NULL, state, &pInstance, TRUE);
  5274. if (SUCCEEDED(hRetRes))
  5275. {
  5276. PutUint32Property(pActionTriggerInstance, L"State", m_lCurrState);
  5277. bsName = SysAllocString(L"EmbeddedStatusEvent");
  5278. MY_ASSERT(bsName); if (!bsName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  5279. VariantInit(&v);
  5280. V_VT(&v) = VT_UNKNOWN;
  5281. V_UNKNOWN(&v) = (IUnknown*)pInstance;
  5282. (V_UNKNOWN(&v))->AddRef();
  5283. hRetRes = (pActionTriggerInstance)->Put(bsName, 0L, &v, 0L);
  5284. VariantClear(&v);
  5285. SysFreeString(bsName);
  5286. bsName = NULL;
  5287. MY_HRESASSERT(hRetRes);
  5288. if (pActionEventSink)
  5289. {
  5290. hRetRes = CoCreateGuid(&guid);
  5291. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  5292. StringFromGUID2(guid, szStatusGUID, 100);
  5293. hRetRes = PutStrProperty(pActionInstance, L"StatusGUID", szStatusGUID);
  5294. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  5295. hRetRes = pActionEventSink->Indicate(1, &pActionInstance);
  5296. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  5297. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  5298. {
  5299. MY_HRESASSERT(hRetRes);
  5300. MY_OUTPUT(L"Failed on Indicate!", 4);
  5301. }
  5302. }
  5303. if (pActionTriggerEventSink)
  5304. {
  5305. hRetRes = pActionTriggerEventSink->Indicate(1, &pActionTriggerInstance);
  5306. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  5307. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  5308. {
  5309. MY_HRESASSERT(hRetRes);
  5310. MY_OUTPUT(L"Failed on Indicate!", 4);
  5311. }
  5312. }
  5313. pInstance->Release();
  5314. pInstance = NULL;
  5315. }
  5316. else
  5317. {
  5318. MY_HRESASSERT(hRetRes);
  5319. MY_OUTPUT(L"failed to get instance!", 4);
  5320. }
  5321. }
  5322. }
  5323. if (firstInstanceState==-1)
  5324. {
  5325. state = PassBackWorstStatePerInstance(L"CollectionErrorCode", FALSE);
  5326. if (state==-1) state = HM_COLLECTING;
  5327. // Check to see if still in the desired state
  5328. if ((ulTriggerStates&(1<<state)))
  5329. {
  5330. hRetRes = GetHMDataCollectorPerInstanceStatusEvent(L"CollectionInstanceCount", NULL, state, &pInstance, TRUE);
  5331. if (SUCCEEDED(hRetRes))
  5332. {
  5333. PutUint32Property(pActionTriggerInstance, L"State", m_lCurrState);
  5334. bsName = SysAllocString(L"EmbeddedStatusEvent");
  5335. MY_ASSERT(bsName); if (!bsName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  5336. VariantInit(&v);
  5337. V_VT(&v) = VT_UNKNOWN;
  5338. V_UNKNOWN(&v) = (IUnknown*)pInstance;
  5339. (V_UNKNOWN(&v))->AddRef();
  5340. hRetRes = (pActionTriggerInstance)->Put(bsName, 0L, &v, 0L);
  5341. VariantClear(&v);
  5342. SysFreeString(bsName);
  5343. bsName = NULL;
  5344. MY_HRESASSERT(hRetRes);
  5345. if (pActionEventSink)
  5346. {
  5347. hRetRes = CoCreateGuid(&guid);
  5348. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  5349. StringFromGUID2(guid, szStatusGUID, 100);
  5350. hRetRes = PutStrProperty(pActionInstance, L"StatusGUID", szStatusGUID);
  5351. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  5352. hRetRes = pActionEventSink->Indicate(1, &pActionInstance);
  5353. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  5354. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  5355. {
  5356. MY_HRESASSERT(hRetRes);
  5357. MY_OUTPUT(L"Failed on Indicate!", 4);
  5358. }
  5359. }
  5360. if (pActionTriggerEventSink)
  5361. {
  5362. hRetRes = pActionTriggerEventSink->Indicate(1, &pActionTriggerInstance);
  5363. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  5364. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  5365. {
  5366. MY_HRESASSERT(hRetRes);
  5367. MY_OUTPUT(L"Failed on Indicate!", 4);
  5368. }
  5369. }
  5370. pInstance->Release();
  5371. pInstance = NULL;
  5372. }
  5373. else
  5374. {
  5375. MY_HRESASSERT(hRetRes);
  5376. MY_OUTPUT(L"failed to get instance!", 4);
  5377. }
  5378. }
  5379. }
  5380. #ifdef SAVE
  5381. state = PassBackWorstStatePerInstance(L"CollectionErrorDescription");
  5382. #endif
  5383. MY_OUTPUT(L"EXIT ***** CDataCollector::SendReminderActionIfStateIsSame...", 2);
  5384. return TRUE;
  5385. error:
  5386. MY_ASSERT(FALSE);
  5387. if (bsName)
  5388. SysFreeString(bsName);
  5389. if (pInstance)
  5390. pInstance->Release();
  5391. m_bValidLoad = FALSE;
  5392. Cleanup(FALSE);
  5393. return FALSE;
  5394. }
  5395. HRESULT CDataCollector::insertNewProperty(LPTSTR pszPropertyName)
  5396. {
  5397. HRESULT hRetRes = S_OK;
  5398. int i, iSize;
  5399. PNSTRUCT *ppn;
  5400. BOOL bFound = FALSE;
  5401. BOOL bDoInsert = FALSE;
  5402. PNSTRUCT pn;
  5403. PNLIST::iterator iaPN;
  5404. bFound = FALSE;
  5405. iaPN=m_pnList.begin();
  5406. iSize = m_pnList.size();
  5407. for (i=0; i<iSize; i++, iaPN++)
  5408. {
  5409. MY_ASSERT(i<m_pnList.size());
  5410. ppn = &m_pnList[i];
  5411. if (!_wcsicmp(ppn->szPropertyName, pszPropertyName))
  5412. {
  5413. bFound = TRUE;
  5414. ppn->iRefCount++;
  5415. break;
  5416. }
  5417. // We know it can't be further than this one, and we can insert here
  5418. if (!_wcsicmp(ppn->szPropertyName, L"CollectionInstanceCount"))
  5419. {
  5420. bDoInsert = TRUE;
  5421. break;
  5422. }
  5423. }
  5424. // Add it it is new!
  5425. if (bFound == FALSE)
  5426. {
  5427. pn.szPropertyName = new TCHAR[wcslen(pszPropertyName)+2];
  5428. MY_ASSERT(pn.szPropertyName); if (!pn.szPropertyName) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  5429. wcscpy(pn.szPropertyName, pszPropertyName);
  5430. pn.iRefCount = 1;
  5431. pn.type = 0;
  5432. if (bDoInsert)
  5433. {
  5434. m_pnList.insert(iaPN, pn);
  5435. }
  5436. else
  5437. {
  5438. m_pnList.push_back(pn);
  5439. }
  5440. }
  5441. return hRetRes;
  5442. error:
  5443. MY_ASSERT(FALSE);
  5444. m_bValidLoad = FALSE;
  5445. Cleanup(FALSE);
  5446. return hRetRes;
  5447. }
  5448. BOOL CDataCollector::propertyNotNeeded(LPTSTR pszPropertyName)
  5449. {
  5450. int j, jSize;
  5451. int k, kSize;
  5452. PNSTRUCT *ppn;
  5453. BOOL bAdded = FALSE;
  5454. PNLIST::iterator iaPN;
  5455. INSTSTRUCT *pinst;
  5456. //
  5457. // Delete the property if this Threshold was the last one that needed it.
  5458. // Refcount if there already.
  5459. //
  5460. iaPN=m_pnList.begin();
  5461. jSize = m_pnList.size();
  5462. for (j=0; j<jSize; j++, iaPN++)
  5463. {
  5464. MY_ASSERT(j<m_pnList.size());
  5465. ppn = &m_pnList[j];
  5466. if (!_wcsicmp(ppn->szPropertyName, pszPropertyName))
  5467. {
  5468. ppn->iRefCount--;
  5469. if (ppn->iRefCount==0)
  5470. {
  5471. kSize = ppn->instList.size();
  5472. for (k = 0; k < kSize ; k++)
  5473. {
  5474. MY_ASSERT(k<ppn->instList.size());
  5475. pinst = &ppn->instList[k];
  5476. if (pinst->szCurrValue)
  5477. {
  5478. delete [] pinst->szCurrValue;
  5479. }
  5480. if (pinst->szInstanceID)
  5481. {
  5482. delete [] pinst->szInstanceID;
  5483. }
  5484. pinst->valList.clear();
  5485. }
  5486. ppn->instList.clear();
  5487. m_pnList.erase(iaPN);
  5488. }
  5489. break;
  5490. }
  5491. // We know it can't be further than this one, and we can insert here
  5492. if (!_wcsicmp(ppn->szPropertyName, L"CollectionInstanceCount"))
  5493. {
  5494. break;
  5495. }
  5496. }
  5497. return TRUE;
  5498. }
  5499. BOOL CDataCollector::ResetInst(INSTSTRUCT *pinst, CIMTYPE type)
  5500. {
  5501. if (type == CIM_REAL32)
  5502. {
  5503. pinst->currValue.fValue = 0;
  5504. pinst->minValue.fValue = MAX_FLOAT;
  5505. pinst->maxValue.fValue = 0;
  5506. pinst->avgValue.fValue = 0;
  5507. }
  5508. else if (type == CIM_REAL64)
  5509. {
  5510. pinst->currValue.dValue = 0;
  5511. pinst->minValue.dValue = MAX_DOUBLE;
  5512. pinst->maxValue.dValue = 0;
  5513. pinst->avgValue.dValue = 0;
  5514. }
  5515. else if (type == CIM_SINT64)
  5516. {
  5517. pinst->currValue.i64Value = 0;
  5518. pinst->minValue.i64Value = MAX_I64;
  5519. pinst->maxValue.i64Value = 0;
  5520. pinst->avgValue.i64Value = 0;
  5521. }
  5522. else if (type == CIM_UINT64)
  5523. {
  5524. pinst->currValue.ui64Value = 0;
  5525. pinst->minValue.ui64Value = MAX_UI64;
  5526. pinst->maxValue.ui64Value = 0;
  5527. pinst->avgValue.ui64Value = 0;
  5528. }
  5529. else if (type == CIM_UINT32)
  5530. {
  5531. pinst->currValue.ulValue = 0;
  5532. pinst->minValue.ulValue = MAX_ULONG;
  5533. pinst->maxValue.ulValue = 0;
  5534. pinst->avgValue.ulValue = 0;
  5535. }
  5536. else
  5537. {
  5538. pinst->currValue.lValue = 0;
  5539. pinst->minValue.lValue = MAX_LONG;
  5540. pinst->maxValue.lValue = 0;
  5541. pinst->avgValue.lValue = 0;
  5542. }
  5543. return TRUE;
  5544. }
  5545. BOOL CDataCollector::CheckForReset(void)
  5546. {
  5547. BOOL bFoundReset;
  5548. BOOL bFoundNonNormal;
  5549. // PNSTRUCT *ppn;
  5550. long state;
  5551. int i, iSize;
  5552. // int j, jSize;
  5553. CThreshold* pThreshold;
  5554. // INSTSTRUCT *pinst;
  5555. // ACTUALINSTSTRUCT *pActualInst;
  5556. //
  5557. // See if we have a Threshold in the RESET state
  5558. //
  5559. bFoundReset = FALSE;
  5560. bFoundNonNormal = FALSE;
  5561. iSize = m_thresholdList.size();
  5562. for (i = 0; i < iSize ; i++)
  5563. {
  5564. MY_ASSERT(i<m_thresholdList.size());
  5565. pThreshold = m_thresholdList[i];
  5566. state = pThreshold->GetCurrState();
  5567. if (state == HM_RESET)
  5568. {
  5569. bFoundReset = TRUE;
  5570. }
  5571. if (state==HM_WARNING || state==HM_CRITICAL)
  5572. {
  5573. bFoundNonNormal = TRUE;
  5574. }
  5575. if (bFoundReset && bFoundNonNormal)
  5576. break;
  5577. }
  5578. if (bFoundReset && bFoundNonNormal)
  5579. {
  5580. // If we don't call the base method, we may get into an endless loop.
  5581. CDataCollector::EvaluateThresholds(TRUE, TRUE, FALSE, FALSE);
  5582. CDataCollector::EvaluateThresholds(TRUE, FALSE, TRUE, FALSE);
  5583. //
  5584. // Set back the RESET one(s)
  5585. //
  5586. m_lCurrState = HM_COLLECTING;
  5587. iSize = m_thresholdList.size();
  5588. for (i = 0; i < iSize ; i++)
  5589. {
  5590. MY_ASSERT(i<m_thresholdList.size());
  5591. pThreshold = m_thresholdList[i];
  5592. if (pThreshold->GetCurrState() == HM_RESET)
  5593. {
  5594. pThreshold->SetCurrState(HM_GOOD);
  5595. }
  5596. }
  5597. }
  5598. //#ifdef SAVE
  5599. //XXX???Do we want the following???
  5600. else if (bFoundReset)
  5601. {
  5602. if (m_deType!=HM_EQDE && m_bRequireReset)
  5603. {
  5604. iSize = m_thresholdList.size();
  5605. for (i = 0; i < iSize ; i++)
  5606. {
  5607. MY_ASSERT(i<m_thresholdList.size());
  5608. pThreshold = m_thresholdList[i];
  5609. if (pThreshold->GetCurrState() == HM_RESET)
  5610. {
  5611. pThreshold->ResetResetThreshold();
  5612. }
  5613. }
  5614. }
  5615. }
  5616. //#endif
  5617. return TRUE;
  5618. }
  5619. HRESULT CDataCollector::CheckForBadLoad(void)
  5620. {
  5621. HRESULT hRetRes = S_OK;
  5622. IWbemClassObject* pObj = NULL;
  5623. TCHAR szTemp[1024];
  5624. IWbemClassObject* pInstance = NULL;
  5625. if (m_bValidLoad == FALSE)
  5626. {
  5627. wcscpy(szTemp, L"MicrosoftHM_DataCollectorConfiguration.GUID=\"");
  5628. lstrcat(szTemp, m_szGUID);
  5629. lstrcat(szTemp, L"\"");
  5630. hRetRes = GetWbemObjectInst(&g_pIWbemServices, szTemp, NULL, &pObj);
  5631. if (!pObj)
  5632. {
  5633. MY_HRESASSERT(hRetRes);
  5634. return S_FALSE;
  5635. }
  5636. hRetRes = LoadInstanceFromMOF(pObj, NULL, L"", TRUE);
  5637. // Here is where we can try and send out a generic SOS if the load failed each time!!!
  5638. if (hRetRes != S_OK)
  5639. {
  5640. if (GetHMDataCollectorStatusInstance(&pInstance, TRUE) == S_OK)
  5641. {
  5642. mg_DCEventList.push_back(pInstance);
  5643. }
  5644. }
  5645. else
  5646. {
  5647. if (GetHMDataCollectorStatusInstance(&pInstance, TRUE) == S_OK)
  5648. {
  5649. mg_DCEventList.push_back(pInstance);
  5650. }
  5651. ResetState(TRUE, TRUE);
  5652. }
  5653. MY_HRESASSERT(hRetRes);
  5654. pObj->Release();
  5655. pObj = NULL;
  5656. return hRetRes;
  5657. }
  5658. return S_OK;
  5659. }