Module: check_mk
Branch: master
Commit: 62ab8e9cd73ca893f774c24f16f426374b08546a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62ab8e9cd73ca8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Aug 11 18:29:15 2011 +0200
Windows: agent now also sends start type
Check has been adapted to parse new and old style output
---
ChangeLog | 1 +
agents/windows/check_mk_agent.cc | 44 +++++++++++++++++++++++++++++++-
agents/windows/check_mk_agent.exe | Bin 96768 -> 96768 bytes
agents/windows/crash.exe | Bin 20024 -> 20024 bytes
checks/services | 50 +++++++++++++++++++++++++------------
5 files changed, 77 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ee3123d..54e08ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -48,6 +48,7 @@
* New checks netapp_cluster, netapp_vfiler for checking NetAPP filer
running as cluster or running vfilers.
* megaraid_pdisks: Better handling of MegaCli output (Thanks to Bastian Kuhn)
+ * Windows: agent now also sends start type (auto/demand/disabled/boot/system)
Multisite:
* FIX: make non-Ascii characters in services names work again
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 9b77d34..67689cc 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -308,6 +308,44 @@ void section_ps(SOCKET &out)
}
+// Determine the start type of a service. Unbelievable how much
+// code is needed for that...
+const char *service_start_type(SC_HANDLE scm, LPCTSTR service_name)
+{
+ // Query the start type of the service
+ const char *start_type = "invalid1";
+ SC_HANDLE schService;
+ LPQUERY_SERVICE_CONFIG lpsc;
+ schService = OpenService(scm, service_name, SERVICE_QUERY_CONFIG);
+ if (schService) {
+ start_type = "invalid2";
+ DWORD dwBytesNeeded, cbBufSize;
+ if (!QueryServiceConfig(schService, NULL, 0, &dwBytesNeeded)) {
+ start_type = "invalid3";
+ DWORD dwError = GetLastError();
+ if (dwError == ERROR_INSUFFICIENT_BUFFER) {
+ start_type = "invalid4";
+ cbBufSize = dwBytesNeeded;
+ lpsc = (LPQUERY_SERVICE_CONFIG) LocalAlloc(LMEM_FIXED, cbBufSize);
+ if (QueryServiceConfig(schService, lpsc, cbBufSize, &dwBytesNeeded))
{
+ switch (lpsc->dwStartType) {
+ case SERVICE_AUTO_START: start_type = "auto"; break;
+ case SERVICE_BOOT_START: start_type = "boot"; break;
+ case SERVICE_DEMAND_START: start_type = "demand"; break;
+ case SERVICE_DISABLED: start_type = "disabled"; break;
+ case SERVICE_SYSTEM_START: start_type = "system"; break;
+ default: start_type = "other";
+ }
+ }
+ LocalFree(lpsc);
+ }
+ }
+ CloseServiceHandle(schService);
+ }
+ return start_type;
+}
+
+
void section_services(SOCKET &out)
{
output(out, "<<<services>>>\n");
@@ -338,6 +376,8 @@ void section_services(SOCKET &out)
case SERVICE_STOP_PENDING: state_name = "stopping"; break;
case SERVICE_STOPPED: state_name = "stopped"; break;
}
+
+ const char *start_type = service_start_type(scm,
service->lpServiceName);
// The service name usually does not contain spaces. But
// in some cases it does. We replace them with _ in order
@@ -348,8 +388,8 @@ void section_services(SOCKET &out)
*w = '_';
}
- output(out, "%-18s %-8s %s\n",
- service->lpServiceName, state_name,
+ output(out, "%s %s/%s %s\n",
+ service->lpServiceName, state_name, start_type,
service->lpDisplayName);
service ++;
}
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index e30b479..bce338b 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/crash.exe b/agents/windows/crash.exe
index 085c008..7cef11e 100755
Binary files a/agents/windows/crash.exe and b/agents/windows/crash.exe differ
diff --git a/checks/services b/checks/services
index 6a12685..f88824f 100644
--- a/checks/services
+++ b/checks/services
@@ -25,7 +25,22 @@
# Boston, MA 02110-1301 USA.
-# List all services to auto-detect here:
+# Output of old agent (< 1.1.10i2):
+# AeLookupSvc running Application Experience Lookup Service
+# Alerter stopped Alerter
+# ALG stopped Application Layer Gateway Service
+# AppMgmt stopped Application Management
+# appmgr running Remote Server Manager
+
+# Output of new agent (>= 1.1.10i2):
+# Alerter stopped/disabled Warndienst
+# ALG running/demand Gatewaydienst auf Anwendungsebene
+# Apple_Mobile_Device running/auto Apple Mobile Device
+# AppMgmt stopped/demand Anwendungsverwaltung
+# AudioSrv running/auto Windows Audio
+# BITS running/demand Intelligenter Hintergrund<FC>bertragungsdienst
+# Bonjour_Service running/auto Dienst "Bonjour"
+
inventory_services = []
def check_windows_services(item, params, info):
@@ -37,33 +52,36 @@ def check_windows_services(item, params, info):
for line in info:
name = line[0]
if name == item:
- state = line[1]
+ # newer agents also send start type as part of state,
+ # e.g. running/auto
+ if '/' in line[1]:
+ state, start_type = line[1].split('/')
+ else:
+ state = line[1]
+ start_type = "unknown"
+
displayname = " ".join(line[2:])
if state == 'running':
- return (0, "OK - running: %s" % displayname)
+ return (0, "OK - running (start type is %s): %s" % (start_type,
displayname))
worststate = state
+ worst_start_type = start_type
if worststate:
- return (2, "CRITICAL - %s: %s" % (worststate, displayname))
+ return (2, "CRITICAL - %s (start type is %s): %s" % (worststate,
worst_start_type, displayname))
else:
return (3, "UNKNOWN - service not found")
-# AeLookupSvc running Application Experience Lookup Service
-# Alerter stopped Alerter
-# ALG stopped Application Layer Gateway Service
-# AppMgmt stopped Application Management
-# appmgr running Remote Server Manager
-# aspnet_state stopped
ASP.NET State Service
-# AudioSrv running Windows Audio
-# BITS stopped Background Intelligent Transfer Service
-# Browser running Computer Browser
-# cimlistener running IBM Director CIM Listener
+
def inventory_windows_services(checkname, info):
inventory = []
for line in info:
name = line[0]
- state = line[1]
+ if '/' in line[1]:
+ state, start_type = line[1].split('/')
+ else:
+ state = line[1]
+ start_type = "unknown"
if state == 'running' and name in inventory_services:
- inventory.append((name, '""', None))
+ inventory.append((name, None))
return inventory