Module: check_mk
Branch: master
Commit: 1cd1e5931a0f55e18773c380f16f4a43131dc064
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1cd1e5931a0f55…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Nov 15 14:23:57 2011 +0100
Windows agent: <<<df>>> output junctions now
Other people call them "mount points".
---
ChangeLog | 2 +
agents/windows/check_mk.ini | 2 +-
agents/windows/check_mk_agent.cc | 99 +++++++++++++++++++++++++++++--------
agents/windows/check_mk_agent.exe | Bin 100864 -> 101376 bytes
4 files changed, 81 insertions(+), 22 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6e6882e..f7e5d73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,8 @@
<<<local>>>
* Windows agent: agent now reuses TCP port even when taskkill'ed, so
a system reboot is (hopefully) not neccessary anymore
+ * Windows agent: section <<<df>>> now also outputs junctions
(windows
+ mount points). No external plugin is needed.
* logwatch: allow to classify messages based on their count (see
man page of logwatch for details)
diff --git a/agents/windows/check_mk.ini b/agents/windows/check_mk.ini
index 9c02959..e208b6e 100644
--- a/agents/windows/check_mk.ini
+++ b/agents/windows/check_mk.ini
@@ -7,7 +7,7 @@
# host = winsrv* zab???ad
# Just output certain sections (e.g. for upper hosts)
- # sections = check_mk local mrpe
+ # sections = check_mk df
[winperf]
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 421c2b1..7717858 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -302,6 +302,15 @@ char *strip(char *s)
return lstrip(s);
}
+void char_replace(char what, char into, char *in)
+{
+ while (*in) {
+ if (*in == what)
+ *in = into;
+ in++;
+ }
+}
+
// .----------------------------------------------------------------------.
// | ______ _ _ _ ______ |
// | / / / /___ _ _ ___| |_ ___ _ __ ___ | |_(_)_ __ ___ ___\ \ \ \ |
@@ -348,6 +357,54 @@ void section_uptime(SOCKET &out)
// | |
// '----------------------------------------------------------------------'
+void df_output_filesystem(SOCKET &out, char *volid)
+{
+ TCHAR fsname[128];
+ TCHAR volume[512];
+ DWORD dwSysFlags = 0;
+ if (!GetVolumeInformation(volid, volume, sizeof(volume), 0, 0, &dwSysFlags,
fsname, sizeof(fsname)))
+ fsname[0] = 0;
+
+ ULARGE_INTEGER free_avail, total, free;
+ free_avail.QuadPart = 0;
+ total.QuadPart = 0;
+ free.QuadPart = 0;
+ int returnvalue = GetDiskFreeSpaceEx(volid, &free_avail, &total, &free);
+ if (returnvalue > 0) {
+ double perc_used = 0;
+ if (total.QuadPart > 0)
+ perc_used = 100 - (100 * free_avail.QuadPart / total.QuadPart);
+
+ if (volume[0]) // have a volume name
+ char_replace(' ', '_', volume);
+ else
+ strncpy(volume, volid, sizeof(volume));
+
+ output(out, "%s %s ", volume, fsname);
+ output(out, "%s ", llu_to_string(total.QuadPart / KiloByte));
+ output(out, "%s ", llu_to_string((total.QuadPart - free_avail.QuadPart)
/ KiloByte));
+ output(out, "%s ", llu_to_string(free_avail.QuadPart / KiloByte));
+ output(out, "%3.0f%% ", perc_used);
+ output(out, "%s\n", volid);
+ }
+}
+
+void df_output_mountpoints(SOCKET &out, char *volid)
+{
+ char mountpoint[512];
+ HANDLE hPt = FindFirstVolumeMountPoint(volid, mountpoint, sizeof(mountpoint));
+ if (hPt != INVALID_HANDLE_VALUE) {
+ while (true) {
+ TCHAR combined_path[1024];
+ snprintf(combined_path, sizeof(combined_path), "%s%s", volid,
mountpoint);
+ df_output_filesystem(out, combined_path);
+ if (!FindNextVolumeMountPoint(hPt, mountpoint, sizeof(mountpoint)))
+ break;
+ }
+ FindVolumeMountPointClose(hPt);
+ }
+}
+
void section_df(SOCKET &out)
{
output(out, "<<<df>>>\n");
@@ -360,30 +417,30 @@ void section_df(SOCKET &out)
UINT drvType = GetDriveType(drive);
if (drvType == DRIVE_FIXED) // only process local harddisks
{
- ULARGE_INTEGER free_avail, total, free;
- free_avail.QuadPart = 0;
- total.QuadPart = 0;
- free.QuadPart = 0;
- int returnvalue = GetDiskFreeSpaceEx(drive, &free_avail, &total,
&free);
- if (returnvalue > 0) {
- double perc_used = 0;
- if (total.QuadPart > 0)
- perc_used = 100 - (100 * free_avail.QuadPart / total.QuadPart);
-
- TCHAR fsname[128];
- if (!GetVolumeInformation(drive, 0, 0, 0, 0, 0, fsname, 128))
- fsname[0] = 0;
-
- output(out, "%-10s %-8s ", drive, fsname);
- output(out, "%s ", llu_to_string(total.QuadPart / KiloByte));
- output(out, "%s ", llu_to_string((total.QuadPart - free_avail.QuadPart) /
KiloByte));
- output(out, "%s ", llu_to_string(free_avail.QuadPart / KiloByte));
- output(out, "%3.0f%% ", perc_used);
- output(out, "%s\n", drive);
- }
+ df_output_filesystem(out, drive);
+ df_output_mountpoints(out, drive);
}
drive += strlen(drive) + 1;
}
+
+ // Output volumes, that have no drive letter. The following code
+ // works, but then we have no information about the drive letters.
+ // And if we run both, then volumes are printed twice. So currently
+ // we output only fixed drives and mount points below those fixed
+ // drives.
+
+ // HANDLE hVolume;
+ // char volid[512];
+ // hVolume = FindFirstVolume(volid, sizeof(volid));
+ // if (hVolume != INVALID_HANDLE_VALUE) {
+ // df_output_filesystem(out, volid);
+ // while (true) {
+ // // df_output_mountpoints(out, volid);
+ // if (!FindNextVolume(hVolume, volid, sizeof(volid)))
+ // break;
+ // }
+ // FindVolumeClose(hVolume);
+ // }
}
// .----------------------------------------------------------------------.
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index 6d3b019..19d8e36 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ