Module: check_mk
Branch: master
Commit: 867b26682e87549fd19bca0b17e3738699bc4480
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=867b26682e8754…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed May 13 10:33:02 2015 +0200
#2270 windows agent: now able to add cached information into section headers
The windows agent now expands the section headers of plugin scripts
with cached information, if applicable. For example, if you configure
the windows_udpates plugin to be cached for one day the section header
will now look like
<tt><<<windows_updates:cached(143115035535:86400)>>></tt>
instead of
<tt><<<windows_updates>>></tt>
For more information please have a look at werk #8243.
---
.werks/2270 | 15 ++++++
ChangeLog | 1 +
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 300032 -> 301056 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 300032 -> 301056 bytes
agents/windows/check_mk_agent.cc | 61 ++++++++++++++++++++--
agents/windows/check_mk_agent.exe | Bin 182272 -> 182784 bytes
agents/windows/check_mk_agent.msi | Bin 730624 -> 732160 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 182272 -> 182784 bytes
agents/windows/install_agent-64.exe | Bin 177884 -> 178405 bytes
agents/windows/install_agent.exe | Bin 158985 -> 159355 bytes
11 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/.werks/2270 b/.werks/2270
new file mode 100644
index 0000000..64a6494
--- /dev/null
+++ b/.werks/2270
@@ -0,0 +1,15 @@
+Title: windows agent: now able to add cached information into section headers
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i1
+Date: 1431505595
+Class: feature
+
+The windows agent now expands the section headers of plugin scripts
+with cached information, if applicable. For example, if you configure
+the windows_udpates plugin to be cached for one day the section header
+will now look like
<tt><<<windows_updates:cached(143115035535:86400)>>></tt>
+instead of
<tt><<<windows_updates>>></tt>
+
+For more information please have a look at werk #8243.
diff --git a/ChangeLog b/ChangeLog
index 15bf44d..dc087c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -174,6 +174,7 @@
* 2076 fortigate_cpu_base, fortigate_sessions_base: supports wider range of
models...
* 2227 isc_dhcpd: New agent plugin and check for checking IP address pools of ISC
DHCP-Daemon
* 2252 SEC: mk_logwatch: Fixed mostly uncritical command injection from config...
+ * 2270 windows agent: now able to add cached information into section headers...
* 1457 FIX: logins: new check renamed from "users" check...
NOTE: Please refer to the migration notes!
* 1762 FIX: lnx_thermal: Now ignoring trip points with level 0...
diff --git a/agents/windows/build_version b/agents/windows/build_version
index aaacbe6..a2ecc45 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-142
+154
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index a90a787..ceea0fd 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 72328cc..37e124e 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 103945f..694ea22 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -3041,25 +3041,76 @@ void output_external_programs(SOCKET &out, script_type type)
// Collect and output data
script_containers_t::iterator it_cont = script_containers.begin();
script_container* cont = NULL;
- while (it_cont != script_containers.end()) {
+ while (it_cont != script_containers.end())
+ {
cont = it_cont->second;
if (!script_exists(cont)) {
it_cont++;
continue;
}
- if (cont->type == type) {
- if (cont->status == SCRIPT_FINISHED) {
+ if (cont->type == type)
+ {
+ if (cont->status == SCRIPT_FINISHED)
+ {
// Free buffer
if (cont->buffer != NULL) {
HeapFree(GetProcessHeap(), 0, cont->buffer);
cont->buffer = NULL;
}
- cont->buffer = cont->buffer_work;
+
+ if (cont->max_age == 0)
+ cont->buffer = cont->buffer_work;
+ else
+ {
+ // Determine chache_info text
+ char cache_info[32];
+ snprintf(cache_info, sizeof(cache_info), ":cached(%d:%d)",
(int)cont->buffer_time, cont->max_age);
+ int cache_len = strlen(cache_info) + 1;
+
+ // We need to parse each line and replace any
<<<section>>> with
<<<section:cached(123455678,3600)>>>
+ // Allocate new buffer, process/modify each line of the original
buffer and write it into the new buffer
+ int buffer_heap_size = HeapSize(GetProcessHeap(), 0,
cont->buffer_work);
+ char *cache_buffer = (char*) HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, buffer_heap_size + 1024);
+ int cache_buffer_offset = 0;
+
+ char *line = strtok(cont->buffer_work, "\n");
+ int write_bytes = 0;
+ while (line)
+ {
+ int length = strlen(line);
+ int cr_offset = line[length-1] == '\r' ? 1 : 0;
+ if (length >=8 && (!strncmp(line,
"<<<", 3) && !strncmp(line+length-cr_offset-3,
">>>", 3)))
+ {
+ // The return value of snprintf seems broken (off by 3?).
Great...
+ write_bytes = length - cr_offset - 3 + 1; // length - \r -
<<< + \0
+ snprintf(cache_buffer + cache_buffer_offset, write_bytes,
"%s", line);
+ cache_buffer_offset += write_bytes - 1;
+
+ snprintf(cache_buffer + cache_buffer_offset, cache_len,
cache_info);
+ cache_buffer_offset += cache_len - 1;
+
+ write_bytes = 3 + cr_offset + 1 + 1; // >>> + \r +
\n + \0
+ snprintf(cache_buffer + cache_buffer_offset, write_bytes,
"%s\n", line + length - cr_offset - 3);
+ cache_buffer_offset += write_bytes - 1;
+ }
+ else
+ {
+ write_bytes = length + 1 + 1; // length + \n + \0
+ snprintf(cache_buffer + cache_buffer_offset, write_bytes,
"%s\n", line);
+ cache_buffer_offset += write_bytes - 1;
+ }
+ line = strtok(NULL, "\n");
+ }
+ HeapFree(GetProcessHeap(), 0, cont->buffer_work);
+ cont->buffer = cache_buffer;
+ }
+
cont->buffer_work = NULL;
cont->status = SCRIPT_IDLE;
}
- else if (cont->retry_count < 0 && cont->buffer != NULL) {
+ else if (cont->retry_count < 0 && cont->buffer != NULL)
+ {
// Remove outdated cache entries
HeapFree(GetProcessHeap(), 0, cont->buffer);
cont->buffer = NULL;
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index dd7be26..7d7387a 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 c516b52..fd48c86 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 91d5c9d..f9f47f8 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 8ea1c38..14cc188 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 ea42ae2..02aa8a6 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ