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.

3805 lines
89 KiB

  1. //***************************************************************************
  2. //
  3. // THRESHLD.CPP
  4. //
  5. // Module: HEALTHMON SERVER AGENT
  6. //
  7. // Purpose: CThreshold class to do thresholding on a CDatapoint class.
  8. // The CDatapoint class contains the WMI instance, and the CThreshold
  9. // class says what ptoperty to threshold against, and how.
  10. //
  11. // Copyright (c)1999 Microsoft Corporation, All Rights Reserved
  12. //
  13. //***************************************************************************
  14. #include <stdio.h>
  15. #include <tchar.h>
  16. #include "threshld.h"
  17. #include "datacltr.h"
  18. #include "system.h"
  19. extern CSystem* g_pSystem;
  20. extern CSystem* g_pStartupSystem;
  21. BOOL CThreshold::mg_bEnglishCompare = TRUE;
  22. //STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC
  23. void CThreshold::ThresholdTerminationCleanup(void)
  24. {
  25. if (g_pThresholdEventSink != NULL)
  26. {
  27. g_pThresholdEventSink->Release();
  28. g_pThresholdEventSink = NULL;
  29. }
  30. #ifdef SAVE
  31. if (g_pThresholdInstanceEventSink != NULL)
  32. {
  33. g_pThresholdInstanceEventSink->Release();
  34. g_pThresholdInstanceEventSink = NULL;
  35. }
  36. #endif
  37. }
  38. //STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC STATIC
  39. void CThreshold::GetLocal(void)
  40. {
  41. LCID lcID = PRIMARYLANGID(GetSystemDefaultLCID());
  42. if (lcID != 0 && lcID == 0x00000009)
  43. {
  44. mg_bEnglishCompare = TRUE;
  45. }
  46. else
  47. {
  48. mg_bEnglishCompare = FALSE;
  49. }
  50. }
  51. //////////////////////////////////////////////////////////////////////
  52. // Construction/Destruction
  53. //////////////////////////////////////////////////////////////////////
  54. CThreshold::CThreshold()
  55. {
  56. MY_OUTPUT(L"ENTER ***** CThreshold...", 4);
  57. Init();
  58. m_hmStatusType = HMSTATUS_THRESHOLD;
  59. m_bValidLoad = FALSE;
  60. MY_OUTPUT(L"EXIT ***** CThreshold...", 4);
  61. }
  62. CThreshold::~CThreshold()
  63. {
  64. MY_OUTPUT(L"ENTER ***** ~CThreshold...", 4);
  65. g_pStartupSystem->RemovePointerFromMasterList(this);
  66. Cleanup(FALSE);
  67. if (m_szGUID)
  68. {
  69. delete [] m_szGUID;
  70. m_szGUID = NULL;
  71. }
  72. m_bValidLoad = FALSE;
  73. MY_OUTPUT(L"EXIT ***** ~CThreshold...", 4);
  74. }
  75. //
  76. // Load a single Threshold
  77. //
  78. HRESULT CThreshold::LoadInstanceFromMOF(IWbemClassObject* pObj, CDataCollector *pParentDC, LPTSTR pszParentObjPath, BOOL bModifyPass/*FALSE*/)
  79. {
  80. long lTemp;
  81. HRESULT hRes = S_OK;
  82. BOOL bRetValue = TRUE;
  83. MY_OUTPUT(L"ENTER ***** CThreshold::LoadInstanceFromMOF...", 4);
  84. Cleanup(bModifyPass);
  85. m_bValidLoad = TRUE;
  86. if (bModifyPass == FALSE)
  87. {
  88. // This is the first initial read in of this
  89. // Get the GUID property
  90. // If this fails we will actually not go through with the creation of this object.
  91. if (m_szGUID)
  92. {
  93. delete [] m_szGUID;
  94. m_szGUID = NULL;
  95. }
  96. hRes = GetStrProperty(pObj, L"GUID", &m_szGUID);
  97. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  98. m_szParentObjPath = new TCHAR[wcslen(pszParentObjPath)+1];
  99. MY_ASSERT(m_szParentObjPath); if (!m_szParentObjPath) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  100. wcscpy(m_szParentObjPath, pszParentObjPath);
  101. m_pParentDC = pParentDC;
  102. hRes = g_pStartupSystem->AddPointerToMasterList(this);
  103. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  104. }
  105. hRes = GetStrProperty(pObj, L"Name", &m_szName);
  106. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  107. hRes = GetStrProperty(pObj, L"Description", &m_szDescription);
  108. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  109. hRes = GetStrProperty(pObj, L"PropertyName", &m_szPropertyName);
  110. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  111. if (!wcscmp(m_szPropertyName, L""))
  112. {
  113. delete [] m_szPropertyName;
  114. m_szPropertyName = new TCHAR[wcslen(L"CollectionErrorCode")+1];
  115. MY_ASSERT(m_szPropertyName); if (!m_szPropertyName) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  116. wcscpy(m_szPropertyName, L"CollectionErrorCode");
  117. }
  118. bRetValue = GetUint32Property(pObj, L"UseFlag", &lTemp);
  119. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  120. if (lTemp == 0)
  121. {
  122. m_bUseAverage = FALSE;
  123. m_bUseDifference = FALSE;
  124. }
  125. else if (lTemp == 1)
  126. {
  127. m_bUseAverage = TRUE;
  128. m_bUseDifference = FALSE;
  129. }
  130. else if (lTemp == 2)
  131. {
  132. m_bUseAverage = FALSE;
  133. m_bUseDifference = TRUE;
  134. }
  135. else
  136. {
  137. m_bUseAverage = FALSE;
  138. m_bUseDifference = FALSE;
  139. MY_ASSERT(FALSE);
  140. }
  141. // hRes = GetBoolProperty(pObj, L"UseSum", &m_bUseSum);
  142. // MY_HRESASSERT(hRes);
  143. m_bUseSum = FALSE;
  144. //[values {"<",">","=","!=",">=","<=","contains","!contains","always"}]
  145. hRes = GetUint32Property(pObj, L"TestCondition", &m_lTestCondition);
  146. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  147. hRes = GetStrProperty(pObj, L"CompareValue", &m_szCompareValue);
  148. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  149. m_lCompareValue = wcstol(m_szCompareValue, NULL, 10);
  150. m_ulCompareValue = wcstoul(m_szCompareValue, NULL, 10);
  151. m_fCompareValue = (float) wcstod(m_szCompareValue, NULL);
  152. m_dCompareValue = wcstod(m_szCompareValue, NULL);
  153. m_i64CompareValue = _wtoi64(m_szCompareValue);
  154. m_ui64CompareValue = 0;
  155. ReadUI64(m_szCompareValue, m_ui64CompareValue);
  156. hRes = GetUint32Property(pObj, L"ThresholdDuration", &m_lThresholdDuration);
  157. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  158. //[values {"CRITICAL","WARNING","INFO","RESET"}]
  159. hRes = GetUint32Property(pObj, L"State", &m_lViolationToState);
  160. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  161. hRes = GetStrProperty(pObj, L"CreationDate", &m_szCreationDate);
  162. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  163. hRes = GetStrProperty(pObj, L"LastUpdate", &m_szLastUpdate);
  164. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  165. hRes = GetBoolProperty(pObj, L"Enabled", &m_bEnabled);
  166. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  167. if (bModifyPass == FALSE)
  168. {
  169. if (m_bEnabled==FALSE || m_pParentDC->m_bEnabled==FALSE || m_pParentDC->m_bParentEnabled==FALSE)
  170. {
  171. if (m_pParentDC->m_bEnabled==FALSE || m_pParentDC->m_bParentEnabled==FALSE)
  172. m_bParentEnabled = FALSE;
  173. // Since our parent is disabled, we will not be able to get into
  174. // our OnAgentInterval function and send the disabled status later.
  175. SetCurrState(HM_DISABLED);
  176. FireEvent(TRUE);
  177. }
  178. }
  179. else
  180. {
  181. if (m_pParentDC->m_deType==HM_EQDE)
  182. {
  183. if (m_bEnabled==FALSE || m_pParentDC->m_bEnabled==FALSE || m_pParentDC->m_bParentEnabled==FALSE)
  184. {
  185. SetCurrState(HM_DISABLED);
  186. FireEvent(FALSE);
  187. }
  188. }
  189. }
  190. m_bValidLoad = TRUE;
  191. MY_OUTPUT(L"EXIT ***** CThreshold::LoadInstanceFromMOF...", 4);
  192. return S_OK;
  193. error:
  194. MY_ASSERT(FALSE);
  195. Cleanup(FALSE);
  196. m_bValidLoad = FALSE;
  197. return hRes;
  198. }
  199. BOOL CThreshold::SkipClean(void)
  200. {
  201. IRSSTRUCT *pirs;
  202. int i, iSize;
  203. m_lNumberChanges = 0;
  204. //
  205. // Clear things before we start
  206. //
  207. m_lPrevState = m_lCurrState;
  208. iSize = m_irsList.size();
  209. for (i = 0; i < iSize; i++)
  210. {
  211. MY_ASSERT(i<m_irsList.size());
  212. pirs = &m_irsList[i];
  213. pirs->lPrevState = m_lCurrState;
  214. pirs->lCurrState = m_lCurrState;
  215. pirs->unknownReason = 0;
  216. }
  217. return TRUE;
  218. }
  219. //
  220. // Evaluate this threshold against the property just collected
  221. //
  222. BOOL CThreshold::OnAgentInterval(ACTUALINSTLIST *actualInstList, PNSTRUCT *ppn, BOOL bRequireReset)
  223. {
  224. long state;
  225. INSTSTRUCT *pinst;
  226. IRSSTRUCT *pirs;
  227. union hm_datatypes delta;
  228. int i, iSize;
  229. //
  230. // Don't do anything if we are not loaded correctly.
  231. //
  232. if (m_bValidLoad == FALSE)
  233. return FALSE;
  234. m_lNumberChanges = 0;
  235. //
  236. // Don't do anything if we are already in the state we need to be in.
  237. // DISABLED, SCHEDULEDOUT
  238. //
  239. if (((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState==HM_DISABLED) ||
  240. (m_bParentScheduledOut==TRUE && m_lCurrState==HM_SCHEDULEDOUT))
  241. {
  242. // The DISABLED and SCHEDULEDOUT states override the UNKNWON. We may be transitioning.
  243. if (((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState!=HM_DISABLED) ||
  244. (m_bParentScheduledOut==TRUE && m_lCurrState!=HM_SCHEDULEDOUT))
  245. {
  246. // The DISABLED state overrides SCHEDULEDOUT. We may be transitioning.
  247. if (((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState!=HM_DISABLED))
  248. {
  249. }
  250. else
  251. {
  252. if (m_lPrevState != m_lCurrState)
  253. {
  254. m_lPrevState = m_lCurrState;
  255. iSize = m_irsList.size();
  256. for (i = 0; i < iSize; i++)
  257. {
  258. MY_ASSERT(i<m_irsList.size());
  259. pirs = &m_irsList[i];
  260. pirs->lPrevState = m_lCurrState;
  261. pirs->lCurrState = m_lCurrState;
  262. pirs->unknownReason = 0;
  263. }
  264. }
  265. return TRUE;
  266. }
  267. }
  268. else
  269. {
  270. if (m_lPrevState != m_lCurrState)
  271. {
  272. m_lPrevState = m_lCurrState;
  273. iSize = m_irsList.size();
  274. for (i = 0; i < iSize; i++)
  275. {
  276. MY_ASSERT(i<m_irsList.size());
  277. pirs = &m_irsList[i];
  278. pirs->lPrevState = m_lCurrState;
  279. pirs->lCurrState = m_lCurrState;
  280. pirs->unknownReason = 0;
  281. }
  282. }
  283. return TRUE;
  284. }
  285. }
  286. //
  287. // Clear things before we start
  288. //
  289. m_lPrevState = m_lCurrState;
  290. iSize = m_irsList.size();
  291. for (i = 0; i < iSize; i++)
  292. {
  293. MY_ASSERT(i<m_irsList.size());
  294. pirs = &m_irsList[i];
  295. if ((m_lCurrState==HM_CRITICAL || m_lCurrState==HM_WARNING) && m_pParentDC->m_deType!=HM_EQDE)
  296. {
  297. pirs->lPrevState = pirs->lCurrState;
  298. }
  299. else
  300. {
  301. pirs->lPrevState = m_lCurrState;
  302. pirs->lCurrState = m_lCurrState;
  303. }
  304. pirs->unknownReason = 0;
  305. }
  306. //
  307. // This is where we are transitioning into the DISABLED State.
  308. //
  309. if (m_bEnabled==FALSE || m_bParentEnabled==FALSE)
  310. {
  311. SetCurrState(HM_DISABLED);
  312. }
  313. else if (m_bParentScheduledOut==TRUE)
  314. {
  315. SetCurrState(HM_SCHEDULEDOUT);
  316. }
  317. else
  318. {
  319. if (bRequireReset && (m_lCurrState==HM_WARNING || m_lCurrState==HM_CRITICAL))
  320. return TRUE;
  321. int x = ppn->instList.size();
  322. int y = m_irsList.size();
  323. // Check for something that should not be happening
  324. if (x != y)
  325. {
  326. MY_OUTPUT(L"BAD BAD BAD - Vector sizes do not match!!!", 2);
  327. MY_ASSERT(FALSE);
  328. return TRUE;
  329. }
  330. //
  331. // For each instance, evaluate what the current state is.
  332. //
  333. MY_ASSERT(ppn->instList.size() == m_irsList.size());
  334. iSize = ppn->instList.size();
  335. for (i = 0; i < iSize ; i++)
  336. {
  337. MY_ASSERT(i<ppn->instList.size());
  338. pinst = &ppn->instList[i];
  339. MY_ASSERT(i<m_irsList.size());
  340. pirs = &m_irsList[i];
  341. // Things to do the first evaluation that happens.
  342. if (ppn->type == CIM_REAL32)
  343. {
  344. if (pirs->fPrevValue == MAX_FLOAT)
  345. {
  346. if (m_bUseAverage)
  347. pirs->fPrevValue = pinst->avgValue.fValue;
  348. else
  349. pirs->fPrevValue = pinst->currValue.fValue;
  350. }
  351. }
  352. else if (ppn->type == CIM_REAL64)
  353. {
  354. if (pirs->dPrevValue == MAX_DOUBLE)
  355. {
  356. if (m_bUseAverage)
  357. pirs->dPrevValue = pinst->avgValue.dValue;
  358. else
  359. pirs->dPrevValue = pinst->currValue.dValue;
  360. }
  361. }
  362. else if (ppn->type == CIM_SINT64)
  363. {
  364. if (pirs->i64PrevValue == MAX_I64)
  365. {
  366. if (m_bUseAverage)
  367. pirs->i64PrevValue = pinst->avgValue.i64Value;
  368. else
  369. pirs->i64PrevValue = pinst->currValue.i64Value;
  370. }
  371. }
  372. else if (ppn->type == CIM_UINT64)
  373. {
  374. if (pirs->ui64PrevValue == MAX_UI64)
  375. {
  376. if (m_bUseAverage)
  377. pirs->ui64PrevValue = pinst->avgValue.ui64Value;
  378. else
  379. pirs->ui64PrevValue = pinst->currValue.ui64Value;
  380. }
  381. }
  382. else if (ppn->type == CIM_UINT32)
  383. {
  384. if (pirs->ulPrevValue == MAX_ULONG)
  385. {
  386. if (m_bUseAverage)
  387. pirs->ulPrevValue = pinst->avgValue.ulValue;
  388. else
  389. pirs->ulPrevValue = pinst->currValue.ulValue;
  390. }
  391. }
  392. else
  393. {
  394. if (pirs->lPrevValue == MAX_LONG)
  395. {
  396. if (m_bUseAverage)
  397. pirs->lPrevValue = pinst->avgValue.lValue;
  398. else
  399. pirs->lPrevValue = pinst->currValue.lValue;
  400. }
  401. }
  402. if (ppn->type == CIM_REAL32)
  403. {
  404. pirs->fPrevPrevValue = pirs->fPrevValue;
  405. }
  406. else if (ppn->type == CIM_REAL64)
  407. {
  408. pirs->dPrevPrevValue = pirs->dPrevValue;
  409. }
  410. else if (ppn->type == CIM_SINT64)
  411. {
  412. pirs->i64PrevPrevValue = pirs->i64PrevValue;
  413. }
  414. else if (ppn->type == CIM_UINT64)
  415. {
  416. pirs->ui64PrevPrevValue = pirs->ui64PrevValue;
  417. }
  418. else if (ppn->type == CIM_UINT32)
  419. {
  420. pirs->ulPrevPrevValue = pirs->ulPrevValue;
  421. }
  422. else
  423. {
  424. pirs->lPrevPrevValue = pirs->lPrevValue;
  425. }
  426. if ((pirs->lCurrState!=HM_CRITICAL && pirs->lCurrState!=HM_WARNING && pirs->lCurrState!=HM_RESET) ||
  427. m_lViolationToState!=pirs->lCurrState)
  428. {
  429. if (pirs->lCurrState!=HM_GOOD)
  430. pirs->lCurrState = HM_GOOD;
  431. if (m_bUseDifference)
  432. {
  433. if (m_bUseAverage)
  434. {
  435. if (ppn->type == CIM_REAL32)
  436. {
  437. if (pinst->avgValue.fValue < pirs->fPrevValue)
  438. delta.fValue = pirs->fPrevValue-pinst->avgValue.fValue;
  439. else
  440. delta.fValue = pinst->avgValue.fValue-pirs->fPrevValue;
  441. }
  442. else if (ppn->type == CIM_REAL64)
  443. {
  444. if (pinst->avgValue.dValue < pirs->dPrevValue)
  445. delta.dValue = pirs->dPrevValue-pinst->avgValue.dValue;
  446. else
  447. delta.dValue = pinst->avgValue.dValue-pirs->dPrevValue;
  448. }
  449. else if (ppn->type == CIM_SINT64)
  450. {
  451. if (pinst->avgValue.i64Value < pirs->i64PrevValue)
  452. delta.i64Value = pirs->i64PrevValue-pinst->avgValue.i64Value;
  453. else
  454. delta.i64Value = pinst->avgValue.i64Value-pirs->i64PrevValue;
  455. }
  456. else if (ppn->type == CIM_UINT64)
  457. {
  458. if (pinst->avgValue.ui64Value < pirs->ui64PrevValue)
  459. delta.ui64Value = pirs->ui64PrevValue-pinst->avgValue.ui64Value;
  460. else
  461. delta.ui64Value = pinst->avgValue.ui64Value-pirs->ui64PrevValue;
  462. }
  463. else if (ppn->type == CIM_UINT32)
  464. {
  465. if (pinst->avgValue.ulValue < pirs->ulPrevValue)
  466. delta.ulValue = pirs->ulPrevValue-pinst->avgValue.ulValue;
  467. else
  468. delta.ulValue = pinst->avgValue.ulValue-pirs->ulPrevValue;
  469. }
  470. else
  471. {
  472. if (pinst->avgValue.lValue < pirs->lPrevValue)
  473. delta.lValue = pirs->lPrevValue-pinst->avgValue.lValue;
  474. else
  475. delta.lValue = pinst->avgValue.lValue-pirs->lPrevValue;
  476. }
  477. CrossTest(ppn, pirs, L"", delta, pinst);
  478. if (ppn->type == CIM_REAL32)
  479. {
  480. pirs->fPrevValue = pinst->avgValue.fValue;
  481. }
  482. else if (ppn->type == CIM_REAL64)
  483. {
  484. pirs->dPrevValue = pinst->avgValue.dValue;
  485. }
  486. else if (ppn->type == CIM_SINT64)
  487. {
  488. pirs->i64PrevValue = pinst->avgValue.i64Value;
  489. }
  490. else if (ppn->type == CIM_UINT64)
  491. {
  492. pirs->ui64PrevValue = pinst->avgValue.ui64Value;
  493. }
  494. else if (ppn->type == CIM_UINT32)
  495. {
  496. pirs->ulPrevValue = pinst->avgValue.ulValue;
  497. }
  498. else
  499. {
  500. pirs->lPrevValue = pinst->avgValue.lValue;
  501. }
  502. }
  503. else
  504. {
  505. if (ppn->type == CIM_REAL32)
  506. {
  507. if (pinst->currValue.fValue < pirs->fPrevValue)
  508. delta.fValue = pirs->fPrevValue-pinst->currValue.fValue;
  509. else
  510. delta.fValue = pinst->currValue.fValue-pirs->fPrevValue;
  511. }
  512. else if (ppn->type == CIM_REAL64)
  513. {
  514. if (pinst->currValue.dValue < pirs->dPrevValue)
  515. delta.dValue = pirs->dPrevValue-pinst->currValue.dValue;
  516. else
  517. delta.dValue = pinst->currValue.dValue-pirs->dPrevValue;
  518. }
  519. else if (ppn->type == CIM_SINT64)
  520. {
  521. if (pinst->currValue.i64Value < pirs->i64PrevValue)
  522. delta.i64Value = pirs->i64PrevValue-pinst->currValue.i64Value;
  523. else
  524. delta.i64Value = pinst->currValue.i64Value-pirs->i64PrevValue;
  525. }
  526. else if (ppn->type == CIM_UINT64)
  527. {
  528. if (pinst->currValue.ui64Value < pirs->ui64PrevValue)
  529. delta.ui64Value = pirs->ui64PrevValue-pinst->currValue.ui64Value;
  530. else
  531. delta.ui64Value = pinst->currValue.ui64Value-pirs->ui64PrevValue;
  532. }
  533. else if (ppn->type == CIM_UINT32)
  534. {
  535. if (pinst->currValue.ulValue < pirs->ulPrevValue)
  536. delta.ulValue = pirs->ulPrevValue-pinst->currValue.ulValue;
  537. else
  538. delta.ulValue = pinst->currValue.ulValue-pirs->ulPrevValue;
  539. }
  540. else
  541. {
  542. if (pinst->currValue.lValue < pirs->lPrevValue)
  543. delta.lValue = pirs->lPrevValue-pinst->currValue.lValue;
  544. else
  545. delta.lValue = pinst->currValue.lValue-pirs->lPrevValue;
  546. }
  547. CrossTest(ppn, pirs, L"", delta, pinst);
  548. if (ppn->type == CIM_REAL32)
  549. {
  550. pirs->fPrevValue = pinst->currValue.fValue;
  551. }
  552. else if (ppn->type == CIM_REAL64)
  553. {
  554. pirs->dPrevValue = pinst->currValue.dValue;
  555. }
  556. else if (ppn->type == CIM_SINT64)
  557. {
  558. pirs->i64PrevValue = pinst->currValue.i64Value;
  559. }
  560. else if (ppn->type == CIM_UINT64)
  561. {
  562. pirs->ui64PrevValue = pinst->currValue.ui64Value;
  563. }
  564. else if (ppn->type == CIM_UINT32)
  565. {
  566. pirs->ulPrevValue = pinst->currValue.ulValue;
  567. }
  568. else
  569. {
  570. pirs->lPrevValue = pinst->currValue.lValue;
  571. }
  572. }
  573. }
  574. else
  575. {
  576. if (m_bUseAverage)
  577. {
  578. CrossTest(ppn, pirs, L"", pinst->avgValue, pinst);
  579. if (ppn->type == CIM_REAL32)
  580. {
  581. pirs->fPrevValue = pinst->avgValue.fValue;
  582. }
  583. else if (ppn->type == CIM_REAL64)
  584. {
  585. pirs->dPrevValue = pinst->avgValue.dValue;
  586. }
  587. else if (ppn->type == CIM_SINT64)
  588. {
  589. pirs->i64PrevValue = pinst->avgValue.i64Value;
  590. }
  591. else if (ppn->type == CIM_UINT64)
  592. {
  593. pirs->ui64PrevValue = pinst->avgValue.ui64Value;
  594. }
  595. else if (ppn->type == CIM_UINT32)
  596. {
  597. pirs->ulPrevValue = pinst->avgValue.ulValue;
  598. }
  599. else
  600. {
  601. pirs->lPrevValue = pinst->avgValue.lValue;
  602. }
  603. }
  604. else
  605. {
  606. CrossTest(ppn, pirs, pinst->szCurrValue, pinst->currValue, pinst);
  607. }
  608. }
  609. }
  610. else
  611. {
  612. if (m_bUseDifference)
  613. {
  614. if (m_bUseAverage)
  615. {
  616. if (ppn->type == CIM_REAL32)
  617. {
  618. if (pinst->avgValue.fValue < pirs->fPrevValue)
  619. delta.fValue = pirs->fPrevValue-pinst->avgValue.fValue;
  620. else
  621. delta.fValue = pinst->avgValue.fValue-pirs->fPrevValue;
  622. }
  623. else if (ppn->type == CIM_REAL64)
  624. {
  625. if (pinst->avgValue.dValue < pirs->dPrevValue)
  626. delta.dValue = pirs->dPrevValue-pinst->avgValue.dValue;
  627. else
  628. delta.dValue = pinst->avgValue.dValue-pirs->dPrevValue;
  629. }
  630. else if (ppn->type == CIM_SINT64)
  631. {
  632. if (pinst->avgValue.i64Value < pirs->i64PrevValue)
  633. delta.i64Value = pirs->i64PrevValue-pinst->avgValue.i64Value;
  634. else
  635. delta.i64Value = pinst->avgValue.i64Value-pirs->i64PrevValue;
  636. }
  637. else if (ppn->type == CIM_UINT64)
  638. {
  639. if (pinst->avgValue.ui64Value < pirs->ui64PrevValue)
  640. delta.ui64Value = pirs->ui64PrevValue-pinst->avgValue.ui64Value;
  641. else
  642. delta.ui64Value = pinst->avgValue.ui64Value-pirs->ui64PrevValue;
  643. }
  644. else if (ppn->type == CIM_UINT32)
  645. {
  646. if (pinst->avgValue.ulValue < pirs->ulPrevValue)
  647. delta.ulValue = pirs->ulPrevValue-pinst->avgValue.ulValue;
  648. else
  649. delta.ulValue = pinst->avgValue.ulValue-pirs->ulPrevValue;
  650. }
  651. else
  652. {
  653. if (pinst->avgValue.lValue < pirs->lPrevValue)
  654. delta.lValue = pirs->lPrevValue-pinst->avgValue.lValue;
  655. else
  656. delta.lValue = pinst->avgValue.lValue-pirs->lPrevValue;
  657. }
  658. RearmTest(ppn, pirs, L"", delta, pinst);
  659. if (ppn->type == CIM_REAL32)
  660. {
  661. pirs->fPrevValue = pinst->avgValue.fValue;
  662. }
  663. else if (ppn->type == CIM_REAL64)
  664. {
  665. pirs->dPrevValue = pinst->avgValue.dValue;
  666. }
  667. else if (ppn->type == CIM_SINT64)
  668. {
  669. pirs->i64PrevValue = pinst->avgValue.i64Value;
  670. }
  671. else if (ppn->type == CIM_UINT64)
  672. {
  673. pirs->ui64PrevValue = pinst->avgValue.ui64Value;
  674. }
  675. else if (ppn->type == CIM_UINT32)
  676. {
  677. pirs->ulPrevValue = pinst->avgValue.ulValue;
  678. }
  679. else
  680. {
  681. pirs->lPrevValue = pinst->avgValue.lValue;
  682. }
  683. }
  684. else
  685. {
  686. if (ppn->type == CIM_REAL32)
  687. {
  688. if (pinst->currValue.fValue < pirs->fPrevValue)
  689. delta.fValue = pirs->fPrevValue-pinst->currValue.fValue;
  690. else
  691. delta.fValue = pinst->currValue.fValue-pirs->fPrevValue;
  692. }
  693. else if (ppn->type == CIM_REAL64)
  694. {
  695. if (pinst->currValue.dValue < pirs->dPrevValue)
  696. delta.dValue = pirs->dPrevValue-pinst->currValue.dValue;
  697. else
  698. delta.dValue = pinst->currValue.dValue-pirs->dPrevValue;
  699. }
  700. else if (ppn->type == CIM_SINT64)
  701. {
  702. if (pinst->currValue.i64Value < pirs->i64PrevValue)
  703. delta.i64Value = pirs->i64PrevValue-pinst->currValue.i64Value;
  704. else
  705. delta.i64Value = pinst->currValue.i64Value-pirs->i64PrevValue;
  706. }
  707. else if (ppn->type == CIM_UINT64)
  708. {
  709. if (pinst->currValue.ui64Value < pirs->ui64PrevValue)
  710. delta.ui64Value = pirs->ui64PrevValue-pinst->currValue.ui64Value;
  711. else
  712. delta.ui64Value = pinst->currValue.ui64Value-pirs->ui64PrevValue;
  713. }
  714. else if (ppn->type == CIM_UINT32)
  715. {
  716. if (pinst->currValue.ulValue < pirs->ulPrevValue)
  717. delta.ulValue = pirs->ulPrevValue-pinst->currValue.ulValue;
  718. else
  719. delta.ulValue = pinst->currValue.ulValue-pirs->ulPrevValue;
  720. }
  721. else
  722. {
  723. if (pinst->currValue.lValue < pirs->lPrevValue)
  724. delta.lValue = pirs->lPrevValue-pinst->currValue.lValue;
  725. else
  726. delta.lValue = pinst->currValue.lValue-pirs->lPrevValue;
  727. }
  728. RearmTest(ppn, pirs, L"", delta, pinst);
  729. if (ppn->type == CIM_REAL32)
  730. {
  731. pirs->fPrevValue = pinst->currValue.fValue;
  732. }
  733. else if (ppn->type == CIM_REAL64)
  734. {
  735. pirs->dPrevValue = pinst->currValue.dValue;
  736. }
  737. else if (ppn->type == CIM_SINT64)
  738. {
  739. pirs->i64PrevValue = pinst->currValue.i64Value;
  740. }
  741. else if (ppn->type == CIM_UINT64)
  742. {
  743. pirs->ui64PrevValue = pinst->currValue.ui64Value;
  744. }
  745. else if (ppn->type == CIM_UINT32)
  746. {
  747. pirs->ulPrevValue = pinst->currValue.ulValue;
  748. }
  749. else
  750. {
  751. pirs->lPrevValue = pinst->currValue.lValue;
  752. }
  753. }
  754. }
  755. else
  756. {
  757. if (m_bUseAverage)
  758. {
  759. RearmTest(ppn, pirs, L"", pinst->avgValue, pinst);
  760. if (ppn->type == CIM_REAL32)
  761. {
  762. pirs->fPrevValue = pinst->avgValue.fValue;
  763. }
  764. else if (ppn->type == CIM_REAL64)
  765. {
  766. pirs->dPrevValue = pinst->avgValue.dValue;
  767. }
  768. else if (ppn->type == CIM_SINT64)
  769. {
  770. pirs->i64PrevValue = pinst->avgValue.i64Value;
  771. }
  772. else if (ppn->type == CIM_UINT64)
  773. {
  774. pirs->ui64PrevValue = pinst->avgValue.ui64Value;
  775. }
  776. else if (ppn->type == CIM_UINT32)
  777. {
  778. pirs->ulPrevValue = pinst->avgValue.ulValue;
  779. }
  780. else
  781. {
  782. pirs->lPrevValue = pinst->avgValue.lValue;
  783. }
  784. }
  785. else
  786. {
  787. RearmTest(ppn, pirs, pinst->szCurrValue, pinst->currValue, pinst);
  788. }
  789. }
  790. }
  791. }
  792. //
  793. // Set the state to the worst of all instances
  794. //
  795. m_lNumberNormals = 0;
  796. m_lNumberWarnings = 0;
  797. m_lNumberCriticals = 0;
  798. m_lNumberChanges = 0;
  799. m_lCurrState = -1;
  800. iSize = m_irsList.size();
  801. for (i = 0; i < iSize; i++)
  802. {
  803. MY_ASSERT(i<m_irsList.size());
  804. pirs = &m_irsList[i];
  805. state = pirs->lCurrState;
  806. if (state > m_lCurrState)
  807. {
  808. m_lCurrState = state;
  809. }
  810. if (state == HM_GOOD)
  811. {
  812. m_lNumberNormals++;
  813. }
  814. if (state == HM_WARNING)
  815. {
  816. m_lNumberWarnings++;
  817. }
  818. if (state == HM_CRITICAL)
  819. {
  820. m_lNumberCriticals++;
  821. }
  822. if (pirs->lPrevState != pirs->lCurrState)
  823. {
  824. //MY_OUTPUT2(L"CHANGE state=%d", state, 4);
  825. m_lNumberChanges++;
  826. }
  827. }
  828. // Maybe we don't have anything underneith
  829. if (m_lCurrState == -1)
  830. {
  831. m_lCurrState = HM_GOOD;
  832. if (m_lPrevState != m_lCurrState)
  833. {
  834. m_lNumberChanges = 1;
  835. }
  836. }
  837. }
  838. //
  839. // the INFO state is not a state that we can transition to, but we just send out the message.
  840. //
  841. if (m_lCurrState == HM_INFO)
  842. {
  843. m_lCurrState = HM_GOOD;
  844. }
  845. else
  846. {
  847. FireEvent(FALSE);
  848. }
  849. return TRUE;
  850. }
  851. //
  852. // If there has been a change in the state then send an event
  853. //
  854. BOOL CThreshold::FireEvent(BOOL bForce)
  855. {
  856. BOOL bRetValue = TRUE;
  857. IWbemClassObject* pInstance = NULL;
  858. HRESULT hRes;
  859. IRSSTRUCT *pirs;
  860. int i, iSize;
  861. MY_OUTPUT(L"ENTER ***** CThreshold::FireEvent...", 2);
  862. // A quick test to see if anything has really changed!
  863. // Proceed if there have been changes
  864. if (m_lViolationToState==HM_RESET && bForce==FALSE && m_lNumberChanges!=0)
  865. {
  866. if (m_lPrevState==HM_DISABLED || m_lPrevState==HM_SCHEDULEDOUT ||
  867. m_lCurrState==HM_DISABLED || m_lCurrState==HM_SCHEDULEDOUT)
  868. {
  869. }
  870. else
  871. {
  872. m_lPrevState = m_lCurrState;
  873. iSize = m_irsList.size();
  874. for (i = 0; i < iSize; i++)
  875. {
  876. MY_ASSERT(i<m_irsList.size());
  877. pirs = &m_irsList[i];
  878. pirs->lPrevState = m_lCurrState;
  879. pirs->lCurrState = m_lCurrState;
  880. pirs->unknownReason = 0;
  881. }
  882. m_lNumberChanges = 0;
  883. return TRUE;
  884. }
  885. }
  886. else
  887. {
  888. if (bForce || (m_lNumberChanges!=0 && m_lPrevState!=m_lCurrState))
  889. {
  890. }
  891. else
  892. {
  893. return FALSE;
  894. }
  895. }
  896. // Don't send if no-one is listening!
  897. if (g_pThresholdEventSink == NULL)
  898. {
  899. return bRetValue;
  900. }
  901. MY_OUTPUT2(L"EVENT: Threshold State Change=%d", m_lCurrState, 4);
  902. // Update time if there has been a change
  903. wcscpy(m_szDTTime, m_szDTCurrTime);
  904. wcscpy(m_szTime, m_szCurrTime);
  905. hRes = GetHMThresholdStatusInstance(&pInstance, TRUE);
  906. if (FAILED(hRes))
  907. {
  908. MY_HRESASSERT(hRes);
  909. MY_OUTPUT(L"failed to get instance!", 1);
  910. return FALSE;
  911. }
  912. else
  913. {
  914. //
  915. // Place Extrinstic event in vector for sending at end of interval.
  916. // All get sent at once.
  917. //
  918. mg_TEventList.push_back(pInstance);
  919. }
  920. MY_OUTPUT(L"EXIT ***** CThreshold::FireEvent...", 2);
  921. return bRetValue;
  922. }
  923. BOOL CThreshold::CrossTest(PNSTRUCT *ppn, IRSSTRUCT *pirs, LPTSTR szTestValue, union hm_datatypes testValue, INSTSTRUCT *pinst)
  924. {
  925. HRESULT hRes = S_OK;
  926. TCHAR szTemp[128] = {0};
  927. BOOL bViolated = FALSE;
  928. int i;
  929. BOOL bAllDigits;
  930. LPTSTR pszCompareValueUpper = NULL;
  931. LPTSTR pszTestValueUpper = NULL;
  932. int rc = 0;
  933. char buffer[50];
  934. MY_OUTPUT(L"ENTER ***** CrossTest...", 1);
  935. if (pinst->bNull)
  936. {
  937. // pirs->lCurrState = HM_CRITICAL;
  938. // pirs->unknownReason = HMRES_NULLVALUE;
  939. pirs->lCrossCountTry = 0;
  940. return TRUE;
  941. }
  942. if (m_lTestCondition == HM_LT)
  943. {
  944. if (ppn->type == CIM_STRING)
  945. {
  946. bAllDigits = FALSE;
  947. i = 0;
  948. while (szTestValue[i])
  949. {
  950. if (i==0)
  951. bAllDigits = TRUE;
  952. if (!iswdigit(szTestValue[i]))
  953. {
  954. bAllDigits = FALSE;
  955. break;
  956. }
  957. i++;
  958. }
  959. if (bAllDigits == FALSE)
  960. {
  961. if (mg_bEnglishCompare == TRUE)
  962. {
  963. if (_wcsicmp(szTestValue, m_szCompareValue)<0)
  964. {
  965. bViolated = TRUE;
  966. }
  967. }
  968. else
  969. {
  970. if (_wcsicoll(szTestValue, m_szCompareValue)<0)
  971. {
  972. bViolated = TRUE;
  973. }
  974. }
  975. }
  976. else
  977. {
  978. __int64 i64Value = _wtoi64(szTestValue);
  979. bViolated = (i64Value < m_i64CompareValue);
  980. }
  981. }
  982. else if (ppn->type == CIM_DATETIME)
  983. {
  984. if (_wcsicmp(szTestValue, m_szCompareValue)<0)
  985. {
  986. bViolated = TRUE;
  987. }
  988. }
  989. else if (ppn->type == CIM_REAL32)
  990. {
  991. bViolated = (testValue.fValue < m_fCompareValue);
  992. }
  993. else if (ppn->type == CIM_REAL64)
  994. {
  995. bViolated = (testValue.dValue < m_dCompareValue);
  996. }
  997. else if (ppn->type == CIM_SINT64)
  998. {
  999. bViolated = (testValue.i64Value < m_i64CompareValue);
  1000. }
  1001. else if (ppn->type == CIM_UINT64)
  1002. {
  1003. bViolated = (testValue.ui64Value < m_ui64CompareValue);
  1004. }
  1005. else if (ppn->type == CIM_UINT32)
  1006. {
  1007. bViolated = (testValue.ulValue < m_ulCompareValue);
  1008. }
  1009. else
  1010. {
  1011. // Must be an integer type
  1012. bViolated = (testValue.lValue < m_lCompareValue);
  1013. }
  1014. }
  1015. else if (m_lTestCondition == HM_GT)
  1016. {
  1017. if (ppn->type == CIM_STRING)
  1018. {
  1019. bAllDigits = FALSE;
  1020. i = 0;
  1021. while (szTestValue[i])
  1022. {
  1023. if (i==0)
  1024. bAllDigits = TRUE;
  1025. if (!iswdigit(szTestValue[i]))
  1026. {
  1027. bAllDigits = FALSE;
  1028. break;
  1029. }
  1030. i++;
  1031. }
  1032. if (bAllDigits == FALSE)
  1033. {
  1034. if (mg_bEnglishCompare == TRUE)
  1035. {
  1036. if (_wcsicmp(szTestValue, m_szCompareValue)>0)
  1037. {
  1038. bViolated = TRUE;
  1039. }
  1040. }
  1041. else
  1042. {
  1043. if (_wcsicoll(szTestValue, m_szCompareValue)>0)
  1044. {
  1045. bViolated = TRUE;
  1046. }
  1047. }
  1048. }
  1049. else
  1050. {
  1051. __int64 i64Value = _wtoi64(szTestValue);
  1052. bViolated = (i64Value > m_i64CompareValue);
  1053. }
  1054. }
  1055. else if (ppn->type == CIM_DATETIME)
  1056. {
  1057. if (_wcsicmp(szTestValue, m_szCompareValue)>0)
  1058. {
  1059. bViolated = TRUE;
  1060. }
  1061. }
  1062. else if (ppn->type == CIM_REAL32)
  1063. {
  1064. bViolated = (testValue.fValue > m_fCompareValue);
  1065. }
  1066. else if (ppn->type == CIM_REAL64)
  1067. {
  1068. bViolated = (testValue.dValue > m_dCompareValue);
  1069. }
  1070. else if (ppn->type == CIM_SINT64)
  1071. {
  1072. bViolated = (testValue.i64Value > m_i64CompareValue);
  1073. }
  1074. else if (ppn->type == CIM_UINT64)
  1075. {
  1076. bViolated = (testValue.ui64Value > m_ui64CompareValue);
  1077. }
  1078. else if (ppn->type == CIM_UINT32)
  1079. {
  1080. bViolated = (testValue.ulValue > m_ulCompareValue);
  1081. }
  1082. else
  1083. {
  1084. // Must be an integer type
  1085. bViolated = (testValue.lValue > m_lCompareValue);
  1086. }
  1087. }
  1088. else if (m_lTestCondition == HM_EQ)
  1089. {
  1090. if (ppn->type == CIM_STRING)
  1091. {
  1092. if (mg_bEnglishCompare == TRUE)
  1093. {
  1094. if (_wcsicmp(szTestValue, m_szCompareValue)==0)
  1095. {
  1096. bViolated = TRUE;
  1097. }
  1098. }
  1099. else
  1100. {
  1101. if (_wcsicoll(szTestValue, m_szCompareValue)==0)
  1102. {
  1103. bViolated = TRUE;
  1104. }
  1105. }
  1106. }
  1107. else if (ppn->type == CIM_DATETIME)
  1108. {
  1109. if (_wcsicmp(szTestValue, m_szCompareValue)==0)
  1110. {
  1111. bViolated = TRUE;
  1112. }
  1113. }
  1114. else if (ppn->type == CIM_REAL32)
  1115. {
  1116. bViolated = (testValue.fValue == m_fCompareValue);
  1117. }
  1118. else if (ppn->type == CIM_REAL64)
  1119. {
  1120. bViolated = (testValue.dValue == m_dCompareValue);
  1121. }
  1122. else if (ppn->type == CIM_SINT64)
  1123. {
  1124. bViolated = (testValue.i64Value == m_i64CompareValue);
  1125. }
  1126. else if (ppn->type == CIM_UINT64)
  1127. {
  1128. bViolated = (testValue.ui64Value == m_ui64CompareValue);
  1129. }
  1130. else if (ppn->type == CIM_UINT32)
  1131. {
  1132. bViolated = (testValue.ulValue == m_ulCompareValue);
  1133. }
  1134. else
  1135. {
  1136. // Must be an integer type
  1137. bViolated = (testValue.lValue == m_lCompareValue);
  1138. }
  1139. }
  1140. else if (m_lTestCondition == HM_NE)
  1141. {
  1142. if (ppn->type == CIM_STRING)
  1143. {
  1144. if (mg_bEnglishCompare == TRUE)
  1145. {
  1146. if (_wcsicmp(szTestValue, m_szCompareValue)!=0)
  1147. {
  1148. bViolated = TRUE;
  1149. }
  1150. }
  1151. else
  1152. {
  1153. if (_wcsicoll(szTestValue, m_szCompareValue)!=0)
  1154. {
  1155. bViolated = TRUE;
  1156. }
  1157. }
  1158. }
  1159. else if (ppn->type == CIM_DATETIME)
  1160. {
  1161. if (_wcsicmp(szTestValue, m_szCompareValue)!=0)
  1162. {
  1163. bViolated = TRUE;
  1164. }
  1165. }
  1166. else if (ppn->type == CIM_REAL32)
  1167. {
  1168. bViolated = (testValue.fValue != m_fCompareValue);
  1169. }
  1170. else if (ppn->type == CIM_REAL64)
  1171. {
  1172. bViolated = (testValue.dValue != m_dCompareValue);
  1173. }
  1174. else if (ppn->type == CIM_SINT64)
  1175. {
  1176. bViolated = (testValue.i64Value != m_i64CompareValue);
  1177. }
  1178. else if (ppn->type == CIM_UINT64)
  1179. {
  1180. bViolated = (testValue.ui64Value != m_ui64CompareValue);
  1181. }
  1182. else if (ppn->type == CIM_UINT32)
  1183. {
  1184. bViolated = (testValue.ulValue != m_ulCompareValue);
  1185. }
  1186. else
  1187. {
  1188. // Must be an integer type
  1189. bViolated = (testValue.lValue != m_lCompareValue);
  1190. }
  1191. }
  1192. else if (m_lTestCondition == HM_GE)
  1193. {
  1194. if (ppn->type == CIM_STRING)
  1195. {
  1196. bAllDigits = FALSE;
  1197. i = 0;
  1198. while (szTestValue[i])
  1199. {
  1200. if (i==0)
  1201. bAllDigits = TRUE;
  1202. if (!iswdigit(szTestValue[i]))
  1203. {
  1204. bAllDigits = FALSE;
  1205. break;
  1206. }
  1207. i++;
  1208. }
  1209. if (bAllDigits == FALSE)
  1210. {
  1211. if (mg_bEnglishCompare == TRUE)
  1212. {
  1213. if (_wcsicmp(szTestValue, m_szCompareValue)>=0)
  1214. {
  1215. bViolated = TRUE;
  1216. }
  1217. }
  1218. else
  1219. {
  1220. if (_wcsicoll(szTestValue, m_szCompareValue)>=0)
  1221. {
  1222. bViolated = TRUE;
  1223. }
  1224. }
  1225. }
  1226. else
  1227. {
  1228. __int64 i64Value = _wtoi64(szTestValue);
  1229. bViolated = (i64Value >= m_i64CompareValue);
  1230. }
  1231. }
  1232. else if (ppn->type == CIM_DATETIME)
  1233. {
  1234. if (_wcsicmp(szTestValue, m_szCompareValue)>=0)
  1235. {
  1236. bViolated = TRUE;
  1237. }
  1238. }
  1239. else if (ppn->type == CIM_REAL32)
  1240. {
  1241. bViolated = (testValue.fValue >= m_fCompareValue);
  1242. }
  1243. else if (ppn->type == CIM_REAL64)
  1244. {
  1245. bViolated = (testValue.dValue >= m_dCompareValue);
  1246. }
  1247. else if (ppn->type == CIM_SINT64)
  1248. {
  1249. bViolated = (testValue.i64Value >= m_i64CompareValue);
  1250. }
  1251. else if (ppn->type == CIM_UINT64)
  1252. {
  1253. bViolated = (testValue.ui64Value >= m_ui64CompareValue);
  1254. }
  1255. else if (ppn->type == CIM_UINT32)
  1256. {
  1257. // Must be an integer type
  1258. bViolated = (testValue.ulValue >= m_ulCompareValue);
  1259. }
  1260. else
  1261. {
  1262. // Must be an integer type
  1263. bViolated = (testValue.lValue >= m_lCompareValue);
  1264. }
  1265. }
  1266. else if (m_lTestCondition == HM_LE)
  1267. {
  1268. if (ppn->type == CIM_STRING)
  1269. {
  1270. bAllDigits = FALSE;
  1271. i = 0;
  1272. while (szTestValue[i])
  1273. {
  1274. if (i==0)
  1275. bAllDigits = TRUE;
  1276. if (!iswdigit(szTestValue[i]))
  1277. {
  1278. bAllDigits = FALSE;
  1279. break;
  1280. }
  1281. i++;
  1282. }
  1283. if (bAllDigits == FALSE)
  1284. {
  1285. if (mg_bEnglishCompare == TRUE)
  1286. {
  1287. if (_wcsicmp(szTestValue, m_szCompareValue)<=0)
  1288. {
  1289. bViolated = TRUE;
  1290. }
  1291. }
  1292. else
  1293. {
  1294. if (_wcsicoll(szTestValue, m_szCompareValue)<=0)
  1295. {
  1296. bViolated = TRUE;
  1297. }
  1298. }
  1299. }
  1300. else
  1301. {
  1302. __int64 i64Value = _wtoi64(szTestValue);
  1303. bViolated = (i64Value <= m_i64CompareValue);
  1304. }
  1305. }
  1306. else if (ppn->type == CIM_DATETIME)
  1307. {
  1308. if (_wcsicmp(szTestValue, m_szCompareValue)<=0)
  1309. {
  1310. bViolated = TRUE;
  1311. }
  1312. }
  1313. else if (ppn->type == CIM_REAL32)
  1314. {
  1315. bViolated = (testValue.fValue <= m_fCompareValue);
  1316. }
  1317. else if (ppn->type == CIM_REAL64)
  1318. {
  1319. bViolated = (testValue.dValue <= m_dCompareValue);
  1320. }
  1321. else if (ppn->type == CIM_SINT64)
  1322. {
  1323. bViolated = (testValue.i64Value <= m_i64CompareValue);
  1324. }
  1325. else if (ppn->type == CIM_UINT64)
  1326. {
  1327. bViolated = (testValue.ui64Value <= m_ui64CompareValue);
  1328. }
  1329. else if (ppn->type == CIM_UINT32)
  1330. {
  1331. bViolated = (testValue.ulValue <= m_ulCompareValue);
  1332. }
  1333. else
  1334. {
  1335. // Must be an integer type
  1336. bViolated = (testValue.lValue <= m_lCompareValue);
  1337. }
  1338. }
  1339. else if (m_lTestCondition == HM_CONTAINS)
  1340. {
  1341. if (ppn->type == CIM_STRING)
  1342. {
  1343. pszCompareValueUpper = _wcsdup(m_szCompareValue);
  1344. MY_ASSERT(pszCompareValueUpper); if (!pszCompareValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1345. _wcsupr(pszCompareValueUpper);
  1346. pszTestValueUpper = _wcsdup(szTestValue);
  1347. MY_ASSERT(pszTestValueUpper); if (!pszTestValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1348. _wcsupr(pszTestValueUpper);
  1349. if (wcsstr(pszTestValueUpper, pszCompareValueUpper))
  1350. {
  1351. bViolated = TRUE;
  1352. }
  1353. free(pszCompareValueUpper);
  1354. pszCompareValueUpper = NULL;
  1355. free(pszTestValueUpper);
  1356. pszTestValueUpper = NULL;
  1357. }
  1358. else if (ppn->type == CIM_DATETIME)
  1359. {
  1360. if (wcsstr(szTestValue, m_szCompareValue))
  1361. {
  1362. bViolated = TRUE;
  1363. }
  1364. }
  1365. else if (ppn->type == CIM_REAL32)
  1366. {
  1367. _gcvt((double)testValue.fValue, 7, buffer);
  1368. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  1369. szTemp[rc] = NULL;
  1370. if (wcsstr(szTemp, m_szCompareValue))
  1371. {
  1372. bViolated = TRUE;
  1373. }
  1374. }
  1375. else if (ppn->type == CIM_REAL64)
  1376. {
  1377. _gcvt(testValue.dValue, 7, buffer);
  1378. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  1379. szTemp[rc] = NULL;
  1380. if (wcsstr(szTemp, m_szCompareValue))
  1381. {
  1382. bViolated = TRUE;
  1383. }
  1384. }
  1385. else if (ppn->type == CIM_SINT64)
  1386. {
  1387. _i64tow(testValue.i64Value, szTemp, 10 );
  1388. if (wcsstr(szTemp, m_szCompareValue))
  1389. {
  1390. bViolated = TRUE;
  1391. }
  1392. }
  1393. else if (ppn->type == CIM_UINT64)
  1394. {
  1395. _ui64tow((int)testValue.ui64Value, szTemp, 10);
  1396. if (wcsstr(szTemp, m_szCompareValue))
  1397. {
  1398. bViolated = TRUE;
  1399. }
  1400. }
  1401. else if (ppn->type == CIM_UINT32)
  1402. {
  1403. _ultow(testValue.ulValue, szTemp, 10);
  1404. if (wcsstr(szTemp, m_szCompareValue))
  1405. {
  1406. bViolated = TRUE;
  1407. }
  1408. }
  1409. else
  1410. {
  1411. // Must be an integer type
  1412. _ltow(testValue.lValue, szTemp, 10);
  1413. if (wcsstr(szTemp, m_szCompareValue))
  1414. {
  1415. bViolated = TRUE;
  1416. }
  1417. }
  1418. }
  1419. else if (m_lTestCondition == HM_NOTCONTAINS)
  1420. {
  1421. if (ppn->type == CIM_STRING)
  1422. {
  1423. pszCompareValueUpper = _wcsdup(m_szCompareValue);
  1424. MY_ASSERT(pszCompareValueUpper); if (!pszCompareValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1425. _wcsupr(pszCompareValueUpper);
  1426. pszTestValueUpper = _wcsdup(szTestValue);
  1427. MY_ASSERT(pszTestValueUpper); if (!pszTestValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1428. _wcsupr(pszTestValueUpper);
  1429. if (!wcsstr(pszTestValueUpper, pszCompareValueUpper))
  1430. {
  1431. bViolated = TRUE;
  1432. }
  1433. free(pszCompareValueUpper);
  1434. pszCompareValueUpper = NULL;
  1435. free(pszTestValueUpper);
  1436. pszTestValueUpper = NULL;
  1437. }
  1438. else if (ppn->type == CIM_DATETIME)
  1439. {
  1440. if (!wcsstr(szTestValue, m_szCompareValue))
  1441. {
  1442. bViolated = TRUE;
  1443. }
  1444. }
  1445. else if (ppn->type == CIM_REAL32)
  1446. {
  1447. _gcvt((double)testValue.fValue, 7, buffer);
  1448. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  1449. szTemp[rc] = NULL;
  1450. if (!wcsstr(szTemp, m_szCompareValue))
  1451. {
  1452. bViolated = TRUE;
  1453. }
  1454. }
  1455. else if (ppn->type == CIM_REAL64)
  1456. {
  1457. _gcvt(testValue.dValue, 7, buffer);
  1458. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  1459. szTemp[rc] = NULL;
  1460. if (!wcsstr(szTemp, m_szCompareValue))
  1461. {
  1462. bViolated = TRUE;
  1463. }
  1464. }
  1465. else if (ppn->type == CIM_SINT64)
  1466. {
  1467. _i64tow(testValue.i64Value, szTemp, 10 );
  1468. if (!wcsstr(szTemp, m_szCompareValue))
  1469. {
  1470. bViolated = TRUE;
  1471. }
  1472. }
  1473. else if (ppn->type == CIM_UINT64)
  1474. {
  1475. _ui64tow((int)testValue.ui64Value, szTemp, 10);
  1476. if (!wcsstr(szTemp, m_szCompareValue))
  1477. {
  1478. bViolated = TRUE;
  1479. }
  1480. }
  1481. else if (ppn->type == CIM_UINT32)
  1482. {
  1483. _ultow(testValue.ulValue, szTemp, 10);
  1484. if (!wcsstr(szTemp, m_szCompareValue))
  1485. {
  1486. bViolated = TRUE;
  1487. }
  1488. }
  1489. else
  1490. {
  1491. // Must be an integer type
  1492. _ltow(testValue.lValue, szTemp, 10);
  1493. if (!wcsstr(szTemp, m_szCompareValue))
  1494. {
  1495. bViolated = TRUE;
  1496. }
  1497. }
  1498. }
  1499. else if (m_lTestCondition == HM_ALWAYS)
  1500. {
  1501. bViolated = TRUE;
  1502. }
  1503. else
  1504. {
  1505. MY_ASSERT(FALSE);
  1506. }
  1507. //
  1508. // Also see if the duration test has been met
  1509. //
  1510. if (bViolated)
  1511. {
  1512. if (m_lThresholdDuration==0 || (m_lThresholdDuration <= pirs->lCrossCountTry))
  1513. {
  1514. pirs->lCurrState = m_lViolationToState;
  1515. }
  1516. pirs->lCrossCountTry++;
  1517. }
  1518. else
  1519. {
  1520. pirs->lCrossCountTry = 0;
  1521. }
  1522. MY_OUTPUT(L"EXIT ***** CrossTest...", 1);
  1523. return TRUE;
  1524. error:
  1525. MY_ASSERT(FALSE);
  1526. if (pszCompareValueUpper)
  1527. free(pszCompareValueUpper);
  1528. if (pszTestValueUpper)
  1529. free(pszTestValueUpper);
  1530. Cleanup(FALSE);
  1531. m_bValidLoad = FALSE;
  1532. return FALSE;
  1533. }
  1534. BOOL CThreshold::RearmTest(PNSTRUCT *ppn, IRSSTRUCT *pirs, LPTSTR szTestValue, union hm_datatypes testValue, INSTSTRUCT *pinst)
  1535. {
  1536. HRESULT hRes = S_OK;
  1537. TCHAR szTemp[128] = {0};
  1538. BOOL bReset = FALSE;
  1539. int i;
  1540. BOOL bAllDigits;
  1541. LPTSTR pszCompareValueUpper = NULL;
  1542. LPTSTR pszTestValueUpper = NULL;
  1543. int rc = 0;
  1544. char buffer[50];
  1545. MY_OUTPUT(L"ENTER ***** RearmTest...", 1);
  1546. //XXXIf too much of this code look duplicated from the Crosstest finction, try to
  1547. //combine the two, and pass in what need!!!
  1548. if (pinst->bNull)
  1549. {
  1550. // pirs->lCurrState = HM_CRITICAL;
  1551. // pirs->unknownReason = HMRES_NULLVALUE;
  1552. pirs->lCurrState = HM_GOOD;
  1553. pirs->lCrossCountTry = 0;
  1554. return TRUE;
  1555. }
  1556. if (m_lTestCondition == HM_LT)
  1557. {
  1558. if (ppn->type == CIM_STRING)
  1559. {
  1560. bAllDigits = FALSE;
  1561. i = 0;
  1562. while (szTestValue[i])
  1563. {
  1564. if (i==0)
  1565. bAllDigits = TRUE;
  1566. if (!iswdigit(szTestValue[i]))
  1567. {
  1568. bAllDigits = FALSE;
  1569. break;
  1570. }
  1571. i++;
  1572. }
  1573. if (bAllDigits == FALSE)
  1574. {
  1575. if (mg_bEnglishCompare == TRUE)
  1576. {
  1577. if (_wcsicmp(szTestValue, m_szCompareValue)>=0)
  1578. {
  1579. bReset = TRUE;
  1580. }
  1581. }
  1582. else
  1583. {
  1584. if (_wcsicoll(szTestValue, m_szCompareValue)>=0)
  1585. {
  1586. bReset = TRUE;
  1587. }
  1588. }
  1589. }
  1590. else
  1591. {
  1592. __int64 i64Value = _wtoi64(szTestValue);
  1593. bReset = (i64Value >= m_i64CompareValue);
  1594. }
  1595. }
  1596. else if (ppn->type == CIM_DATETIME)
  1597. {
  1598. if (_wcsicmp(szTestValue, m_szCompareValue)>=0)
  1599. {
  1600. bReset = TRUE;
  1601. }
  1602. }
  1603. else if (ppn->type == CIM_REAL32)
  1604. {
  1605. bReset = (testValue.fValue >= m_fCompareValue);
  1606. }
  1607. else if (ppn->type == CIM_REAL64)
  1608. {
  1609. bReset = (testValue.dValue >= m_dCompareValue);
  1610. }
  1611. else if (ppn->type == CIM_SINT64)
  1612. {
  1613. bReset = (testValue.i64Value >= m_i64CompareValue);
  1614. }
  1615. else if (ppn->type == CIM_UINT64)
  1616. {
  1617. bReset = (testValue.ui64Value >= m_ui64CompareValue);
  1618. }
  1619. else if (ppn->type == CIM_UINT32)
  1620. {
  1621. bReset = (testValue.ulValue >= m_ulCompareValue);
  1622. }
  1623. else
  1624. {
  1625. // Must be an integer type
  1626. bReset = (testValue.lValue >= m_lCompareValue);
  1627. }
  1628. }
  1629. else if (m_lTestCondition == HM_GT)
  1630. {
  1631. if (ppn->type == CIM_STRING)
  1632. {
  1633. bAllDigits = FALSE;
  1634. i = 0;
  1635. while (szTestValue[i])
  1636. {
  1637. if (i==0)
  1638. bAllDigits = TRUE;
  1639. if (!iswdigit(szTestValue[i]))
  1640. {
  1641. bAllDigits = FALSE;
  1642. break;
  1643. }
  1644. i++;
  1645. }
  1646. if (bAllDigits == FALSE)
  1647. {
  1648. if (mg_bEnglishCompare == TRUE)
  1649. {
  1650. if (_wcsicmp(szTestValue, m_szCompareValue)<=0)
  1651. {
  1652. bReset = TRUE;
  1653. }
  1654. }
  1655. else
  1656. {
  1657. if (_wcsicoll(szTestValue, m_szCompareValue)<=0)
  1658. {
  1659. bReset = TRUE;
  1660. }
  1661. }
  1662. }
  1663. else
  1664. {
  1665. __int64 i64Value = _wtoi64(szTestValue);
  1666. bReset = (i64Value <= m_i64CompareValue);
  1667. }
  1668. }
  1669. else if (ppn->type == CIM_DATETIME)
  1670. {
  1671. if (_wcsicmp(szTestValue, m_szCompareValue)<=0)
  1672. {
  1673. bReset = TRUE;
  1674. }
  1675. }
  1676. else if (ppn->type == CIM_REAL32)
  1677. {
  1678. bReset = (testValue.fValue <= m_fCompareValue);
  1679. }
  1680. else if (ppn->type == CIM_REAL64)
  1681. {
  1682. bReset = (testValue.dValue <= m_dCompareValue);
  1683. }
  1684. else if (ppn->type == CIM_SINT64)
  1685. {
  1686. bReset = (testValue.i64Value <= m_i64CompareValue);
  1687. }
  1688. else if (ppn->type == CIM_UINT64)
  1689. {
  1690. bReset = (testValue.ui64Value <= m_ui64CompareValue);
  1691. }
  1692. else if (ppn->type == CIM_UINT32)
  1693. {
  1694. bReset = (testValue.ulValue <= m_ulCompareValue);
  1695. }
  1696. else
  1697. {
  1698. // Must be an integer type
  1699. bReset = (testValue.lValue <= m_lCompareValue);
  1700. }
  1701. }
  1702. else if (m_lTestCondition == HM_EQ)
  1703. {
  1704. if (ppn->type == CIM_STRING)
  1705. {
  1706. if (mg_bEnglishCompare == TRUE)
  1707. {
  1708. if (_wcsicmp(szTestValue, m_szCompareValue)!=0)
  1709. {
  1710. bReset = TRUE;
  1711. }
  1712. }
  1713. else
  1714. {
  1715. if (_wcsicoll(szTestValue, m_szCompareValue)!=0)
  1716. {
  1717. bReset = TRUE;
  1718. }
  1719. }
  1720. }
  1721. else if (ppn->type == CIM_DATETIME)
  1722. {
  1723. if (_wcsicmp(szTestValue, m_szCompareValue)==0)
  1724. {
  1725. bReset = TRUE;
  1726. }
  1727. }
  1728. else if (ppn->type == CIM_REAL32)
  1729. {
  1730. bReset = (testValue.fValue != m_fCompareValue);
  1731. }
  1732. else if (ppn->type == CIM_REAL64)
  1733. {
  1734. bReset = (testValue.dValue != m_dCompareValue);
  1735. }
  1736. else if (ppn->type == CIM_SINT64)
  1737. {
  1738. bReset = (testValue.i64Value != m_i64CompareValue);
  1739. }
  1740. else if (ppn->type == CIM_UINT64)
  1741. {
  1742. bReset = (testValue.ui64Value != m_ui64CompareValue);
  1743. }
  1744. else if (ppn->type == CIM_UINT32)
  1745. {
  1746. bReset = (testValue.ulValue != m_ulCompareValue);
  1747. }
  1748. else
  1749. {
  1750. bReset = (testValue.lValue != m_lCompareValue);
  1751. }
  1752. }
  1753. else if (m_lTestCondition == HM_NE)
  1754. {
  1755. if (ppn->type == CIM_STRING)
  1756. {
  1757. if (mg_bEnglishCompare == TRUE)
  1758. {
  1759. if (_wcsicmp(szTestValue, m_szCompareValue)==0)
  1760. {
  1761. bReset = TRUE;
  1762. }
  1763. }
  1764. else
  1765. {
  1766. if (_wcsicoll(szTestValue, m_szCompareValue)==0)
  1767. {
  1768. bReset = TRUE;
  1769. }
  1770. }
  1771. }
  1772. else if (ppn->type == CIM_DATETIME)
  1773. {
  1774. if (_wcsicmp(szTestValue, m_szCompareValue)==0)
  1775. {
  1776. bReset = TRUE;
  1777. }
  1778. }
  1779. else if (ppn->type == CIM_REAL32)
  1780. {
  1781. bReset = (testValue.fValue == m_fCompareValue);
  1782. }
  1783. else if (ppn->type == CIM_REAL64)
  1784. {
  1785. bReset = (testValue.dValue == m_dCompareValue);
  1786. }
  1787. else if (ppn->type == CIM_SINT64)
  1788. {
  1789. bReset = (testValue.i64Value == m_i64CompareValue);
  1790. }
  1791. else if (ppn->type == CIM_UINT64)
  1792. {
  1793. bReset = (testValue.ui64Value == m_ui64CompareValue);
  1794. }
  1795. else if (ppn->type == CIM_UINT32)
  1796. {
  1797. bReset = (testValue.ulValue == m_ulCompareValue);
  1798. }
  1799. else
  1800. {
  1801. // Must be an integer type
  1802. bReset = (testValue.lValue == m_lCompareValue);
  1803. }
  1804. }
  1805. else if (m_lTestCondition == HM_GE)
  1806. {
  1807. if (ppn->type == CIM_STRING)
  1808. {
  1809. bAllDigits = FALSE;
  1810. i = 0;
  1811. while (szTestValue[i])
  1812. {
  1813. if (i==0)
  1814. bAllDigits = TRUE;
  1815. if (!iswdigit(szTestValue[i]))
  1816. {
  1817. bAllDigits = FALSE;
  1818. break;
  1819. }
  1820. i++;
  1821. }
  1822. if (bAllDigits == FALSE)
  1823. {
  1824. if (mg_bEnglishCompare == TRUE)
  1825. {
  1826. if (_wcsicmp(szTestValue, m_szCompareValue)<0)
  1827. {
  1828. bReset = TRUE;
  1829. }
  1830. }
  1831. else
  1832. {
  1833. if (_wcsicoll(szTestValue, m_szCompareValue)<0)
  1834. {
  1835. bReset = TRUE;
  1836. }
  1837. }
  1838. }
  1839. else
  1840. {
  1841. __int64 i64Value = _wtoi64(szTestValue);
  1842. bReset = (i64Value < m_i64CompareValue);
  1843. }
  1844. }
  1845. else if (ppn->type == CIM_DATETIME)
  1846. {
  1847. if (_wcsicmp(szTestValue, m_szCompareValue)<0)
  1848. {
  1849. bReset = TRUE;
  1850. }
  1851. }
  1852. else if (ppn->type == CIM_REAL32)
  1853. {
  1854. bReset = (testValue.fValue < m_fCompareValue);
  1855. }
  1856. else if (ppn->type == CIM_REAL64)
  1857. {
  1858. bReset = (testValue.dValue < m_dCompareValue);
  1859. }
  1860. else if (ppn->type == CIM_SINT64)
  1861. {
  1862. bReset = (testValue.i64Value < m_i64CompareValue);
  1863. }
  1864. else if (ppn->type == CIM_UINT64)
  1865. {
  1866. bReset = (testValue.ui64Value < m_ui64CompareValue);
  1867. }
  1868. else if (ppn->type == CIM_UINT32)
  1869. {
  1870. bReset = (testValue.ulValue < m_ulCompareValue);
  1871. }
  1872. else
  1873. {
  1874. // Must be an integer type
  1875. bReset = (testValue.lValue < m_lCompareValue);
  1876. }
  1877. }
  1878. else if (m_lTestCondition == HM_LE)
  1879. {
  1880. if (ppn->type == CIM_STRING)
  1881. {
  1882. bAllDigits = FALSE;
  1883. i = 0;
  1884. while (szTestValue[i])
  1885. {
  1886. if (i==0)
  1887. bAllDigits = TRUE;
  1888. if (!iswdigit(szTestValue[i]))
  1889. {
  1890. bAllDigits = FALSE;
  1891. break;
  1892. }
  1893. i++;
  1894. }
  1895. if (bAllDigits == FALSE)
  1896. {
  1897. if (mg_bEnglishCompare == TRUE)
  1898. {
  1899. if (_wcsicmp(szTestValue, m_szCompareValue)>0)
  1900. {
  1901. bReset = TRUE;
  1902. }
  1903. }
  1904. else
  1905. {
  1906. if (_wcsicoll(szTestValue, m_szCompareValue)>0)
  1907. {
  1908. bReset = TRUE;
  1909. }
  1910. }
  1911. }
  1912. else
  1913. {
  1914. __int64 i64Value = _wtoi64(szTestValue);
  1915. bReset = (i64Value > m_i64CompareValue);
  1916. }
  1917. }
  1918. else if (ppn->type == CIM_DATETIME)
  1919. {
  1920. if (_wcsicmp(szTestValue, m_szCompareValue)>0)
  1921. {
  1922. bReset = TRUE;
  1923. }
  1924. }
  1925. else if (ppn->type == CIM_REAL32)
  1926. {
  1927. bReset = (testValue.fValue > m_fCompareValue);
  1928. }
  1929. else if (ppn->type == CIM_REAL64)
  1930. {
  1931. bReset = (testValue.dValue > m_dCompareValue);
  1932. }
  1933. else if (ppn->type == CIM_SINT64)
  1934. {
  1935. bReset = (testValue.i64Value > m_i64CompareValue);
  1936. }
  1937. else if (ppn->type == CIM_UINT64)
  1938. {
  1939. bReset = (testValue.ui64Value > m_ui64CompareValue);
  1940. }
  1941. else if (ppn->type == CIM_UINT32)
  1942. {
  1943. bReset = (testValue.ulValue > m_ulCompareValue);
  1944. }
  1945. else
  1946. {
  1947. // Must be an integer type
  1948. bReset = (testValue.lValue > m_lCompareValue);
  1949. }
  1950. }
  1951. else if (m_lTestCondition == HM_CONTAINS)
  1952. {
  1953. if (ppn->type == CIM_STRING)
  1954. {
  1955. pszCompareValueUpper = _wcsdup(m_szCompareValue);
  1956. MY_ASSERT(pszCompareValueUpper); if (!pszCompareValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1957. _wcsupr(pszCompareValueUpper);
  1958. pszTestValueUpper = _wcsdup(szTestValue);
  1959. MY_ASSERT(pszTestValueUpper); if (!pszTestValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1960. _wcsupr(pszTestValueUpper);
  1961. if (!wcsstr(pszTestValueUpper, pszCompareValueUpper))
  1962. {
  1963. bReset = TRUE;
  1964. }
  1965. free(pszCompareValueUpper);
  1966. pszCompareValueUpper = NULL;
  1967. free(pszTestValueUpper);
  1968. pszTestValueUpper = NULL;
  1969. }
  1970. else if (ppn->type == CIM_DATETIME)
  1971. {
  1972. if (!wcsstr(szTestValue, m_szCompareValue))
  1973. {
  1974. bReset = TRUE;
  1975. }
  1976. }
  1977. else if (ppn->type == CIM_REAL32)
  1978. {
  1979. _gcvt((double)testValue.fValue, 7, buffer);
  1980. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  1981. szTemp[rc] = NULL;
  1982. if (!wcsstr(szTemp, m_szCompareValue))
  1983. {
  1984. bReset = TRUE;
  1985. }
  1986. }
  1987. else if (ppn->type == CIM_REAL64)
  1988. {
  1989. _gcvt(testValue.dValue, 7, buffer);
  1990. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  1991. szTemp[rc] = NULL;
  1992. if (!wcsstr(szTemp, m_szCompareValue))
  1993. {
  1994. bReset = TRUE;
  1995. }
  1996. }
  1997. else if (ppn->type == CIM_SINT64)
  1998. {
  1999. _i64tow(testValue.i64Value, szTemp, 10 );
  2000. if (!wcsstr(szTemp, m_szCompareValue))
  2001. {
  2002. bReset = TRUE;
  2003. }
  2004. }
  2005. else if (ppn->type == CIM_UINT64)
  2006. {
  2007. _ui64tow((int)testValue.ui64Value, szTemp, 10);
  2008. if (!wcsstr(szTemp, m_szCompareValue))
  2009. {
  2010. bReset = TRUE;
  2011. }
  2012. }
  2013. else if (ppn->type == CIM_UINT32)
  2014. {
  2015. // Must be an integer type
  2016. _ultow(testValue.ulValue, szTemp, 10);
  2017. if (!wcsstr(szTemp, m_szCompareValue))
  2018. {
  2019. bReset = TRUE;
  2020. }
  2021. }
  2022. else
  2023. {
  2024. // Must be an integer type
  2025. _ltow(testValue.lValue, szTemp, 10);
  2026. if (!wcsstr(szTemp, m_szCompareValue))
  2027. {
  2028. bReset = TRUE;
  2029. }
  2030. }
  2031. }
  2032. else if (m_lTestCondition == HM_NOTCONTAINS)
  2033. {
  2034. if (ppn->type == CIM_STRING)
  2035. {
  2036. pszCompareValueUpper = _wcsdup(m_szCompareValue);
  2037. MY_ASSERT(pszCompareValueUpper); if (!pszCompareValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2038. _wcsupr(pszCompareValueUpper);
  2039. pszTestValueUpper = _wcsdup(szTestValue);
  2040. MY_ASSERT(pszTestValueUpper); if (!pszTestValueUpper) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2041. _wcsupr(pszTestValueUpper);
  2042. if (wcsstr(pszTestValueUpper, pszCompareValueUpper))
  2043. {
  2044. bReset = TRUE;
  2045. }
  2046. free(pszCompareValueUpper);
  2047. pszCompareValueUpper = NULL;
  2048. free(pszTestValueUpper);
  2049. pszTestValueUpper = NULL;
  2050. }
  2051. else if (ppn->type == CIM_DATETIME)
  2052. {
  2053. if (wcsstr(szTestValue, m_szCompareValue))
  2054. {
  2055. bReset = TRUE;
  2056. }
  2057. }
  2058. else if (ppn->type == CIM_REAL32)
  2059. {
  2060. _gcvt((double)testValue.fValue, 7, buffer);
  2061. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2062. szTemp[rc] = NULL;
  2063. if (wcsstr(szTemp, m_szCompareValue))
  2064. {
  2065. bReset = TRUE;
  2066. }
  2067. }
  2068. else if (ppn->type == CIM_REAL64)
  2069. {
  2070. _gcvt(testValue.dValue, 7, buffer);
  2071. rc = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, buffer, strlen(buffer), szTemp, 128);
  2072. szTemp[rc] = NULL;
  2073. if (wcsstr(szTemp, m_szCompareValue))
  2074. {
  2075. bReset = TRUE;
  2076. }
  2077. }
  2078. else if (ppn->type == CIM_SINT64)
  2079. {
  2080. _i64tow(testValue.i64Value, szTemp, 10 );
  2081. if (wcsstr(szTemp, m_szCompareValue))
  2082. {
  2083. bReset = TRUE;
  2084. }
  2085. }
  2086. else if (ppn->type == CIM_UINT64)
  2087. {
  2088. _ui64tow((int)testValue.ui64Value, szTemp, 10);
  2089. if (wcsstr(szTemp, m_szCompareValue))
  2090. {
  2091. bReset = TRUE;
  2092. }
  2093. }
  2094. else if (ppn->type == CIM_UINT32)
  2095. {
  2096. _ultow(testValue.ulValue, szTemp, 10);
  2097. if (wcsstr(szTemp, m_szCompareValue))
  2098. {
  2099. bReset = TRUE;
  2100. }
  2101. }
  2102. else
  2103. {
  2104. // Must be an integer type
  2105. _ltow(testValue.lValue, szTemp, 10);
  2106. if (wcsstr(szTemp, m_szCompareValue))
  2107. {
  2108. bReset = TRUE;
  2109. }
  2110. }
  2111. }
  2112. else if (m_lTestCondition == HM_ALWAYS)
  2113. {
  2114. }
  2115. else
  2116. {
  2117. MY_ASSERT(FALSE);
  2118. }
  2119. //
  2120. // Now see if the duration test has been met
  2121. //
  2122. if (bReset)
  2123. {
  2124. pirs->lCurrState = HM_GOOD;
  2125. pirs->lCrossCountTry = 0;
  2126. }
  2127. else
  2128. {
  2129. }
  2130. MY_OUTPUT(L"EXIT ***** RearmTest...", 1);
  2131. return TRUE;
  2132. error:
  2133. MY_ASSERT(FALSE);
  2134. if (pszCompareValueUpper)
  2135. free(pszCompareValueUpper);
  2136. if (pszTestValueUpper)
  2137. free(pszTestValueUpper);
  2138. Cleanup(FALSE);
  2139. m_bValidLoad = FALSE;
  2140. return FALSE;
  2141. }
  2142. LPTSTR CThreshold::GetPropertyName(void)
  2143. {
  2144. return m_szPropertyName;
  2145. }
  2146. HRESULT CThreshold::GetHMThresholdStatusInstance(IWbemClassObject** ppThresholdInstance, BOOL bEventBased)
  2147. {
  2148. TCHAR szTemp[1024];
  2149. IWbemClassObject* pClass = NULL;
  2150. BSTR bsString = NULL;
  2151. HRESULT hRes;
  2152. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 2;
  2153. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 2];
  2154. MY_OUTPUT(_T("ENTER ***** GetHMSystemStatusInstance..."), 1);
  2155. if (bEventBased)
  2156. {
  2157. bsString = SysAllocString(L"MicrosoftHM_ThresholdStatusEvent");
  2158. }
  2159. else
  2160. {
  2161. bsString = SysAllocString(L"MicrosoftHM_ThresholdStatus");
  2162. }
  2163. MY_ASSERT(bsString); if (!bsString) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2164. hRes = g_pIWbemServices->GetObject(bsString, 0L, NULL, &pClass, NULL);
  2165. SysFreeString(bsString);
  2166. bsString = NULL;
  2167. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2168. hRes = pClass->SpawnInstance(0, ppThresholdInstance);
  2169. pClass->Release();
  2170. pClass = NULL;
  2171. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2172. if (m_bValidLoad == FALSE)
  2173. {
  2174. hRes = PutStrProperty(*ppThresholdInstance, L"GUID", m_szGUID);
  2175. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2176. hRes = PutUint32Property(*ppThresholdInstance, L"State", HM_CRITICAL);
  2177. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2178. if (g_hResLib == NULL || !LoadString(g_hResLib, HMRES_THRESHOLD_LOADFAIL, szTemp, 1024))
  2179. {
  2180. wcscpy(szTemp, L"Threshold failed to load.");
  2181. }
  2182. hRes = PutStrProperty(*ppThresholdInstance, L"Message", szTemp);
  2183. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2184. hRes = PutStrProperty(*ppThresholdInstance, L"Name", L"...");
  2185. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2186. }
  2187. else
  2188. {
  2189. hRes = PutStrProperty(*ppThresholdInstance, L"GUID", m_szGUID);
  2190. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2191. hRes = PutStrProperty(*ppThresholdInstance, L"ParentGUID", m_pParentDC->m_szGUID);
  2192. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2193. hRes = PutStrProperty(*ppThresholdInstance, L"Name", m_szName);
  2194. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2195. if (GetComputerName(szComputerName, &dwNameLen))
  2196. {
  2197. hRes = PutStrProperty(*ppThresholdInstance, L"SystemName", szComputerName);
  2198. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2199. }
  2200. else
  2201. {
  2202. hRes = PutStrProperty(*ppThresholdInstance, L"SystemName", L"LocalMachine");
  2203. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2204. }
  2205. hRes = PutStrProperty(*ppThresholdInstance, L"TimeGeneratedGMT", m_szDTTime);
  2206. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2207. hRes = PutStrProperty(*ppThresholdInstance, L"LocalTimeFormatted", m_szTime);
  2208. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2209. if (m_lCurrState==HM_RESET || (m_lViolationToState==HM_RESET && m_lCurrState==HM_COLLECTING))
  2210. hRes = PutUint32Property(*ppThresholdInstance, L"State", HM_GOOD);
  2211. else
  2212. hRes = PutUint32Property(*ppThresholdInstance, L"State", m_lCurrState);
  2213. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2214. }
  2215. MY_OUTPUT(_T("EXIT ***** GetHMSystemStatusInstance..."), 1);
  2216. return hRes;
  2217. error:
  2218. MY_ASSERT(FALSE);
  2219. if (bsString)
  2220. SysFreeString(bsString);
  2221. if (pClass)
  2222. pClass->Release();
  2223. Cleanup(FALSE);
  2224. m_bValidLoad = FALSE;
  2225. return hRes;
  2226. }
  2227. // For a single GetObject
  2228. HRESULT CThreshold::SendHMThresholdStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  2229. {
  2230. MY_ASSERT(pSink!=NULL);
  2231. //
  2232. // Is this the one we are looking for?
  2233. //
  2234. if (!_wcsicmp(m_szGUID, pszGUID))
  2235. {
  2236. //XXX if (m_bValidLoad == FALSE)
  2237. //XXX return WBEM_E_INVALID_OBJECT;
  2238. return SendHMThresholdStatusInstances(pSink);
  2239. }
  2240. else
  2241. {
  2242. return WBEM_S_DIFFERENT;
  2243. }
  2244. }
  2245. // This one is for enumeration of all HMThresholdStatus Instances outside of the hierarchy.
  2246. // Just the flat list.
  2247. HRESULT CThreshold::SendHMThresholdStatusInstances(IWbemObjectSink* pSink)
  2248. {
  2249. HRESULT hRes = S_OK;
  2250. IWbemClassObject* pInstance = NULL;
  2251. MY_OUTPUT(L"ENTER ***** SendHMThresholdStatusInstances...", 2);
  2252. //XXX if (m_bValidLoad == FALSE)
  2253. //XXX return WBEM_E_INVALID_OBJECT;
  2254. if (pSink == NULL)
  2255. {
  2256. MY_OUTPUT(L"CDC::SendInitialHMMachStatInstances-Invalid Sink", 1);
  2257. return WBEM_E_FAILED;
  2258. }
  2259. hRes = GetHMThresholdStatusInstance(&pInstance, FALSE);
  2260. if (SUCCEEDED(hRes))
  2261. {
  2262. hRes = pSink->Indicate(1, &pInstance);
  2263. if (FAILED(hRes) && hRes!=WBEM_E_SERVER_TOO_BUSY && hRes!=WBEM_E_CALL_CANCELLED && hRes!=WBEM_E_TRANSPORT_FAILURE)
  2264. {
  2265. MY_HRESASSERT(hRes);
  2266. MY_OUTPUT(L"SendHMThresholdStatusInstances-failed to send status!", 1);
  2267. }
  2268. pInstance->Release();
  2269. pInstance = NULL;
  2270. }
  2271. else
  2272. {
  2273. MY_HRESASSERT(hRes);
  2274. MY_OUTPUT(L":SendHMThresholdStatusInstances-failed to get instance!", 1);
  2275. }
  2276. MY_OUTPUT(L"EXIT ***** SendHMThresholdStatusInstances...", 2);
  2277. return hRes;
  2278. }
  2279. #ifdef SAVE
  2280. // For a single GetObject
  2281. HRESULT CThreshold::SendHMThresholdStatusInstanceInstance(ACTUALINSTLIST *actualInstList, PNSTRUCT *ppn, IWbemObjectSink* pSink, LPTSTR pszGUID)
  2282. {
  2283. MY_OUTPUT(L"ENTER ***** SendHMThresholdStatusInstance...", 1);
  2284. //
  2285. // Is this the one we are looking for?
  2286. //
  2287. if (!_wcsicmp(m_szGUID, pszGUID))
  2288. {
  2289. SendHMThresholdStatusInstanceInstances(actualInstList, ppn, pSink);
  2290. return TRUE;
  2291. }
  2292. MY_OUTPUT(L"EXIT ***** SendHMThresholdStatusInstance...", 1);
  2293. return FALSE;
  2294. }
  2295. // This one is for enumeration of all HMThresholdStatus Instances outside of the hierarchy.
  2296. // Just the flat list.
  2297. HRESULT CThreshold::SendHMThresholdStatusInstanceInstances(ACTUALINSTLIST *actualInstList, PNSTRUCT *ppn, IWbemObjectSink* pSink)
  2298. {
  2299. int i, iSize;
  2300. IRSSTRUCT *pirs;
  2301. INSTSTRUCT *pinst;
  2302. HRESULT hRes = S_OK;
  2303. IWbemClassObject* pObj = NULL;
  2304. ACTUALINSTSTRUCT *pActualInst;
  2305. MY_OUTPUT(L"ENTER ***** SendHMSystemStatusInstances...", 2);
  2306. if (pSink == NULL)
  2307. {
  2308. MY_OUTPUT(L"CDP::SendInitialHMMachStatInstances-Invalid Sink", 1);
  2309. return WBEM_E_INVALID_PARAMETER;
  2310. }
  2311. //XXXABC
  2312. // MY_ASSERT(m_irsList.size() == actualInstList->size());
  2313. if (_wcsicmp(m_szPropertyName, L"CollectionInstanceCount") &&
  2314. _wcsicmp(m_szPropertyName, L"CollectionErrorCode") &&
  2315. _wcsicmp(m_szPropertyName, L"CollectionErrorDescription"))
  2316. {
  2317. MY_ASSERT(m_irsList.size() == actualInstList->size());
  2318. }
  2319. iSize = m_irsList.size();
  2320. for (i=0; i<iSize; i++)
  2321. {
  2322. MY_ASSERT(i<ppn->instList.size());
  2323. pinst = &ppn->instList[i];
  2324. MY_ASSERT(i<m_irsList.size());
  2325. pirs = &m_irsList[i];
  2326. if (!_wcsicmp(m_szPropertyName, L"CollectionInstanceCount") ||
  2327. !_wcsicmp(m_szPropertyName, L"CollectionErrorCode") ||
  2328. !_wcsicmp(m_szPropertyName, L"CollectionErrorDescription"))
  2329. {
  2330. pActualInst = NULL;
  2331. }
  2332. else
  2333. {
  2334. pActualInst = &(*actualInstList)[i];
  2335. }
  2336. // Provide HMMachStatus Instance
  2337. hRes = GetHMThresholdStatusInstanceInstance(pActualInst, ppn, pinst, pirs, &pObj, FALSE);
  2338. if (SUCCEEDED(hRes))
  2339. {
  2340. hRes = pSink->Indicate(1, &pObj);
  2341. if (FAILED(hRes) && hRes != WBEM_E_SERVER_TOO_BUSY)
  2342. {
  2343. MY_HRESASSERT(hRes);
  2344. MY_OUTPUT(L"SendHMSystemStatusInstances-failed to send status!", 1);
  2345. }
  2346. pObj->Release();
  2347. pObj = NULL;
  2348. }
  2349. else
  2350. {
  2351. MY_HRESASSERT(hRes);
  2352. MY_OUTPUT(L":SendHMSystemStatusInstances-failed to get instance!", 1);
  2353. }
  2354. }
  2355. MY_OUTPUT(L"EXIT ***** SendHMSystemStatusInstances...", 2);
  2356. return hRes;
  2357. }
  2358. #endif
  2359. long CThreshold::GetCurrState(void)
  2360. {
  2361. return m_lCurrState;
  2362. }
  2363. HRESULT CThreshold::FindAndModThreshold(BSTR szGUID, IWbemClassObject* pObj)
  2364. {
  2365. HRESULT hRes = S_OK;
  2366. //
  2367. // Is this us we are looking for?
  2368. //
  2369. if (!_wcsicmp(m_szGUID, szGUID))
  2370. {
  2371. hRes = LoadInstanceFromMOF(pObj, NULL, L"", TRUE);
  2372. return hRes;
  2373. }
  2374. return WBEM_S_DIFFERENT;
  2375. }
  2376. LPTSTR CThreshold::GetGUID(void)
  2377. {
  2378. return m_szGUID;
  2379. }
  2380. BOOL CThreshold::SetParentEnabledFlag(BOOL bEnabled)
  2381. {
  2382. m_bParentEnabled = bEnabled;
  2383. return TRUE;
  2384. }
  2385. BOOL CThreshold::SetParentScheduledOutFlag(BOOL bScheduledOut)
  2386. {
  2387. m_bParentScheduledOut = bScheduledOut;
  2388. return TRUE;
  2389. }
  2390. BOOL CThreshold::SetCurrState(HM_STATE state, BOOL bForce/*=FALSE*/, int reason/* = 0*/)
  2391. {
  2392. int i, iSize;
  2393. IRSSTRUCT *pirs;
  2394. if (m_pParentDC->m_deType==HM_EQDE && (m_bEnabled==FALSE || m_bParentEnabled==FALSE))
  2395. {
  2396. if (m_lCurrState!=HM_DISABLED)
  2397. {
  2398. m_lCurrState = HM_DISABLED;
  2399. m_lNumberChanges++;
  2400. }
  2401. return TRUE;
  2402. }
  2403. m_lNumberChanges = 0;
  2404. iSize = m_irsList.size();
  2405. for (i = 0; i < iSize ; i++)
  2406. {
  2407. MY_ASSERT(i<m_irsList.size());
  2408. pirs = &m_irsList[i];
  2409. if (pirs->lCurrState != state)
  2410. {
  2411. m_lNumberChanges++;
  2412. }
  2413. pirs->lCurrState = state;
  2414. pirs->unknownReason = reason;
  2415. }
  2416. if (iSize==0 || bForce)
  2417. {
  2418. if (m_lCurrState!=state || bForce)
  2419. {
  2420. m_lNumberChanges++;
  2421. }
  2422. }
  2423. m_lCurrState = state;
  2424. return TRUE;
  2425. }
  2426. BOOL CThreshold::SetBackPrev(PNSTRUCT *ppn)
  2427. {
  2428. int i, iSize;
  2429. IRSSTRUCT *pirs;
  2430. iSize = m_irsList.size();
  2431. for (i = 0; i < iSize ; i++)
  2432. {
  2433. MY_ASSERT(i<m_irsList.size());
  2434. pirs = &m_irsList[i];
  2435. if (ppn->type == CIM_REAL32)
  2436. {
  2437. pirs->fPrevValue = pirs->fPrevPrevValue;
  2438. }
  2439. else if (ppn->type == CIM_REAL64)
  2440. {
  2441. pirs->dPrevValue = pirs->dPrevPrevValue;
  2442. }
  2443. else if (ppn->type == CIM_SINT64)
  2444. {
  2445. pirs->i64PrevValue = pirs->i64PrevPrevValue;
  2446. }
  2447. else if (ppn->type == CIM_UINT64)
  2448. {
  2449. pirs->ui64PrevValue = pirs->ui64PrevPrevValue;
  2450. }
  2451. else if (ppn->type == CIM_UINT32)
  2452. {
  2453. pirs->ulPrevValue = pirs->ulPrevPrevValue;
  2454. }
  2455. else
  2456. {
  2457. pirs->lPrevValue = pirs->lPrevPrevValue;
  2458. }
  2459. }
  2460. return TRUE;
  2461. }
  2462. BOOL CThreshold::ResetResetThreshold(void)
  2463. {
  2464. int i, iSize;
  2465. IRSSTRUCT *pirs;
  2466. m_lCurrState = HM_RESET;
  2467. m_lPrevState = HM_RESET;
  2468. iSize = m_irsList.size();
  2469. for (i = 0; i < iSize ; i++)
  2470. {
  2471. MY_ASSERT(i<m_irsList.size());
  2472. pirs = &m_irsList[i];
  2473. pirs->lCurrState = HM_RESET;
  2474. pirs->lPrevState = HM_RESET;
  2475. pirs->unknownReason = 0;
  2476. }
  2477. m_lNumberChanges = 0;
  2478. return TRUE;
  2479. }
  2480. BOOL CThreshold::GetChange(void)
  2481. {
  2482. if (m_lNumberChanges!=0 && m_lPrevState!=m_lCurrState)
  2483. {
  2484. return TRUE;
  2485. }
  2486. else
  2487. {
  2488. return FALSE;
  2489. }
  2490. }
  2491. BOOL CThreshold::GetEnabledChange(void)
  2492. {
  2493. BOOL bChanged = FALSE;
  2494. if ((m_bEnabled==FALSE || m_bParentEnabled==FALSE) && m_lCurrState!=HM_DISABLED)
  2495. {
  2496. bChanged = TRUE;
  2497. }
  2498. if ((m_bEnabled==TRUE && m_bParentEnabled==TRUE) && m_lCurrState==HM_DISABLED)
  2499. {
  2500. bChanged = TRUE;
  2501. }
  2502. return bChanged;
  2503. }
  2504. HRESULT CThreshold::AddInstance(LPTSTR pszID)
  2505. {
  2506. HRESULT hRes = S_OK;
  2507. GUID guid;
  2508. IRSSTRUCT irs;
  2509. irs.szInstanceID = new TCHAR[wcslen(pszID)+2];
  2510. MY_ASSERT(irs.szInstanceID); if (!irs.szInstanceID) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2511. wcscpy(irs.szInstanceID, pszID);
  2512. // yyyymmddhhmmss.ssssssXUtc; X = GMT(+ or -), Utc = 3 dig. offset from UTC.")]
  2513. wcscpy(irs.szDTTime, m_szDTCurrTime);
  2514. wcscpy(irs.szTime, m_szCurrTime);
  2515. hRes = CoCreateGuid(&guid);
  2516. MY_HRESASSERT(hRes); if (hRes!=S_OK) goto error;
  2517. irs.szStatusGUID = new TCHAR[100];
  2518. MY_ASSERT(irs.szStatusGUID); if (!irs.szStatusGUID) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2519. StringFromGUID2(guid, irs.szStatusGUID, 100);
  2520. irs.lCurrState = HM_COLLECTING;
  2521. irs.lPrevState = HM_COLLECTING;
  2522. irs.unknownReason = 0;
  2523. irs.lCrossCountTry = 0;
  2524. irs.fPrevValue = MAX_FLOAT;
  2525. irs.dPrevValue = MAX_DOUBLE;
  2526. irs.i64PrevValue = MAX_I64;
  2527. irs.ui64PrevValue = MAX_UI64;
  2528. irs.lPrevValue = MAX_LONG;
  2529. irs.ulPrevValue = MAX_ULONG;
  2530. irs.bNeeded = TRUE;
  2531. m_irsList.push_back(irs);
  2532. return S_OK;
  2533. error:
  2534. MY_ASSERT(FALSE);
  2535. Cleanup(FALSE);
  2536. m_bValidLoad = FALSE;
  2537. return hRes;
  2538. }
  2539. BOOL CThreshold::ClearInstList(void)
  2540. {
  2541. int i, iSize;
  2542. IRSSTRUCT *pirs;
  2543. iSize = m_irsList.size();
  2544. for (i=0; i<iSize; i++)
  2545. {
  2546. MY_ASSERT(i<m_irsList.size());
  2547. pirs = &m_irsList[i];
  2548. if (pirs->szInstanceID)
  2549. {
  2550. delete [] pirs->szInstanceID;
  2551. }
  2552. if (pirs->szStatusGUID)
  2553. {
  2554. delete [] pirs->szStatusGUID;
  2555. }
  2556. }
  2557. m_irsList.clear();
  2558. return TRUE;
  2559. }
  2560. #ifdef SAVE
  2561. //
  2562. // Do string replacement for the Message property
  2563. //
  2564. BOOL CThreshold::FormatMessage(IWbemClassObject* pIRSInstance, IWbemClassObject *pEmbeddedInstance)
  2565. {
  2566. // TCHAR szMsg[1024];
  2567. BSTR PropName = NULL;
  2568. LPTSTR pszMsg = NULL;
  2569. SAFEARRAY *psaNames = NULL;
  2570. long lNum;
  2571. HRESULT hRes;
  2572. LPTSTR pszDest;
  2573. LPTSTR pszUpperMsg;
  2574. LPTSTR pszNewMsg;
  2575. LPTSTR pStr;
  2576. LPTSTR pStrStart;
  2577. TOKENSTRUCT tokenElmnt;
  2578. TOKENSTRUCT *pTokenElmnt;
  2579. REPSTRUCT repElmnt;
  2580. REPSTRUCT *pRepElmnt;
  2581. REPSTRUCT *pRepElmnt2;
  2582. REPLIST replacementList;
  2583. int i, iSize, iSizeNeeded, j;
  2584. // long lMessageRID;
  2585. long lLower, lUpper;
  2586. // long iLBound, iUBound;
  2587. // IUnknown* vUnknown;
  2588. static TOKENLIST tokenList;
  2589. // int iRet;
  2590. TOKENLIST embeddedInstTokenList;
  2591. //
  2592. // We only need to build the set of tokens one time, then from then on
  2593. // we just need to fill in the values for what the replacement strings are.
  2594. //
  2595. if (tokenList.size() == 0)
  2596. {
  2597. //
  2598. // First we build the set of tokens that we are looking for. Each property that
  2599. // is in the ThresholdStatusInstance. We build that set of strings,
  2600. // and the values to replace with.
  2601. //
  2602. //
  2603. // Now go through ThresholdInstance, which is where the Message String
  2604. // actually lives. Get that set of properties for the Instances.
  2605. //
  2606. psaNames = NULL;
  2607. hRes = pIRSInstance->GetNames(NULL, WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
  2608. if (SUCCEEDED(hRes))
  2609. {
  2610. // Get the number of properties.
  2611. SafeArrayGetLBound(psaNames, 1, &lLower);
  2612. SafeArrayGetUBound(psaNames, 1, &lUpper);
  2613. // For each property...
  2614. for (long l=lLower; l<=lUpper; l++)
  2615. {
  2616. // Get this property.
  2617. hRes = SafeArrayGetElement(psaNames, &l, &PropName);
  2618. if (SUCCEEDED(hRes))
  2619. {
  2620. // Will want to skip some that don't make sense.
  2621. if (!wcscmp(PropName, L"Message"))
  2622. {
  2623. SysFreeString(PropName);
  2624. PropName = NULL;
  2625. continue;
  2626. }
  2627. else if (!wcscmp(PropName, L"ResetMessage"))
  2628. {
  2629. SysFreeString(PropName);
  2630. PropName = NULL;
  2631. continue;
  2632. }
  2633. else if (!wcscmp(PropName, L"EmbeddedInstance"))
  2634. {
  2635. SysFreeString(PropName);
  2636. PropName = NULL;
  2637. continue;
  2638. }
  2639. tokenElmnt.szOrigToken = new TCHAR[wcslen(PropName)+1];
  2640. wcscpy(tokenElmnt.szOrigToken, PropName);
  2641. tokenElmnt.szToken = new TCHAR[wcslen(PropName)+3];
  2642. wcscpy(tokenElmnt.szToken, L"%");
  2643. wcscat(tokenElmnt.szToken, PropName);
  2644. wcscat(tokenElmnt.szToken, L"%");
  2645. _wcsupr(tokenElmnt.szToken);
  2646. tokenElmnt.szReplacementText = NULL;
  2647. tokenList.push_back(tokenElmnt);
  2648. SysFreeString(PropName);
  2649. PropName = NULL;
  2650. }
  2651. }
  2652. SafeArrayDestroy(psaNames);
  2653. }
  2654. }
  2655. //
  2656. // Populate the list of properties on the embedded instance that came from the
  2657. // Data Collector.
  2658. //
  2659. if (_wcsicmp(m_szPropertyName, L"CollectionInstanceCount") &&
  2660. _wcsicmp(m_szPropertyName, L"CollectionErrorCode") &&
  2661. _wcsicmp(m_szPropertyName, L"CollectionErrorDescription"))
  2662. {
  2663. psaNames = NULL;
  2664. MY_ASSERT(pEmbeddedInstance);
  2665. hRes = pEmbeddedInstance->GetNames(NULL, WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
  2666. if (SUCCEEDED(hRes))
  2667. {
  2668. // Get the number of properties.
  2669. SafeArrayGetLBound(psaNames, 1, &lLower);
  2670. SafeArrayGetUBound(psaNames, 1, &lUpper);
  2671. // For each property...
  2672. for (long l=lLower; l<=lUpper; l++)
  2673. {
  2674. // Get this property.
  2675. hRes = SafeArrayGetElement(psaNames, &l, &PropName);
  2676. if (SUCCEEDED(hRes))
  2677. {
  2678. tokenElmnt.szOrigToken = new TCHAR[wcslen(PropName)+1];
  2679. wcscpy(tokenElmnt.szOrigToken, PropName);
  2680. tokenElmnt.szToken = new TCHAR[wcslen(PropName)+20];
  2681. wcscpy(tokenElmnt.szToken, L"%");
  2682. wcscat(tokenElmnt.szToken, L"EmbeddedInstance.");
  2683. wcscat(tokenElmnt.szToken, PropName);
  2684. wcscat(tokenElmnt.szToken, L"%");
  2685. _wcsupr(tokenElmnt.szToken);
  2686. tokenElmnt.szReplacementText = NULL;
  2687. embeddedInstTokenList.push_back(tokenElmnt);
  2688. SysFreeString(PropName);
  2689. PropName = NULL;
  2690. }
  2691. }
  2692. SafeArrayDestroy(psaNames);
  2693. }
  2694. }
  2695. //
  2696. // Now we can fill in the values to use for the replacement strings.
  2697. //
  2698. //
  2699. // Now go through each ThresholdInstance, which is where the Message String
  2700. // actually lives. Get that set of properties of the Instance,
  2701. // And do the message formatting while there.
  2702. //
  2703. //
  2704. // Get the replacement strings for this instance
  2705. //
  2706. iSize = tokenList.size();
  2707. for (i=0; i<iSize; i++)
  2708. {
  2709. MY_ASSERT(i<tokenList.size());
  2710. pTokenElmnt = &tokenList[i];
  2711. if (pTokenElmnt->szReplacementText != NULL)
  2712. {
  2713. delete [] pTokenElmnt->szReplacementText;
  2714. }
  2715. if (!wcscmp(pTokenElmnt->szToken, L"%TESTCONDITION%"))
  2716. {
  2717. hRes = GetUint32Property(pIRSInstance, pTokenElmnt->szOrigToken, &lNum);
  2718. MY_HRESASSERT(hRes);
  2719. MY_ASSERT(lNum<9);
  2720. pStr = new TCHAR[wcslen(condition[lNum])+1];
  2721. wcscpy(pStr, condition[lNum]);
  2722. }
  2723. else if (!wcscmp(pTokenElmnt->szToken, L"%STATE%"))
  2724. {
  2725. hRes = GetUint32Property(pIRSInstance, pTokenElmnt->szOrigToken, &lNum);
  2726. MY_HRESASSERT(hRes);
  2727. MY_ASSERT(lNum<10);
  2728. pStr = new TCHAR[wcslen(state[lNum])+1];
  2729. wcscpy(pStr, state[lNum]);
  2730. }
  2731. else
  2732. {
  2733. hRes = GetAsStrProperty(pIRSInstance, pTokenElmnt->szOrigToken, &pStr);
  2734. }
  2735. pTokenElmnt->szReplacementText = pStr;
  2736. MY_HRESASSERT(hRes);
  2737. }
  2738. //
  2739. // Get the replacement strings for this instance - Embedded
  2740. //
  2741. iSize = embeddedInstTokenList.size();
  2742. for (i=0; i<iSize; i++)
  2743. {
  2744. MY_ASSERT(i<embeddedInstTokenList.size());
  2745. pTokenElmnt = &embeddedInstTokenList[i];
  2746. if (pTokenElmnt->szReplacementText != NULL)
  2747. {
  2748. delete [] pTokenElmnt->szReplacementText;
  2749. }
  2750. MY_ASSERT(pEmbeddedInstance);
  2751. hRes = GetAsStrProperty(pEmbeddedInstance, pTokenElmnt->szOrigToken, &pStr);
  2752. pTokenElmnt->szReplacementText = pStr;
  2753. MY_HRESASSERT(hRes);
  2754. }
  2755. //
  2756. // Now we have both lists of tokens that have replacement
  2757. // strings that go with them and the replacement strings
  2758. // that go with them
  2759. //
  2760. //
  2761. // Do formatting of Message. We replace all Variable Tags.
  2762. // Sample string -
  2763. // "Drive %InstanceName% is full. Currently at %CurrentValue%%."
  2764. //
  2765. //
  2766. // Get the origional un-formatted message first.
  2767. // To make case in-sensitive, do a _strdup and then a _wcsupr on the string
  2768. // to scan run the code on it, and then free the duplicated string.
  2769. //
  2770. // If it uses resource IDs, then get that string first, then format that!!!
  2771. hRes = GetStrProperty(pIRSInstance, L"Message", &pszMsg);
  2772. MY_HRESASSERT(hRes);
  2773. // if (!wcscmp(pszMsg, L""))
  2774. // {
  2775. // delete [] pszMsg;
  2776. // hRes = GetUint32Property(pIRSInstance, L"MessageStringRID", &lMessageRID);
  2777. // MY_HRESASSERT(hRes);
  2778. // if (m_hResLib == NULL)
  2779. // {
  2780. // wcscpy(szMsg , L"Resource DLL not found");
  2781. // }
  2782. // else
  2783. // {
  2784. // TCHAR szMsg[1024];
  2785. // int iRet;
  2786. // iRet = LoadString(m_hResLib, lMessageRID, szMsg, 1024);
  2787. // if (iRet == 0)
  2788. // {
  2789. // wcscpy(szMsg , L"Resource string not found");
  2790. // }
  2791. // }
  2792. // pszMsg = new TCHAR[wcslen(szMsg)+2];
  2793. // wcscpy(pszMsg , szMsg);
  2794. // }
  2795. // else
  2796. // {
  2797. // hRes = GetStrProperty(pIRSInstance, L"Message", &pszMsg);
  2798. // MY_HRESASSERT(hRes);
  2799. // }
  2800. pszUpperMsg = _wcsdup(pszMsg);
  2801. _wcsupr(pszUpperMsg);
  2802. //
  2803. // First loop through and find every token that needs replacing.
  2804. // Put that info into the replacement list.
  2805. //
  2806. // We will do strstr() for each special token until there are no more to find
  2807. // for each. At each find we will store the offset into the string of what
  2808. // we found. Then we sort by what came first.
  2809. //
  2810. // Quick test to see if it is worth searching
  2811. if (wcschr(pszUpperMsg, '%'))
  2812. {
  2813. iSize = tokenList.size();
  2814. pStrStart = pszUpperMsg;
  2815. for (i=0; i<iSize; i++)
  2816. {
  2817. MY_ASSERT(i<tokenList.size());
  2818. pTokenElmnt = &tokenList[i];
  2819. pStr = wcsstr(pStrStart, pTokenElmnt->szToken);
  2820. if (pStr != NULL)
  2821. {
  2822. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  2823. repElmnt.len = wcslen(pTokenElmnt->szToken);
  2824. repElmnt.pszReplacementText = pTokenElmnt->szReplacementText;
  2825. replacementList.push_back(repElmnt);
  2826. i--;
  2827. pStrStart = pStr+1;
  2828. }
  2829. else
  2830. {
  2831. pStrStart = pszUpperMsg;
  2832. }
  2833. }
  2834. // Embedded stuff
  2835. iSize = embeddedInstTokenList.size();
  2836. pStrStart = pszUpperMsg;
  2837. for (i=0; i<iSize; i++)
  2838. {
  2839. MY_ASSERT(i<embeddedInstTokenList.size());
  2840. pTokenElmnt = &embeddedInstTokenList[i];
  2841. pStr = wcsstr(pStrStart, pTokenElmnt->szToken);
  2842. if (pStr != NULL)
  2843. {
  2844. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  2845. repElmnt.len = wcslen(pTokenElmnt->szToken);
  2846. repElmnt.pszReplacementText = pTokenElmnt->szReplacementText;
  2847. replacementList.push_back(repElmnt);
  2848. i--;
  2849. pStrStart = pStr+1;
  2850. }
  2851. else
  2852. {
  2853. pStrStart = pszUpperMsg;
  2854. }
  2855. }
  2856. //
  2857. // Need to look for replacement strings that have not been replaced.
  2858. // Simply search for %EmbeddedCollectedInstance. and find the end % for each
  2859. // Replace them with <null>
  2860. //
  2861. if (!pEmbeddedInstance)
  2862. {
  2863. pStrStart = pszUpperMsg;
  2864. while (TRUE)
  2865. {
  2866. pStr = wcsstr(pStrStart, L"%EMBEDDEDCOLLECTEDINSTANCE.");
  2867. if (pStr != NULL)
  2868. {
  2869. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  2870. pStr2 = pStr;
  2871. while (pStr2++)
  2872. {
  2873. if (*pStr2=='%' || iswspace(*pStr2))
  2874. break;
  2875. }
  2876. if (*pStr2=='%')
  2877. {
  2878. repElmnt.len = (pStr2-pStr)+1;
  2879. repElmnt.pszReplacementText = L"<null>";
  2880. replacementList.push_back(repElmnt);
  2881. }
  2882. pStrStart = pStr+1;
  2883. }
  2884. else
  2885. {
  2886. break;
  2887. }
  2888. }
  2889. }
  2890. }
  2891. iSize = replacementList.size();
  2892. if (iSize != 0)
  2893. {
  2894. //
  2895. // Next, sort the replacement list from the first string to
  2896. // be replaced, to the last. Shell sort, Knuth, Vol13, pg. 84.
  2897. //
  2898. for (int gap=iSize/2; 0<gap; gap/=2)
  2899. {
  2900. for (i=gap; i<iSize; i++)
  2901. {
  2902. for (j=i-gap; 0<=j; j-=gap)
  2903. {
  2904. MY_ASSERT(j+gap<replacementList.size());
  2905. pRepElmnt = &replacementList[j+gap];
  2906. MY_ASSERT(j<replacementList.size());
  2907. pRepElmnt2 = &replacementList[j];
  2908. if (pRepElmnt->pStartStr < pRepElmnt2->pStartStr)
  2909. {
  2910. MY_ASSERT(j<replacementList.size());
  2911. repElmnt = replacementList[j];
  2912. MY_ASSERT(j+gap<replacementList.size());
  2913. replacementList[j] = replacementList[j+gap];
  2914. MY_ASSERT(j+gap<replacementList.size());
  2915. replacementList[j+gap] = repElmnt;
  2916. }
  2917. }
  2918. }
  2919. }
  2920. //
  2921. // Next, figure out the size needed for the Message with
  2922. // everything replaced.
  2923. //
  2924. iSizeNeeded = wcslen(pszMsg)+1;
  2925. iSize = replacementList.size();
  2926. for (i=0; i<iSize; i++)
  2927. {
  2928. MY_ASSERT(i<replacementList.size());
  2929. pRepElmnt = &replacementList[i];
  2930. iSizeNeeded -= pRepElmnt->len;
  2931. iSizeNeeded += wcslen(pRepElmnt->pszReplacementText);
  2932. }
  2933. pszNewMsg = new TCHAR[iSizeNeeded];
  2934. *pszNewMsg = '\0';
  2935. //
  2936. // Next, we loop through and do the actual replacements.
  2937. // "Drive %InstanceName% is full. Currently at %CurrentValue%%."
  2938. //
  2939. pszDest = pszMsg;
  2940. iSize = replacementList.size();
  2941. for (i=0; i<iSize; i++)
  2942. {
  2943. MY_ASSERT(i<replacementList.size());
  2944. pRepElmnt = &replacementList[i];
  2945. *(pRepElmnt->pStartStr) = '\0';
  2946. wcscat(pszNewMsg, pszDest);
  2947. wcscat(pszNewMsg, pRepElmnt->pszReplacementText);
  2948. //XXXWould memcpy be faster??? memcpy(pszDest, source, charCnt*sizeof(TCHAR));
  2949. pszDest = pRepElmnt->pStartStr+pRepElmnt->len;
  2950. }
  2951. wcscat(pszNewMsg, pszDest);
  2952. PutStrProperty(pIRSInstance, L"Message", pszNewMsg);
  2953. delete [] pszNewMsg;
  2954. replacementList.clear();
  2955. }
  2956. else
  2957. {
  2958. PutStrProperty(pIRSInstance, L"Message", pszMsg);
  2959. }
  2960. delete [] pszMsg;
  2961. free(pszUpperMsg);
  2962. // Free up the temporary token list
  2963. iSize = embeddedInstTokenList.size();
  2964. for (i=0; i<iSize; i++)
  2965. {
  2966. MY_ASSERT(i<embeddedInstTokenList.size());
  2967. pTokenElmnt = &embeddedInstTokenList[i];
  2968. if (pTokenElmnt->szToken)
  2969. delete [] pTokenElmnt->szToken;
  2970. if (pTokenElmnt->szOrigToken)
  2971. delete [] pTokenElmnt->szOrigToken;
  2972. if (pTokenElmnt->szReplacementText)
  2973. delete [] pTokenElmnt->szReplacementText;
  2974. }
  2975. embeddedInstTokenList.clear();
  2976. return TRUE;
  2977. }
  2978. #endif
  2979. BOOL CThreshold::Init(void)
  2980. {
  2981. MY_OUTPUT(L"ENTER ***** CThreshold::Init...", 4);
  2982. m_bParentScheduledOut = FALSE;
  2983. m_lNumberNormals = 0;
  2984. m_lNumberWarnings = 0;
  2985. m_lNumberCriticals = 0;
  2986. m_lNumberChanges = 0;
  2987. m_lCompareValue = -99999;
  2988. m_lCurrState = HM_COLLECTING;
  2989. m_lPrevState = HM_COLLECTING;
  2990. m_szGUID = NULL;
  2991. m_szParentObjPath = NULL;
  2992. m_pParentDC = NULL;
  2993. m_szName = NULL;
  2994. m_szDescription = NULL;
  2995. m_szPropertyName = NULL;
  2996. m_szCompareValue = NULL;
  2997. m_szCreationDate = NULL;
  2998. m_szLastUpdate = NULL;
  2999. // m_szMessage = NULL;
  3000. // m_szResetMessage = NULL;
  3001. // m_lID = 0;
  3002. m_bUseAverage = FALSE;
  3003. m_bUseDifference = FALSE;
  3004. m_bUseSum = FALSE;
  3005. m_lTestCondition = 0;
  3006. m_lThresholdDuration = 0;
  3007. m_lViolationToState = 9;
  3008. m_lStartupDelay = 0;
  3009. m_bEnabled = TRUE;
  3010. m_bParentEnabled = TRUE;
  3011. // yyyymmddhhmmss.ssssssXUtc; X = GMT(+ or -), Utc = 3 dig. offset from UTC.")]
  3012. wcscpy(m_szDTTime, m_szDTCurrTime);
  3013. wcscpy(m_szTime, m_szCurrTime);
  3014. MY_OUTPUT(L"EXIT ***** CThreshold::Init...", 4);
  3015. return TRUE;
  3016. }
  3017. BOOL CThreshold::Cleanup(BOOL bSavePrevSettings)
  3018. {
  3019. int i, iSize;
  3020. IRSSTRUCT *pirs;
  3021. MY_OUTPUT(L"ENTER ***** CThreshold::Cleanup...", 4);
  3022. if (bSavePrevSettings == FALSE)
  3023. {
  3024. if (m_szParentObjPath)
  3025. {
  3026. delete [] m_szParentObjPath;
  3027. m_szParentObjPath = NULL;
  3028. }
  3029. }
  3030. if (m_szName)
  3031. {
  3032. delete [] m_szName;
  3033. m_szName = NULL;
  3034. }
  3035. if (m_szDescription)
  3036. {
  3037. delete [] m_szDescription;
  3038. m_szDescription = NULL;
  3039. }
  3040. if (m_szPropertyName)
  3041. {
  3042. delete [] m_szPropertyName;
  3043. m_szPropertyName = NULL;
  3044. }
  3045. if (m_szCompareValue)
  3046. {
  3047. delete [] m_szCompareValue;
  3048. m_szCompareValue = NULL;
  3049. }
  3050. if (m_szCreationDate)
  3051. {
  3052. delete [] m_szCreationDate;
  3053. m_szCreationDate = NULL;
  3054. }
  3055. if (m_szLastUpdate)
  3056. {
  3057. delete [] m_szLastUpdate;
  3058. m_szLastUpdate = NULL;
  3059. }
  3060. // if (m_szMessage)
  3061. // {
  3062. // delete [] m_szMessage;
  3063. // m_szMessage = NULL;
  3064. // }
  3065. // if (m_szResetMessage)
  3066. // {
  3067. // delete [] m_szResetMessage;
  3068. // m_szResetMessage = NULL;
  3069. // }
  3070. if (bSavePrevSettings)
  3071. {
  3072. iSize = m_irsList.size();
  3073. for (i = 0; i < iSize ; i++)
  3074. {
  3075. MY_ASSERT(i<m_irsList.size());
  3076. pirs = &m_irsList[i];
  3077. pirs->lCrossCountTry = 0;
  3078. pirs->fPrevValue = MAX_FLOAT;
  3079. pirs->dPrevValue = MAX_DOUBLE;
  3080. pirs->i64PrevValue = MAX_I64;
  3081. pirs->ui64PrevValue = MAX_UI64;
  3082. pirs->lPrevValue = MAX_LONG;
  3083. pirs->ulPrevValue = MAX_ULONG;
  3084. }
  3085. }
  3086. else
  3087. {
  3088. iSize = m_irsList.size();
  3089. for (i = 0; i < iSize ; i++)
  3090. {
  3091. MY_ASSERT(i<m_irsList.size());
  3092. pirs = &m_irsList[i];
  3093. if (pirs->szInstanceID)
  3094. {
  3095. delete [] pirs->szInstanceID;
  3096. }
  3097. if (pirs->szStatusGUID)
  3098. {
  3099. delete [] pirs->szStatusGUID;
  3100. }
  3101. }
  3102. m_irsList.clear();
  3103. }
  3104. MY_OUTPUT(L"EXIT ***** CThreshold::Cleanup...", 4);
  3105. return TRUE;
  3106. }
  3107. //
  3108. // For when moving from one parent to another
  3109. //
  3110. #ifdef SAVE
  3111. BOOL CThreshold::ModifyAssocForMove(CBase *pNewParentBase)
  3112. {
  3113. HRESULT hRes;
  3114. TCHAR szTemp[1024];
  3115. TCHAR szNewTemp[1024];
  3116. BSTR instName;
  3117. IWbemContext *pCtx = 0;
  3118. IWbemCallResult *pResult = 0;
  3119. IWbemClassObject* pObj = NULL;
  3120. IWbemClassObject* pNewObj = NULL;
  3121. MY_OUTPUT(L"ENTER ***** CDataGroup::ModifyAssocForMove...", 4);
  3122. MY_OUTPUT2(L"m_szGUID=%s", m_szGUID, 4);
  3123. //
  3124. // Figure out the new parent path
  3125. //
  3126. if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3127. ((CDataCollector *)pNewParentBase)->m_deType == HM_EQDE)
  3128. {
  3129. wcscpy(szNewTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_EventQueryDataCollectorConfiguration.GUID=\"");
  3130. }
  3131. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3132. ((CDataCollector *)pNewParentBase)->m_deType == HM_PGDE)
  3133. {
  3134. wcscpy(szNewTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_PolledGetObjectDataCollectorConfiguration.GUID=\"");
  3135. }
  3136. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3137. ((CDataCollector *)pNewParentBase)->m_deType == HM_PMDE)
  3138. {
  3139. wcscpy(szNewTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_PolledMethodDataCollectorConfiguration.GUID=\"");
  3140. }
  3141. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3142. ((CDataCollector *)pNewParentBase)->m_deType == HM_PQDE)
  3143. {
  3144. wcscpy(szNewTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHM_PolledQueryDataCollectorConfiguration.GUID=\"");
  3145. }
  3146. else
  3147. {
  3148. MY_ASSERT(FALSE);
  3149. }
  3150. lstrcat(szNewTemp, pNewParentBase->m_szGUID);
  3151. lstrcat(szNewTemp, L"\"");
  3152. //
  3153. // Delete the association from my parent to me.
  3154. //
  3155. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:MicrosoftHealthMonitor:MicrosoftHM_ThresholdConfiguration.GUID=\\\"");
  3156. lstrcat(szTemp, m_szGUID);
  3157. lstrcat(szTemp, L"\"");
  3158. instName = SysAllocString(L"MicrosoftHM_ConfigurationAssociation");
  3159. if ((hRes = g_pIWbemServices->GetObject(instName, 0L, NULL, &pObj, NULL)) != S_OK)
  3160. {
  3161. MY_HRESASSERT(hRes);
  3162. }
  3163. SysFreeString(instName);
  3164. if (pObj)
  3165. {
  3166. hRes = pObj->SpawnInstance(0, &pNewObj);
  3167. pObj->Release();
  3168. PutStrProperty(pNewObj, L"ChildPath", szTemp);
  3169. PutStrProperty(pNewObj, L"ParentPath", szNewTemp);
  3170. hRes = g_pIWbemServices->PutInstance(pNewObj, 0, NULL, &pResult);
  3171. pNewObj->Release();
  3172. pNewObj = NULL;
  3173. }
  3174. DeleteThresholdConfig(TRUE);
  3175. if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3176. ((CDataCollector *)pNewParentBase)->m_deType == HM_EQDE)
  3177. {
  3178. wcscpy(szNewTemp, L"MicrosoftHM_EventQueryDataCollectorConfiguration.GUID=\\\"");
  3179. }
  3180. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3181. ((CDataCollector *)pNewParentBase)->m_deType == HM_PGDE)
  3182. {
  3183. wcscpy(szNewTemp, L"MicrosoftHM_PolledGetObjectDataCollectorConfiguration.GUID=\\\"");
  3184. }
  3185. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3186. ((CDataCollector *)pNewParentBase)->m_deType == HM_PMDE)
  3187. {
  3188. wcscpy(szNewTemp, L"MicrosoftHM_PolledMethodDataCollectorConfiguration.GUID=\\\"");
  3189. }
  3190. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR &&
  3191. ((CDataCollector *)pNewParentBase)->m_deType == HM_PQDE)
  3192. {
  3193. wcscpy(szNewTemp, L"MicrosoftHM_PolledQueryDataCollectorConfiguration.GUID=\\\"");
  3194. }
  3195. else
  3196. {
  3197. MY_ASSERT(FALSE);
  3198. }
  3199. lstrcat(szNewTemp, pNewParentBase->m_szGUID);
  3200. lstrcat(szNewTemp, L"\\\"");
  3201. if (m_szParentObjPath)
  3202. {
  3203. delete [] m_szParentObjPath;
  3204. }
  3205. m_szParentObjPath = new TCHAR[wcslen(szNewTemp)+1];
  3206. wcscpy(m_szParentObjPath, szNewTemp);
  3207. m_pParentDC = (CDataCollector *)pNewParentBase;
  3208. MY_OUTPUT(L"EXIT ***** CDataGroup::ModifyAssocForMove...", 4);
  3209. return TRUE;
  3210. }
  3211. #endif
  3212. BOOL CThreshold::ReceiveNewChildForMove(CBase *pBase)
  3213. {
  3214. MY_ASSERT(FALSE);
  3215. return FALSE;
  3216. }
  3217. BOOL CThreshold::DeleteChildFromList(LPTSTR pszGUID)
  3218. {
  3219. MY_ASSERT(FALSE);
  3220. return FALSE;
  3221. }
  3222. BOOL CThreshold::DeleteThresholdConfig(BOOL bDeleteAssocOnly)
  3223. {
  3224. HRESULT hRes = S_OK;
  3225. TCHAR szTemp[1024];
  3226. BSTR instName = NULL;
  3227. LPTSTR pszStr = NULL;
  3228. MY_OUTPUT(L"ENTER ***** CThreshold::DeleteThresholdConfig...", 4);
  3229. MY_OUTPUT2(L"m_szGUID=%s", m_szGUID, 4);
  3230. //
  3231. // Delete the association from my parent to me.
  3232. // For some reason, we have to try twice, as we can't count on what will be there.
  3233. //
  3234. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_ThresholdConfiguration.GUID=\\\"");
  3235. lstrcat(szTemp, m_szGUID);
  3236. lstrcat(szTemp, L"\\\"\",ParentPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:");
  3237. lstrcat(szTemp, m_szParentObjPath);
  3238. lstrcat(szTemp, L"\"");
  3239. instName = SysAllocString(szTemp);
  3240. MY_ASSERT(instName); if (!instName) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3241. if ((hRes = g_pIWbemServices->DeleteInstance(instName, 0L, NULL, NULL)) != S_OK)
  3242. {
  3243. SysFreeString(instName);
  3244. instName = NULL;
  3245. wcscpy(szTemp, L"MicrosoftHM_ConfigurationAssociation.ChildPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:MicrosoftHM_ThresholdConfiguration.GUID=\\\"");
  3246. lstrcat(szTemp, m_szGUID);
  3247. lstrcat(szTemp, L"\\\"\",ParentPath=\"\\\\\\\\.\\\\root\\\\cimv2\\\\MicrosoftHealthMonitor:");
  3248. lstrcat(szTemp, L"MicrosoftHM_DataCollectorConfiguration.");
  3249. pszStr = wcsstr(m_szParentObjPath, L"GUID");
  3250. lstrcat(szTemp, pszStr);
  3251. lstrcat(szTemp, L"\"");
  3252. instName = SysAllocString(szTemp);
  3253. MY_ASSERT(instName); if (!instName) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3254. if ((hRes = g_pIWbemServices->DeleteInstance(instName, 0L, NULL, NULL)) != S_OK)
  3255. {
  3256. MY_OUTPUT2(L"Threshold delete failure GUID=%s", instName, 4);
  3257. }
  3258. }
  3259. SysFreeString(instName);
  3260. instName = NULL;
  3261. if (bDeleteAssocOnly)
  3262. {
  3263. return TRUE;
  3264. }
  3265. //
  3266. // Delete our exact instance
  3267. //
  3268. wcscpy(szTemp, L"MicrosoftHM_ThresholdConfiguration.GUID=\"");
  3269. lstrcat(szTemp, m_szGUID);
  3270. lstrcat(szTemp, L"\"");
  3271. instName = SysAllocString(szTemp);
  3272. MY_ASSERT(instName); if (!instName) {hRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3273. if ((hRes = g_pIWbemServices->DeleteInstance(instName, 0L, NULL, NULL)) != S_OK)
  3274. {
  3275. MY_HRESASSERT(hRes);
  3276. MY_OUTPUT2(L"Threshold delete failure GUID=%s", instName, 4);
  3277. }
  3278. SysFreeString(instName);
  3279. instName = NULL;
  3280. //
  3281. // Get rid of any associations to actions for this
  3282. //
  3283. g_pSystem->DeleteAllConfigActionAssoc(m_szGUID);
  3284. MY_OUTPUT(L"EXIT ***** CThreshold::DeleteThresholdConfig...", 4);
  3285. return TRUE;
  3286. error:
  3287. MY_ASSERT(FALSE);
  3288. if (instName)
  3289. SysFreeString(instName);
  3290. Cleanup(FALSE);
  3291. m_bValidLoad = FALSE;
  3292. return FALSE;
  3293. }
  3294. HRESULT CThreshold::Copy(ILIST* pConfigList, LPTSTR pszOldParentGUID, LPTSTR pszNewParentGUID)
  3295. {
  3296. GUID guid;
  3297. TCHAR szTemp[1024];
  3298. TCHAR szNewGUID[1024];
  3299. IWbemClassObject* pInst = NULL;
  3300. IWbemClassObject* pInstCopy = NULL;
  3301. IWbemClassObject* pInstAssocCopy = NULL;
  3302. IWbemClassObject* pObj = NULL;
  3303. HRESULT hRetRes = S_OK;
  3304. BSTR Language = NULL;
  3305. BSTR Query = NULL;
  3306. IEnumWbemClassObject *pEnum;
  3307. ULONG uReturned;
  3308. IWbemContext *pCtx = 0;
  3309. LPTSTR pszParentPath = NULL;
  3310. LPTSTR pszChildPath = NULL;
  3311. LPTSTR pStr = NULL;
  3312. MY_OUTPUT(L"ENTER ***** CThreshold::Copy...", 1);
  3313. if (m_bValidLoad == FALSE)
  3314. return WBEM_E_INVALID_OBJECT;
  3315. //
  3316. // Get the origional starting point HMConfiguration instance.
  3317. //
  3318. wcscpy(szTemp, L"MicrosoftHM_Configuration.GUID=\"");
  3319. lstrcat(szTemp, m_szGUID);
  3320. lstrcat(szTemp, L"\"");
  3321. hRetRes = GetWbemObjectInst(&g_pIWbemServices, szTemp, NULL, &pInst);
  3322. if (!pInst)
  3323. {
  3324. MY_HRESASSERT(hRetRes);
  3325. return hRetRes;
  3326. }
  3327. //
  3328. // Clone the instance, and change the GUID
  3329. //
  3330. hRetRes = pInst->Clone(&pInstCopy);
  3331. if (FAILED(hRetRes))
  3332. {
  3333. MY_HRESASSERT(hRetRes);
  3334. pInst->Release();
  3335. pInst = NULL;
  3336. return hRetRes;
  3337. }
  3338. hRetRes = CoCreateGuid(&guid);
  3339. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3340. StringFromGUID2(guid, szNewGUID, 100);
  3341. hRetRes = PutStrProperty(pInstCopy, L"GUID", szNewGUID);
  3342. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3343. pConfigList->push_back(pInstCopy);
  3344. //
  3345. // Add instance of HMConfigurationAssociation where we are the child,
  3346. // using the parent GUID passed in.
  3347. // Change the GUIDs of both the Parent and Child.
  3348. // also make sure that the machine name is not in the path, and is relative!
  3349. //
  3350. if (pszOldParentGUID != NULL)
  3351. {
  3352. Language = SysAllocString(L"WQL");
  3353. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3354. wcscpy(szTemp, L"REFERENCES OF {MicrosoftHM_Configuration.GUID=\"");
  3355. lstrcat(szTemp, m_szGUID);
  3356. lstrcat(szTemp, L"\"} WHERE ResultClass=MicrosoftHM_ConfigurationAssociation Role=ChildPath");
  3357. Query = SysAllocString(szTemp);
  3358. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3359. // Initialize IEnumWbemClassObject pointer
  3360. pEnum = 0;
  3361. // Issue query
  3362. hRetRes = g_pIWbemServices->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY, 0, &pEnum);
  3363. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3364. SysFreeString(Query);
  3365. Query = NULL;
  3366. SysFreeString(Query);
  3367. Language = NULL;
  3368. // Retrieve object in result set
  3369. pObj = NULL;
  3370. uReturned = 0;
  3371. hRetRes = pEnum->Next(0, 1, &pObj, &uReturned);
  3372. if (uReturned == 0)
  3373. {
  3374. hRetRes = WBEM_E_INVALID_OBJECT_PATH; goto error;
  3375. }
  3376. //
  3377. // Change the GUIDs
  3378. //
  3379. hRetRes = GetStrProperty(pObj, L"ParentPath", &pszParentPath);
  3380. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3381. hRetRes = GetStrProperty(pObj, L"ChildPath", &pszChildPath);
  3382. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3383. pStr = wcschr(pszParentPath, '\"');
  3384. if (pStr)
  3385. {
  3386. pStr++;
  3387. wcsncpy(pStr, pszNewParentGUID, wcslen(pszNewParentGUID));
  3388. }
  3389. else
  3390. {
  3391. hRetRes = WBEM_E_INVALID_OBJECT_PATH; goto error;
  3392. }
  3393. pStr = wcschr(pszChildPath, '\"');
  3394. if (pStr)
  3395. {
  3396. pStr++;
  3397. wcsncpy(pStr, szNewGUID, wcslen(szNewGUID));
  3398. }
  3399. else
  3400. {
  3401. hRetRes = WBEM_E_INVALID_OBJECT_PATH; goto error;
  3402. }
  3403. hRetRes = pObj->Clone(&pInstAssocCopy);
  3404. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3405. hRetRes = PutStrProperty(pInstAssocCopy, L"ParentPath", pszParentPath);
  3406. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3407. hRetRes = PutStrProperty(pInstAssocCopy, L"ChildPath", pszChildPath);
  3408. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3409. pConfigList->push_back(pInstAssocCopy);
  3410. // Release it.
  3411. pObj->Release();
  3412. pObj = NULL;
  3413. pEnum->Release();
  3414. pEnum = NULL;
  3415. delete [] pszParentPath;
  3416. pszParentPath = NULL;
  3417. delete [] pszChildPath;
  3418. pszChildPath = NULL;
  3419. }
  3420. pInst->Release();
  3421. pInst = NULL;
  3422. MY_OUTPUT(L"EXIT ***** CThreshold::Copy...", 1);
  3423. return S_OK;
  3424. error:
  3425. MY_ASSERT(FALSE);
  3426. if (pInst)
  3427. pInst->Release();
  3428. if (pObj)
  3429. pObj->Release();
  3430. if (pEnum)
  3431. pEnum->Release();
  3432. if (Query)
  3433. SysFreeString(Query);
  3434. if (Language)
  3435. SysFreeString(Language);
  3436. if (pszParentPath)
  3437. delete [] pszParentPath;
  3438. if (pszChildPath)
  3439. delete [] pszChildPath;
  3440. Cleanup(FALSE);
  3441. m_bValidLoad = FALSE;
  3442. return hRetRes;
  3443. }
  3444. CBase *CThreshold::FindImediateChildByName(LPTSTR pszName)
  3445. {
  3446. MY_ASSERT(FALSE);
  3447. return NULL;
  3448. }
  3449. BOOL CThreshold::GetNextChildName(LPTSTR pszChildName, LPTSTR pszOutName)
  3450. {
  3451. MY_ASSERT(FALSE);
  3452. return NULL;
  3453. }
  3454. CBase *CThreshold::FindPointerFromName(LPTSTR pszName)
  3455. {
  3456. MY_ASSERT(FALSE);
  3457. return NULL;
  3458. }
  3459. long CThreshold::PassBackStateIfChangedPerInstance(LPTSTR pszInstName)
  3460. {
  3461. int i, iSize;
  3462. IRSSTRUCT *pirs;
  3463. BOOL bFound = FALSE;
  3464. long state = -1;
  3465. iSize = m_irsList.size();
  3466. for (i=0; i<iSize; i++)
  3467. {
  3468. MY_ASSERT(i<m_irsList.size());
  3469. pirs = &m_irsList[i];
  3470. if (!wcscmp(pirs->szInstanceID, pszInstName))
  3471. {
  3472. if (pirs->lPrevState != pirs->lCurrState)
  3473. {
  3474. state = pirs->lCurrState;
  3475. bFound = TRUE;
  3476. break;
  3477. }
  3478. }
  3479. }
  3480. return state;
  3481. }
  3482. long CThreshold::PassBackWorstStatePerInstance(LPTSTR pszInstName)
  3483. {
  3484. int i, iSize;
  3485. IRSSTRUCT *pirs;
  3486. BOOL bFound = FALSE;
  3487. long state = -1;
  3488. iSize = m_irsList.size();
  3489. for (i=0; i<iSize; i++)
  3490. {
  3491. MY_ASSERT(i<m_irsList.size());
  3492. pirs = &m_irsList[i];
  3493. if (!wcscmp(pirs->szInstanceID, pszInstName))
  3494. {
  3495. state = pirs->lCurrState;
  3496. bFound = TRUE;
  3497. break;
  3498. }
  3499. }
  3500. return state;
  3501. }
  3502. BOOL CThreshold::SetPrevState(HM_STATE state)
  3503. {
  3504. int i, iSize;
  3505. IRSSTRUCT *pirs;
  3506. iSize = m_irsList.size();
  3507. for (i = 0; i < iSize ; i++)
  3508. {
  3509. MY_ASSERT(i<m_irsList.size());
  3510. pirs = &m_irsList[i];
  3511. pirs->lCurrState = state;
  3512. pirs->lPrevState = state;
  3513. }
  3514. m_lNumberChanges = 0;
  3515. m_lCurrState = state;
  3516. return TRUE;
  3517. }
  3518. BOOL CThreshold::SendReminderActionIfStateIsSame(IWbemObjectSink* pActionEventSink, IWbemObjectSink* pActionTriggerEventSink, IWbemClassObject* pActionInstance, IWbemClassObject* pActionTriggerInstance, unsigned long ulTriggerStates)
  3519. {
  3520. MY_ASSERT(FALSE);
  3521. return FALSE;
  3522. }
  3523. HRESULT CThreshold::CheckForBadLoad(void)
  3524. {
  3525. HRESULT hRetRes = S_OK;
  3526. IWbemClassObject* pObj = NULL;
  3527. TCHAR szTemp[1024];
  3528. IWbemClassObject* pInstance = NULL;
  3529. if (m_bValidLoad == FALSE)
  3530. {
  3531. wcscpy(szTemp, L"MicrosoftHM_ThresholdConfiguration.GUID=\"");
  3532. lstrcat(szTemp, m_szGUID);
  3533. lstrcat(szTemp, L"\"");
  3534. hRetRes = GetWbemObjectInst(&g_pIWbemServices, szTemp, NULL, &pObj);
  3535. if (!pObj)
  3536. {
  3537. MY_HRESASSERT(hRetRes);
  3538. return S_FALSE;
  3539. }
  3540. hRetRes = LoadInstanceFromMOF(pObj, NULL, L"", TRUE);
  3541. // Here is where we can try and send out a generic SOS if the load failed each time!!!
  3542. if (hRetRes != S_OK)
  3543. {
  3544. if (GetHMThresholdStatusInstance(&pInstance, TRUE) == S_OK)
  3545. {
  3546. mg_TEventList.push_back(pInstance);
  3547. }
  3548. }
  3549. else
  3550. {
  3551. if (GetHMThresholdStatusInstance(&pInstance, TRUE) == S_OK)
  3552. {
  3553. mg_TEventList.push_back(pInstance);
  3554. }
  3555. m_pParentDC->ResetState(TRUE, TRUE);
  3556. }
  3557. MY_HRESASSERT(hRetRes);
  3558. pObj->Release();
  3559. pObj = NULL;
  3560. return hRetRes;
  3561. }
  3562. return S_OK;
  3563. }