diff options
author | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2022-07-12 12:11:06 +0300 |
---|---|---|
committer | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2022-07-12 12:13:06 +0300 |
commit | 1bbe355cb8f454e001a14afd09175e7f601e1ec0 (patch) | |
tree | c17ded392f9519558a551600d6ffd0ac9630a49d | |
parent | 1a99963025bcc81a7234b350c91e5abd2755d29e (diff) |
...G...... [ZBX-19001] fixed wmi.getall[] and wmi.get[] to report invalid queries
Merge in ZBX/zabbix from feature/ZBX-19001-5.0 to release/5.0
* commit 'fdd711474806626819d6d6da45a7c6f12fcd75c8':
...G...... [ZBX-19001] fixed wmi.getall[] error reporting in case of failed error retrieval and removed redundant initialization
.D........ [ZBX-19001] added ChangeLog entry
...G...... [ZBX-19001] fixed wmi.getall[] to report invalid queries
...G...... [ZBX-19001] fixed wmi.getall[] to report invalid queries
(cherry picked from commit 98a783cbd6101bc06c67439d3389853aeed04abe)
-rw-r--r-- | ChangeLog.d/bugfix/ZBX-19001 | 1 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/win32/wmi.cpp | 54 |
2 files changed, 53 insertions, 2 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-19001 b/ChangeLog.d/bugfix/ZBX-19001 new file mode 100644 index 00000000000..44abbcda187 --- /dev/null +++ b/ChangeLog.d/bugfix/ZBX-19001 @@ -0,0 +1 @@ +...G...... [ZBX-19001] fixed wmi.getall[] and wmi.get[] to report invalid queries (vso) diff --git a/src/libs/zbxsysinfo/win32/wmi.cpp b/src/libs/zbxsysinfo/win32/wmi.cpp index ed3578bbea9..598a1df2724 100644 --- a/src/libs/zbxsysinfo/win32/wmi.cpp +++ b/src/libs/zbxsysinfo/win32/wmi.cpp @@ -112,6 +112,44 @@ extern "C" void zbx_co_uninitialize() CoUninitialize(); } +extern "C" static void get_error_code_text(HRESULT hres, char **error) +{ + IWbemStatusCodeText *pStatus = NULL; + SCODE sc; + + sc = CoCreateInstance(CLSID_WbemStatusCodeText, 0, CLSCTX_INPROC_SERVER, IID_IWbemStatusCodeText, + (LPVOID *) &pStatus); + + if(S_OK == sc) + { + BSTR bstr = 0; + + sc = pStatus->GetErrorCodeText(hres, 0, 0, &bstr); + if (S_OK == sc) + { + *error = zbx_unicode_to_utf8((wchar_t *)bstr); + zbx_rtrim(*error, "\n\r"); + SysFreeString(bstr); + } + else + { + *error = zbx_dsprintf(*error, "error code:" ZBX_FS_I64, hres); + zabbix_log(LOG_LEVEL_DEBUG, "GetErrorCodeText() failed with code:" ZBX_FS_I64 " when retrieving error" + " code for " ZBX_FS_I64, sc, hres); + } + pStatus->Release(); + } + else + { + *error = zbx_dsprintf(*error, "error code:" ZBX_FS_I64, hres); + zabbix_log(LOG_LEVEL_DEBUG, "CoCreateInstance() failed with code:" ZBX_FS_I64 " when retrieving error code" + " for:" ZBX_FS_I64, sc, hres); + } + + if (NULL != pStatus) + pStatus->Release(); +} + /****************************************************************************** * * * Purpose: extract only one value from the search result * @@ -147,7 +185,13 @@ extern "C" static int parse_first_first(IEnumWbemClassObject *pEnumerator, doubl goto out2; } - if (FAILED(hres) || 0 == uReturn) + if (FAILED(hres)) + { + get_error_code_text(hres, error); + goto out2; + } + + if (0 == uReturn) goto out2; hres = pclsObj->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY); @@ -229,7 +273,13 @@ extern "C" static int parse_all(IEnumWbemClassObject *pEnumerator, double timeou if (WBEM_S_FALSE == hres && 0 == uReturn) return SYSINFO_RET_OK; - if (FAILED(hres) || 0 == uReturn) + if (FAILED(hres)) + { + get_error_code_text(hres, error); + return ret; + } + + if (0 == uReturn) return ret; hres = pclsObj->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY); |