Module: check_mk
Branch: master
Commit: 1f4505d084a772556eeec1a69a6cc66681a93513
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1f4505d084a772…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Fri Oct 9 16:06:27 2015 +0200
#2657 FIX windows agent: fixed failure to resolve named performance counters
The problem occured when there were very many performance counters on the system.
---
.werks/2657 | 9 +++
ChangeLog | 1 +
agents/windows/Configuration.cc | 67 +++++++++++-----------
agents/windows/Makefile | 2 +-
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 826368 -> 210944 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 826368 -> 210944 bytes
agents/windows/check_mk_agent.cc | 3 +-
agents/windows/check_mk_agent.exe | Bin 743424 -> 206336 bytes
agents/windows/check_mk_agent.msi | Bin 1827328 -> 665600 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 743424 -> 206336 bytes
agents/windows/install_agent-64.exe | Bin 380165 -> 196415 bytes
agents/windows/install_agent.exe | Bin 370666 -> 191727 bytes
13 files changed, 48 insertions(+), 36 deletions(-)
diff --git a/.werks/2657 b/.werks/2657
new file mode 100644
index 0000000..6e3ef88
--- /dev/null
+++ b/.werks/2657
@@ -0,0 +1,9 @@
+Title: windows agent: fixed failure to resolve named performance counters
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i3
+Date: 1444399470
+Class: fix
+
+The problem occured when there were very many performance counters on the system.
diff --git a/ChangeLog b/ChangeLog
index c21e520..8fee803 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -215,6 +215,7 @@
* 2654 FIX: logwatch: fixed high memory and cpu usage caused by too many
unacknowledged messages...
* 2622 FIX: postfix_mailq: Fixed exception when postfix is installed but not
configured properly
* 2675 FIX: checkpoint_connections checkpoint_packets: Fixed wrong discovered
services on non checkpoint devices
+ * 2657 FIX: windows agent: fixed failure to resolve named performance counters...
Multisite:
* 2385 SEC: Fixed possible reflected XSS on all GUI pages where users can produce
unhandled exceptions...
diff --git a/agents/windows/Configuration.cc b/agents/windows/Configuration.cc
index 5db2c8a..6c32957 100644
--- a/agents/windows/Configuration.cc
+++ b/agents/windows/Configuration.cc
@@ -171,51 +171,52 @@ bool Configuration::handleGlobalConfigVariable(char *var, char
*value)
}
+// retrieve the next line from a multi-sz registry key
+const TCHAR *get_next_multi_sz(const std::vector<TCHAR> &data, size_t
&offset)
+{
+ const TCHAR *next = &data[offset];
+ size_t len = strlen(next);
+ if ((len == 0) || (offset + len > data.size())) {
+ // the second condition would only happen with an invalid registry value but
that's not
+ // unheard of
+ return NULL;
+ } else {
+ offset += len + 1;
+ return next;
+ }
+}
+
+
int Configuration::getCounterIdFromLang(const char *language, const char *counter_name)
{
- HKEY hKey;
- LONG result;
- TCHAR szValueName[300000];
- DWORD dwcbData = sizeof(szValueName);
char regkey[512];
snprintf(regkey, sizeof(regkey), "SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\Perflib\\%s", language);
- result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, REG_MULTI_SZ, KEY_READ,
&hKey);
- RegQueryValueEx(
- hKey,
- "Counter",
- NULL,
- NULL,
- (LPBYTE) szValueName,
- &dwcbData
- );
+ HKEY hKey;
+ LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, REG_MULTI_SZ, KEY_READ,
&hKey);
+
+ // preflight
+ std::vector<TCHAR> szValueName;
+ DWORD dwcbData = 0;
+ RegQueryValueEx(hKey, "Counter", NULL, NULL, (LPBYTE)&szValueName[0],
&dwcbData);
+ szValueName.resize(dwcbData);
+ // actual read op
+ RegQueryValueEx(hKey, "Counter", NULL, NULL, (LPBYTE) &szValueName[0],
&dwcbData);
RegCloseKey (hKey);
if (result != ERROR_SUCCESS) {
return -1;
}
- int length = 0;
- int last_ctr_id = 0;
- bool is_name = false;
- DWORD offset = 0;
-
- TCHAR* ptr_perf = szValueName;
+ size_t offset = 0;
for(;;) {
- if (offset > dwcbData)
+ const TCHAR *id = get_next_multi_sz(szValueName, offset);
+ const TCHAR *name = get_next_multi_sz(szValueName, offset);
+ if ((id == NULL) || (name == NULL)) {
break;
-
- length = strlen(ptr_perf);
- if (length == 0)
- break;
-
- if (is_name && !strcmp(counter_name, ptr_perf))
- return last_ctr_id;
- else
- last_ctr_id = atoi(ptr_perf);
-
- offset = offset + length + 1;
- ptr_perf = szValueName + offset;
- is_name = !is_name;
+ }
+ if (strcmp(name, counter_name) == 0) {
+ return strtol(id, NULL, 10);
+ }
}
return -1;
diff --git a/agents/windows/Makefile b/agents/windows/Makefile
index a9e1eb8..36b3117 100644
--- a/agents/windows/Makefile
+++ b/agents/windows/Makefile
@@ -27,7 +27,7 @@ SHELL = /bin/bash
VERSION = 1.2.7i3
VERSION_DUMMY = @@@@@CHECK_MK_VERSION@@@@@
WINDRES = i686-w64-mingw32-windres
-COPTIONS = -s -O2 -Wall -Werror -static
-DCHECK_MK_VERSION='"$(VERSION_DUMMY)"'
+COPTIONS = -s -O2 -Wall -Werror -static -fno-rtti
-DCHECK_MK_VERSION='"$(VERSION_DUMMY)"'
MKDIR = mkdir -p
ifeq ($(shell uname),Linux)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 5873851..ff5670f 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-467
+481
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index f084614..5173a19 100755
Binary files a/agents/windows/check_mk_agent-64.exe and
b/agents/windows/check_mk_agent-64.exe differ
diff --git a/agents/windows/check_mk_agent-64.unversioned.exe
b/agents/windows/check_mk_agent-64.unversioned.exe
index beb4cbe..7ddefd1 100755
Binary files a/agents/windows/check_mk_agent-64.unversioned.exe and
b/agents/windows/check_mk_agent-64.unversioned.exe differ
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index d23ed23..6635814 100644
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -832,8 +832,9 @@ void section_winperf(SOCKET &out)
// also output additionally configured counters
for (winperf_counters_t::const_iterator it_wp =
g_config->winperfCounters().begin();
- it_wp != g_config->winperfCounters().end(); ++it_wp)
+ it_wp != g_config->winperfCounters().end(); ++it_wp) {
dump_performance_counters(out, (*it_wp)->id, (*it_wp)->name);
+ }
}
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index c807ed5..a25cd30 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/check_mk_agent.msi b/agents/windows/check_mk_agent.msi
index 42340c5..c188732 100755
Binary files a/agents/windows/check_mk_agent.msi and b/agents/windows/check_mk_agent.msi
differ
diff --git a/agents/windows/check_mk_agent.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index 6c1907a..61fd4c0 100755
Binary files a/agents/windows/check_mk_agent.unversioned.exe and
b/agents/windows/check_mk_agent.unversioned.exe differ
diff --git a/agents/windows/install_agent-64.exe b/agents/windows/install_agent-64.exe
index 988b428..0510833 100755
Binary files a/agents/windows/install_agent-64.exe and
b/agents/windows/install_agent-64.exe differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index 0040c28..6110f96 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ