for writing output into a file
Message-ID: <54816a78.U1s2PqoX6So+91lA%mk(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: d57c9497aa61568f8b90e61259db4d0168d637b8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d57c9497aa6156…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 5 09:18:55 2014 +0100
#1699 Windows agent: new option "file" for writing output into a file
The redirection of the output of the agent via <tt>check_mk_agent test >
filename</tt>
does not work correctly on Windows and misses some of the outputs of check plugins.
Therefore if you want to get the output into a file the simply call the agent as follows:
C+:
C:\Program Files\Check_MK\> <b>check_mk_agent file output.txt</b>
C-:
The output will then be written to the file <tt>output.txt</tt>.
---
.werks/1699 | 17 +++++++++++++++++
ChangeLog | 1 +
agents/windows/check_mk_agent.cc | 37 +++++++++++++++++++++++++++++--------
3 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/.werks/1699 b/.werks/1699
new file mode 100644
index 0000000..e29bb17
--- /dev/null
+++ b/.werks/1699
@@ -0,0 +1,17 @@
+Title: Windows agent: new option "file" for writing output into a file
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417767417
+Class: feature
+
+The redirection of the output of the agent via <tt>check_mk_agent test >
filename</tt>
+does not work correctly on Windows and misses some of the outputs of check plugins.
+Therefore if you want to get the output into a file the simply call the agent as
follows:
+
+C+:
+C:\Program Files\Check_MK\> <b>check_mk_agent file output.txt</b>
+C-:
+
+The output will then be written to the file <tt>output.txt</tt>.
diff --git a/ChangeLog b/ChangeLog
index 2ad9ef1..f9a253e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -56,6 +56,7 @@
* 1645 Added basic kernel section to FreeBSD agent...
* 1597 bluecat_dhcp, bluecat_dns: Checks can now be used in Check_MK Cluster Mode
* 1599 check_mk_agent.aix: Simple run_cached Feature for plugins...
+ * 1699 Windows agent: new option "file" for writing output into a file...
* 1478 FIX: kernel.util, statgrab_cpu: fix computation of utilization...
* 1480 FIX: brocade_vdx_status: disable check on some devices that do not support
it...
* 1485 FIX: dell_om_disks, dell_om_esmlog, dell_om_mem, dell_om_processors,
dell_om_sensors: detect more devices...
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 852fd5b..0abd14c 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -286,6 +286,8 @@ bool verbose_mode = false;
bool g_crash_debug = false;
bool do_tcp = false;
bool force_tcp_output = false; // if true, send socket data immediately
+bool do_file = false;
+static FILE* fileout;
char g_hostname[256];
int g_port = CHECK_MK_AGENT_PORT;
@@ -4375,7 +4377,10 @@ void output(SOCKET &out, const char *format, ...)
}
}
else {
- fwrite(outbuffer, len, 1, stdout);
+ if (do_file)
+ fwrite(outbuffer, len, 1, fileout);
+ else
+ fwrite(outbuffer, len, 1, stdout);
len = 0;
}
}
@@ -4394,12 +4399,13 @@ void output(SOCKET &out, const char *format, ...)
void usage()
{
fprintf(stderr, "Usage: \n"
- "check_mk_agent version -- show version %s and exit\n"
- "check_mk_agent install -- install as Windows NT service
Check_Mk_Agent\n"
- "check_mk_agent remove -- remove Windows NT service\n"
- "check_mk_agent adhoc -- open TCP port %d and answer request until
killed\n"
- "check_mk_agent test -- test output of plugin, do not open TCP
port\n"
- "check_mk_agent debug -- similar to test, but with lots of debug
output\n",
+ "check_mk_agent version -- show version %s and exit\n"
+ "check_mk_agent install -- install as Windows NT service
Check_Mk_Agent\n"
+ "check_mk_agent remove -- remove Windows NT service\n"
+ "check_mk_agent adhoc -- open TCP port %d and answer request
until killed\n"
+ "check_mk_agent test -- test output of plugin, do not open
TCP port\n"
+ "check_mk_agent file FILENAME -- write output of plugin into file, do
not open TCP port\n"
+ "check_mk_agent debug -- similar to test, but with lots of
debug output\n",
check_mk_version, g_port);
exit(1);
}
@@ -4415,6 +4421,7 @@ void do_debug()
output_data(dummy);
}
+
void do_test()
{
do_tcp = false;
@@ -4780,12 +4787,26 @@ int main(int argc, char **argv)
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ctrl_handler, TRUE);
- if (argc > 2)
+ if ( ( argc > 2) and (strcmp(argv[1], "file")) )
usage();
else if (argc <= 1)
RunService();
else if (!strcmp(argv[1], "test"))
do_test();
+ else if (!strcmp(argv[1], "file")) {
+ if (argc < 3) {
+ fprintf(stderr, "Please specify the name of an output file.\n");
+ exit(1);
+ }
+ fileout = fopen(argv[2], "w");
+ if (!fileout) {
+ fprintf(stderr, "Cannot open %s for writing.\n", argv[2]);
+ exit(1);
+ }
+ do_file = true;
+ do_test();
+ fclose(fileout);
+ }
else if (!strcmp(argv[1], "adhoc"))
do_adhoc();
else if (!strcmp(argv[1], "install"))