Module: check_mk
Branch: master
Commit: 5741f6cd10519fa165796e63afbd295e7d44af86
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5741f6cd10519f…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Jan 14 12:37:15 2014 +0100
windows_agent: now able to handle the removal of local/plugin scripts during runtime
---
.werks/255 | 11 +++++++++++
ChangeLog | 1 +
agents/windows/check_mk_agent.cc | 24 ++++++++++++++++++++----
3 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/.werks/255 b/.werks/255
new file mode 100644
index 0000000..6183612
--- /dev/null
+++ b/.werks/255
@@ -0,0 +1,11 @@
+Title: windows_agent: now able to handle the removal of local/plugin scripts during
runtime
+Level: 1
+Component: checks
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1389699043
+
+Whenever a script got removed in the windows agents local or plugins directories,
+the agent still tried to call this script, thus resulting in an error message in the
+agent output. This has been fixed. Removed scripts no longer produce agent output.
diff --git a/ChangeLog b/ChangeLog
index 2f8e444..ed475e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -101,6 +101,7 @@
* 0118 FIX: stulz_humidity: Fixed coloring in pnp template...
* 0119 FIX: stulz_humidity: Fixed lower thresholds...
* 0565 FIX: windows_updates: fix for some cases when forced_reboot is not set
+ * 0255 FIX: windows_agent: now able to handle the removal of local/plugin scripts
during runtime...
Multisite:
* 0371 Added log class filter to hostsvcevents view
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 325837a..db67017 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -171,7 +171,8 @@ enum script_type {
};
struct script_container {
- char *path;
+ char *path; // full path with interpreter, cscript, etc.
+ char *script_path; // path of script
int max_age;
int timeout;
int max_retries;
@@ -2414,6 +2415,11 @@ DWORD WINAPI ScriptWorkerThread(LPVOID lpParam)
return 0;
}
+bool script_exists(script_container *cont)
+{
+ DWORD dwAttr = GetFileAttributes(cont->script_path);
+ return !(dwAttr == INVALID_FILE_ATTRIBUTES);
+}
void run_script_container(script_container *cont)
{
@@ -2421,6 +2427,11 @@ void run_script_container(script_container *cont)
(cont->type == LOCAL && !(enabled_sections & SECTION_LOCAL)) )
return;
+ // Return if this script is no longer present
+ // However, the script container is preserved
+ if (!script_exists(cont))
+ return;
+
time_t now = time(0);
if (now - cont->buffer_time >= cont->max_age) {
// Check if the thread within this cont is still collecting data
@@ -2433,6 +2444,7 @@ void run_script_container(script_container *cont)
if (cont->worker_thread != INVALID_HANDLE_VALUE)
CloseHandle(cont->worker_thread);
+
cont->worker_thread = CreateThread(
NULL, // default security attributes
0, // use default stack size
@@ -2443,9 +2455,7 @@ void run_script_container(script_container *cont)
if (cont->execution_mode == SYNC ||
cont->execution_mode == ASYNC && g_default_script_async_execution
== SEQUENTIAL)
- {
WaitForSingleObject(cont->worker_thread, INFINITE);
- }
}
}
@@ -2456,6 +2466,11 @@ void output_external_programs(SOCKET &out, script_type type)
script_container* cont = NULL;
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) {
// Free buffer
@@ -3848,7 +3863,7 @@ void determine_available_scripts(script_type type)
char newpath[512];
// If the path in question is a directory -> continue
DWORD dwAttr = GetFileAttributes(path);
- if(dwAttr != 0xffffffff && (dwAttr &
FILE_ATTRIBUTE_DIRECTORY)) {
+ if(dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr &
FILE_ATTRIBUTE_DIRECTORY)) {
continue;
}
@@ -3860,6 +3875,7 @@ void determine_available_scripts(script_type type)
// create new entry for this program
cont = new script_container();
cont->path = strdup(command);
+ cont->script_path = strdup(path);
cont->buffer_time = 0;
cont->buffer = NULL;
cont->buffer_work = NULL;