[checkmk-commits] Check_MK Git: check_mk: The windows agent is now able to unpack the plugins.cap file upon install.

Andreas Boesl ab at mathias-kettner.de
Mon Feb 2 15:08:28 CET 2015


Module: check_mk
Branch: master
Commit: 68b46e787f0122563b83f96a60e2a44f51da70ea
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=68b46e787f0122563b83f96a60e2a44f51da70ea

Author: Andreas Boesl <ab at mathias-kettner.de>
Date:   Mon Feb  2 15:08:14 2015 +0100

The windows agent is now able to unpack the plugins.cap file upon install.
This file may contain host specific check_mk.ini parameters, as well as
local and plugins scripts.

Conflicts:
	ChangeLog
	agents/windows/build_version
	agents/windows/check_mk_agent.exe
	agents/windows/check_mk_agent.msi
	agents/windows/check_mk_agent.unversioned.exe
	agents/windows/install_agent-64.exe
	agents/windows/install_agent.exe

---

 .werks/1930                                      |   13 +++
 ChangeLog                                        |    1 +
 agents/windows/build_version                     |    2 +-
 agents/windows/check_mk_agent-64.exe             |  Bin 211968 -> 212480 bytes
 agents/windows/check_mk_agent-64.unversioned.exe |  Bin 211968 -> 212480 bytes
 agents/windows/check_mk_agent.cc                 |  115 +++++++++++++++++++++-
 agents/windows/check_mk_agent.exe                |  Bin 180224 -> 181760 bytes
 agents/windows/check_mk_agent.msi                |  Bin 626176 -> 628224 bytes
 agents/windows/check_mk_agent.unversioned.exe    |  Bin 180224 -> 181760 bytes
 agents/windows/install_agent-64.exe              |  Bin 161361 -> 162045 bytes
 agents/windows/install_agent.exe                 |  Bin 158131 -> 158775 bytes
 11 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/.werks/1930 b/.werks/1930
new file mode 100644
index 0000000..a821b41
--- /dev/null
+++ b/.werks/1930
@@ -0,0 +1,13 @@
+Title: Windows agent: now able to unpack plugins.cap file (created by Check_MK agent bakery)
+Level: 1
+Component: checks
+Class: feature
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1422885763
+
+The windows agent is now able to unpack the plugins.cap file upon install.
+This file may contain host specific check_mk.ini parameters, as well as
+local and plugins scripts.
+
diff --git a/ChangeLog b/ChangeLog
index 6ca25b2..2c95d1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -69,6 +69,7 @@
     * 1219 synology_disks, synology_fans, synology_info, synology_raid, synology_status, synology_update: Multiple Synology NAS Checks
     * 1968 qlogic_fcport, qlogic_sanbox, qlogic_sanbox_fabric_element: Supporting SAN Switch Module for IBM BladeCenter(R) now
     * 1220 if,if64: Discovery can now be based on port description...
+    * 1930 Windows agent: now able to unpack plugins.cap file (created by Check_MK agent bakery)...
     * 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 bc6298e..a57f6ce 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-110
+131
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index 0d026c8..1c811db 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 87de9dd..1a1f94b 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 7ef9b17..a7c30a6 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -4885,6 +4885,117 @@ int get_perf_counter_id(const char *counter_name)
     return -1;
 }
 
+void do_unpack_plugins(char *plugin_filename) {
+    snprintf(g_logwatch_statefile, sizeof(g_logwatch_statefile), "%s\\logstate.txt", g_agent_directory);
+
+    FILE *file = fopen(plugin_filename, "rb");
+    if (!file) {
+        printf("Unable to open Check_MK-Agent package %s\n", plugin_filename);
+        exit(1);
+    }
+
+
+    char uninstall_file_path[512];
+    snprintf(uninstall_file_path, 512, "%s\\uninstall_plugins.bat", g_agent_directory);
+    FILE *uninstall_file = fopen(uninstall_file_path, "w");
+    fprintf(uninstall_file, "REM * If you want to uninstall the plugins which were installed during the\n"
+                            "REM * last 'check_mk_agent.exe unpack' command, just execute this script\n\n");
+
+
+    bool had_error = false;
+    while (true) {
+        int   read_bytes;
+        BYTE  filepath_length;
+        int   content_length;
+        BYTE *filepath;
+        BYTE *content;
+
+        // Read Filename
+        read_bytes = fread(&filepath_length, 1, 1, file);
+        if (read_bytes != 1) {
+            if (feof(file))
+                break;
+            else {
+                had_error = true;
+                break;
+            }
+        }
+        filepath = (BYTE *)malloc(filepath_length + 1);
+        read_bytes = fread(filepath, 1, filepath_length, file);
+        filepath[filepath_length] = 0;
+
+        if (read_bytes != filepath_length) {
+            had_error = true;
+            break;
+        }
+
+        // Read Content
+        read_bytes = fread(&content_length, 1, sizeof(content_length), file);
+        if (read_bytes != sizeof(content_length)) {
+            had_error = true;
+            break;
+        }
+
+        // Maximum plugin size is 20 MB
+        if (content_length > 20 * 1024 * 1024) {
+            had_error = true;
+            break;
+        }
+        content = (BYTE *)malloc(content_length);
+        read_bytes = fread(content, 1, content_length, file);
+        if (read_bytes != content_length) {
+            had_error = true;
+            break;
+        }
+
+        // Extract filename and path to file
+        BYTE *filename = NULL;
+        BYTE *dirname  = NULL;
+        for (int i = filepath_length - 1; i >= 0; i--)
+        {
+            if (filepath[i] == '/') {
+                if (filename == NULL) {
+                    filename = filepath + i + 1;
+                    dirname  = filepath;
+                    filepath[i] = 0;
+                }
+                else {
+                    filepath[i] = '\\';
+                }
+            }
+        }
+
+        if (dirname != NULL) {
+            char new_dir[1024];
+            snprintf(new_dir, sizeof(new_dir), "%s\\%s", g_agent_directory, dirname);
+            CreateDirectory(new_dir, NULL);
+        }
+
+        // Add uninstall information for this plugin
+        fprintf(uninstall_file, "del \"%s\\%s\\%s\"\n", g_agent_directory, dirname, filename);
+
+        // Write plugin
+        char plugin_path[512];
+        snprintf(plugin_path, sizeof(plugin_path), "%s\\%s\\%s", g_agent_directory, dirname, filename);
+        FILE *plugin_file = fopen(plugin_path, "wb");
+        fwrite(content, 1, content_length, plugin_file);
+        fclose(plugin_file);
+
+        free(filepath);
+        free(content);
+    }
+
+    fclose(uninstall_file);
+    fclose(file);
+
+    if (had_error) {
+        printf("There was an error on unpacking the Check_MK-Agent package: File integrety is broken\n."
+               "The file might have been installed partially.");
+        exit(1);
+    }
+
+}
+
 int main(int argc, char **argv)
 {
     wsa_startup();
@@ -4898,7 +5009,7 @@ int main(int argc, char **argv)
 
     SetConsoleCtrlHandler((PHANDLER_ROUTINE)ctrl_handler, TRUE);
 
-    if ( ( argc > 2) and  (strcmp(argv[1], "file")) )
+    if ( ( argc > 2) and  (strcmp(argv[1], "file") && strcmp(argv[1], "unpack")) )
         usage();
     else if (argc <= 1)
         RunService();
@@ -4924,6 +5035,8 @@ int main(int argc, char **argv)
         do_install();
     else if (!strcmp(argv[1], "remove"))
         do_remove();
+    else if (!strcmp(argv[1], "unpack"))
+        do_unpack_plugins(argv[2]);
     else if (!strcmp(argv[1], "debug"))
         do_debug();
     else if (!strcmp(argv[1], "version"))
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index 60108a9..d1093b3 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 7db179f..dd96fb7 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 91dfe31..1422526 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 1470dfc..fe99923 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 140ad3f..eac4305 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe differ



More information about the checkmk-commits mailing list