From: <do...@hy...> - 2007-06-06 02:23:28
|
Author: dougm Date: 2007-06-05 19:23:24 -0700 (Tue, 05 Jun 2007) New Revision: 4668 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=4668 Modified: trunk/plugins/system/src/org/hyperic/hq/plugin/system/WindowsDetector.java Log: add auto-discovery option for generic windows services Modified: trunk/plugins/system/src/org/hyperic/hq/plugin/system/WindowsDetector.java =================================================================== --- trunk/plugins/system/src/org/hyperic/hq/plugin/system/WindowsDetector.java 2007-06-05 22:30:20 UTC (rev 4667) +++ trunk/plugins/system/src/org/hyperic/hq/plugin/system/WindowsDetector.java 2007-06-06 02:23:24 UTC (rev 4668) @@ -35,6 +35,7 @@ import org.hyperic.sigar.win32.Service; import org.hyperic.sigar.win32.ServiceConfig; import org.hyperic.sigar.win32.Win32Exception; +import org.hyperic.util.StringUtil; import org.hyperic.util.config.ConfigResponse; import org.hyperic.util.config.EncodingException; @@ -86,6 +87,14 @@ } } + if (!exists) { + if (config.getStartType() == ServiceConfig.START_DISABLED) { + log.debug("Skipping " + serviceName + + ", start type=" + config.getStartTypeString()); + return null; + } + } + String desc = config.getDescription(); if (desc == null) { desc = config.getDisplayName(); @@ -128,6 +137,27 @@ return svc; } + private void discoverWindowsServices(String names, ArrayList services) + throws Win32Exception { + + List serviceNames; + if ("true".equals(names)) { + serviceNames = Service.getServiceNames(); + } + else { + serviceNames = StringUtil.explode(names, ","); + } + + for (int i=0; i<serviceNames.size(); i++) { + String name = (String)serviceNames.get(i); + AIServiceValue svc = + findWindowsService(SystemPlugin.SVC_NAME, name); + if (svc != null) { + services.add(svc); + } + } + } + protected ArrayList getSystemServiceValues(Sigar sigar, ConfigResponse serverConfig) throws SigarException { @@ -154,7 +184,7 @@ services.add(svc); } - //auto-discovery of services + //auto-discovery of services (plugin defined types) Map plugins = getServiceInventoryPlugins(); for (Iterator it = plugins.keySet().iterator(); it.hasNext();) { type = (String)it.next(); @@ -162,9 +192,18 @@ log.debug("Looking for " + type + " service=" + name); AIServiceValue svc = findWindowsService(type, name); - services.add(svc); + if (svc != null) { + services.add(svc); + } } + //auto-discover of any generic windows service + String windowsServices = + getManager().getProperty("windows.services.discover"); + if (windowsServices != null) { + discoverWindowsServices(windowsServices, services); + } + return services; } } |