Module: check_mk
Branch: master
Commit: eedfe432f798918b76d9eb22c8b480bf81464077
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eedfe432f79891…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Jul 31 10:27:04 2014 +0200
#1093 windows agent: performance counter can now be specified by name
It is no longer required to set a performance counter id in the
<tt>check_mk.ini</tt> file
F+:check_mk.ini
[winperf]
counters = 10332:msx_queues
F-:
You can now use the counter name instead
F+:check_mk.ini
[winperf]
counters = MSExchangeTransport Queues:msx_queues
F-:
<b>Note:</b> Keep in mind that this name depends on you system
language.<br>
If available, the windows agent tries to find the counter name in the registry
key.<br>
<tt>SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\Perflib\\CurrentLanguage</tt><br>
<br>
If this key is missing, the english language key is used as fallback<br>
<tt>SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009</tt>
---
.werks/1093 | 28 ++++++
ChangeLog | 2 +
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 207360 -> 208896 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 207360 -> 208896 bytes
agents/windows/check_mk_agent.cc | 105 +++++++++++++++++++---
agents/windows/check_mk_agent.exe | Bin 176640 -> 178176 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 176640 -> 178176 bytes
agents/windows/install_agent-64.exe | Bin 155392 -> 159871 bytes
agents/windows/install_agent.exe | Bin 152452 -> 156784 bytes
10 files changed, 124 insertions(+), 13 deletions(-)
diff --git a/.werks/1093 b/.werks/1093
new file mode 100644
index 0000000..8ead350
--- /dev/null
+++ b/.werks/1093
@@ -0,0 +1,28 @@
+Title: windows agent: performance counter can now be specified by name
+Level: 1
+Component: checks
+Version: 1.2.5i6
+Date: 1406794406
+Class: feature
+
+It is no longer required to set a performance counter id in the
<tt>check_mk.ini</tt> file
+
+F+:check_mk.ini
+[winperf]
+ counters = 10332:msx_queues
+F-:
+
+You can now use the counter name instead
+
+F+:check_mk.ini
+[winperf]
+ counters = MSExchangeTransport Queues:msx_queues
+F-:
+
+<b>Note:</b> Keep in mind that this name depends on you system
language.<br>
+If available, the windows agent tries to find the counter name in the registry
key.<br>
+<tt>SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\Perflib\\CurrentLanguage</tt><br>
+<br>
+If this key is missing, the english language key is used as fallback<br>
+<tt>SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009</tt>
+
diff --git a/ChangeLog b/ChangeLog
index f19e236..997e7a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
* 1065 heartbeat_crm / heartbeat_crm.resources: Rewrote checks / formalized
parameters...
* 0186 touchstone_cable_modem_fec: New Check to monitor the Forward error correction
on touchstone cable modems
* 1068 livedump: Added optional check interval (detect staleness) / option to encrypt
mails...
+ * 1093 windows agent: performance counter can now be specified by name...
* 1051 FIX: tcp_conn_stats: fix missing performance data...
* 1142 FIX: winperf_ts_sessions: fix computation, check has never really worked
* 1090 FIX: zfsget: fixed exception which happened on incomplete zfs entries
@@ -17,6 +18,7 @@
* 1064 FIX: Fixed rare issue with WATO communication in distributed setups (different
OS versions)...
* 1089 FIX: Snapshot restore: fixed exception during exception handling......
* 1091 FIX: logwatch patterns: allow unicode text in pattern comment
+ * 1092 FIX: logwatch: now able to enter unicode text into the "Pattern
(Regex)" field
1.2.5i5:
diff --git a/agents/windows/build_version b/agents/windows/build_version
index b4de394..60d3b2f 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-11
+15
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index d537f7f..7e7f6ed 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 acf90d6..66519d7 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 91e2864..bf03297 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -264,6 +264,7 @@ void close_crash_log();
void crash_log(const char *format, ...);
void lowercase(char* value);
char* next_word(char** line);
+int get_perf_counter_id(const char* counter_name);
// .----------------------------------------------------------------------.
// | ____ _ _ _ |
@@ -3784,19 +3785,31 @@ bool handle_global_config_variable(char *var, char *value)
bool handle_winperf_config_variable(char *var, char *value)
{
if (!strcmp(var, "counters")) {
- char *word;
- while (0 != (word = next_word(&value))) {
- char *colon = strchr(word, ':');
- if (!colon) {
- fprintf(stderr, "Invalid counter '%s' in section [winperf]:
need number and colon, e.g. 238:processor.\n", word);
- exit(1);
- }
- *colon = 0;
- winperf_counter *tmp_counter = new winperf_counter();
- tmp_counter->name = strdup(colon + 1);
- tmp_counter->id = atoi(word);
- g_winperf_counters.push_back(tmp_counter);
+ char *colon = strchr(value, ':');
+ if (!colon) {
+ fprintf(stderr, "Invalid counter '%s' in section [winperf]: need
number(or text) and colon, e.g. 238:processor.\n", value);
+ exit(1);
}
+ *colon = 0;
+ winperf_counter *tmp_counter = new winperf_counter();
+ tmp_counter->name = strdup(colon + 1);
+
+ bool is_digit = true;
+ for (unsigned int i = 0; i < strlen(value); i++)
+ if (!isdigit(value[i])) {
+ is_digit = false;
+ int id = get_perf_counter_id(value);
+ if (id == -1) {
+ fprintf(stderr, "No matching performance counter id found for
%s.\n", value);
+ return false;
+ }
+ tmp_counter->id = id;
+ break;
+ }
+
+ if(is_digit)
+ tmp_counter->id = atoi(value);
+ g_winperf_counters.push_back(tmp_counter);
return true;
}
return false;
@@ -4610,6 +4623,74 @@ void determine_directories()
snprintf(g_logwatch_statefile, sizeof(g_logwatch_statefile),
"%s\\logstate.txt", g_agent_directory);
}
+int get_perf_counter_id(const char *counter_name) {
+
+ HKEY hKey;
+ LONG result;
+ TCHAR szValueName[300000];
+ DWORD dwcbData = sizeof(szValueName);
+
+ // Determine the correct perflib key..
+ // CurrentLanguage first
+ result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\Perflib\\CurrentLanguage", REG_MULTI_SZ, KEY_READ, &hKey);
+ RegQueryValueEx(
+ hKey,
+ "Counter",
+ NULL,
+ NULL,
+ (LPBYTE) szValueName,
+ &dwcbData
+ );
+ RegCloseKey (hKey);
+
+ if (result != ERROR_SUCCESS) // nothing found, try english (009) as fallback
+ {
+ result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009",
REG_MULTI_SZ, KEY_READ, &hKey);
+ RegQueryValueEx(
+ hKey,
+ "Counter",
+ NULL,
+ NULL,
+ (LPBYTE) szValueName,
+ &dwcbData
+ );
+ RegCloseKey (hKey);
+ if (result != ERROR_SUCCESS)
+ {
+ // Unable to open any perflib registry
+ return -1;
+ }
+ }
+
+
+ int length = 0;
+ int last_ctr_id = 0;
+ bool is_name = false;
+ DWORD offset = 0;
+
+ TCHAR* ptr_perf = szValueName;
+ for(;;) {
+ if (offset > dwcbData)
+ 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;
+ }
+ return -1;
+}
+
int main(int argc, char **argv)
{
wsa_startup();
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index e14c863..66fb39b 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.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index fecf7c9..d22914e 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 21f4575..e21840f 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 9093e26..fc24dba 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ