Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.hq.product
Class ServerDetector

java.lang.Object
  extended by org.hyperic.hq.product.GenericPlugin
      extended by org.hyperic.hq.product.ServerDetector
All Implemented Interfaces:
RuntimeDiscoverer
Direct Known Subclasses:
DaemonDetector, PlatformServiceDetector

public abstract class ServerDetector
extends GenericPlugin
implements RuntimeDiscoverer

Encapsulate the know-how to determine all kinds of server-specific information about a single type of server.


Field Summary
protected static java.lang.String AUTOINVENTORY_NAME
           
protected static java.lang.String INSTALLPATH
           
protected static java.lang.String INSTALLPATH_MATCH
           
protected static java.lang.String INSTALLPATH_NOMATCH
           
protected static java.lang.String INVENTORY_ID
           
protected static java.lang.String VERSION_FILE
           
 
Fields inherited from class org.hyperic.hq.product.GenericPlugin
config, FILE_DELIM, FILE_DELIM_ESC, PROP_NAME
 
Constructor Summary
ServerDetector()
           
 
Method Summary
protected  ServerResource createServerResource(java.lang.String installpath)
          Initialize an ServerResource with default values.
protected  ServiceResource createServiceResource(java.lang.String type)
           
 RuntimeResourceReport discoverResources(int serverId, AIPlatformValue platform, ConfigResponse config)
          Deprecated. - Plugins should not use this method.
protected  java.util.List discoverServers(ConfigResponse config)
          Override to discover servers for the server type of the plugin instance.
protected  java.util.List discoverServices(ConfigResponse config)
          Override to discover services for the server type of the plugin instance.
protected  java.util.Set discoverServiceTypes(ConfigResponse config)
           
protected  java.io.File findVersionFile(java.io.File dir, java.util.regex.Pattern pattern)
           
protected  java.lang.String formatAutoInventoryName(java.lang.String type, ConfigResponse parentConfig, ConfigResponse config, ConfigResponse cprops)
          Format the auto-inventory name as defined by the plugin, for example: %value%s are replaced using the ConfigResponse parameters.
protected  java.lang.String formatName(java.lang.String name, ConfigResponse parentConfig, ConfigResponse config, ConfigResponse cprops)
           
protected static java.lang.String getCanonicalPath(java.lang.String installpath)
          Fixup the installpath.
protected  ConfigSchema getConfigSchema(java.lang.String name, int type)
           
 java.lang.String getConnectionProtocol(java.lang.String port)
           
protected  org.w3c.dom.Document getDocument(java.io.File file)
          DocumentBuilder.parse() wrapper
protected  java.lang.String getListenAddress(long port)
           
protected  java.lang.String getListenAddress(java.lang.String port)
           
 AutoinventoryPluginManager getManager()
           
protected static java.lang.String getParentDir(java.lang.String path)
           
protected static java.lang.String getParentDir(java.lang.String path, int levels)
           
protected static long[] getPids(java.lang.String query)
          Wrapper for Sigar's ProcessFinder.find method.
protected static java.lang.String[] getProcArgs(long pid)
          Wrapper for Sigar.getProcArgs which catches SigarException and returns a String[] with length 0 if the SigarException is caught.
protected static java.lang.String getProcCwd(long pid)
          Attempt to get the current working directory of a process.
protected static java.lang.String getProcExe(long pid)
           
protected static java.lang.String getProcExe(long pid, java.lang.String name)
          Attempt to find the absolute name of the process executable.
protected static java.util.List getProcModules(long pid)
          Wrapper for Sigar.getProcModules which catches SigarException and returns a String[] with length 0 if the SigarException is caught.
 java.util.List getRegistryScanKeys()
          Helper for RegistryServerDetector implementors.
 RuntimeDiscoverer getRuntimeDiscoverer()
          Deprecated. - Plugins should not use this method.
 ServerSignature getServerSignature()
          The server signature is defined by plugins in etc/hq-plugin.xml if the plugin implements FileServerDetector or RegistryServerDetector.
 java.util.List getServiceConfigs(java.lang.String type)
           
 java.util.Map getServiceInventoryPlugins()
           
protected static org.hyperic.sigar.SigarProxy getSigar()
           
 java.lang.String getTypeProperty(java.lang.String type, java.lang.String name)
          Get a value defined by a <property> tag in the plugin's hq-plugin.xml, within a <server> or <service> tag for this plugin's type.
protected  java.lang.String getXPathValue(java.io.File file, java.lang.String xpath)
           
protected  java.lang.String getXPathValue(org.w3c.dom.Node node, java.lang.String xpath)
          XPathAPI.eval() wrapper.
 void init(PluginManager manager)
          Called when the plugin is loaded on the server and on the agent side.
protected  boolean isInstallTypeVersion(java.lang.String installpath)
          Test if server type version filters apply: VERSION_FILE - Return true if given file exists within installpath INSTALLPATH_MATCH - Return true if installpath matches given substring INSTALLPATH_NOMATCH - Return false if installpath matches given substring
 boolean isRuntimeDiscoverySupported()
          If plugins do not override discoverServers or discoverServices, returning false here will prevent those methods from being called.
 boolean isSSLPort(java.lang.String port)
           
 boolean isWin32ServiceRunning(java.lang.String name)
           
protected  void setControlConfig(ServerResource server, ConfigResponse config)
          Merge default values from server's control ConfigSchema and saves to ServerResource.setControlConfig.
protected  void setControlConfig(ServiceResource service, ConfigResponse config)
          Merge default values from services's control ConfigSchema and saves to ServiceResource.setControlConfig.
protected  void setCustomProperties(ConfigResponse cprops)
           
protected  void setCustomProperties(ServerResource server, ConfigResponse config)
          Merge default values from server's Custom Properties schema and saves to ServerResource.setCustomProperties.
protected  void setDescription(java.lang.String description)
           
protected  void setMeasurementConfig(ServerResource server, ConfigResponse config)
          Merge default values from server's measurement ConfigSchema and saves to ServerResource.setMeasurementConfig.
protected  void setMeasurementConfig(ServiceResource service, ConfigResponse config)
          Merge default values from service's measurement ConfigSchema and saves to ServiceResource.setMeasurementConfig.
protected  void setProductConfig(ServerResource server, ConfigResponse config)
          Merge default values from server's product ConfigSchema and saves to ServerResource.setProductConfig.
protected  void setProductConfig(ServiceResource service, ConfigResponse config)
          Merge default values from service's product ConfigSchema and saves to ServiceResource.setProductConfig.
 
Methods inherited from class org.hyperic.hq.product.GenericPlugin
adjustClassPath, configure, getAbsoluteFiles, getConfig, getConfig, getConfigSchema, getCustomPropertiesSchema, getCustomPropertiesSchema, getCustomPropertiesSchema, getDefaultInstallPath, getLog, getLogName, getManagerProperty, getName, getPlatformName, getPluginClassName, getPluginData, getPluginProperty, getProductPlugin, getProperties, getScriptExtension, getScriptExtension, getScriptExtension, getTypeInfo, getTypeNameProperty, getTypeNameProperty, getTypeProperties, getTypeProperty, getTypeProperty, isNetStatEnabled, isWin32, openResource, setData, setName, setTypeInfo, shutdown, toFileList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION_FILE

protected static final java.lang.String VERSION_FILE
See Also:
Constant Field Values

INSTALLPATH_MATCH

protected static final java.lang.String INSTALLPATH_MATCH
See Also:
Constant Field Values

INSTALLPATH_NOMATCH

protected static final java.lang.String INSTALLPATH_NOMATCH
See Also:
Constant Field Values

INSTALLPATH

protected static final java.lang.String INSTALLPATH
See Also:
Constant Field Values

INVENTORY_ID

protected static final java.lang.String INVENTORY_ID
See Also:
Constant Field Values

AUTOINVENTORY_NAME

protected static final java.lang.String AUTOINVENTORY_NAME
See Also:
Constant Field Values
Constructor Detail

ServerDetector

public ServerDetector()
Method Detail

getRuntimeDiscoverer

public RuntimeDiscoverer getRuntimeDiscoverer()
Deprecated. - Plugins should not use this method.

See Also:
discoverServers(org.hyperic.util.config.ConfigResponse), discoverServices(org.hyperic.util.config.ConfigResponse)

isRuntimeDiscoverySupported

public boolean isRuntimeDiscoverySupported()
If plugins do not override discoverServers or discoverServices, returning false here will prevent those methods from being called.

Returns:
true by default.

discoverResources

public RuntimeResourceReport discoverResources(int serverId,
                                               AIPlatformValue platform,
                                               ConfigResponse config)
                                        throws PluginException
Deprecated. - Plugins should not use this method.

Description copied from interface: RuntimeDiscoverer
This method is called by the autoinventory code that runs within the agent. It is used to discover resources for a particular server by communicating directly with the server as it is running.

Specified by:
discoverResources in interface RuntimeDiscoverer
Parameters:
serverId - The server ID to use when constructing AIServerValue objects and other resources to put into the RuntimeResourceReport.
platform - The current platform. This should be used when detecting servers on the current platform.
config - The config response to use when querying for resources.
Returns:
A RuntimeResourceReport object that describes the services, groups and other resources that are detected. This method can return null if nothing is detected.
Throws:
PluginException - TODO
See Also:
discoverServers(org.hyperic.util.config.ConfigResponse), discoverServices(org.hyperic.util.config.ConfigResponse), discoverServiceTypes(org.hyperic.util.config.ConfigResponse)

setDescription

protected void setDescription(java.lang.String description)

setCustomProperties

protected void setCustomProperties(ConfigResponse cprops)

discoverServers

protected java.util.List discoverServers(ConfigResponse config)
                                  throws PluginException
Override to discover servers for the server type of the plugin instance. In most cases plugins will override discoverServices rather than this method. The general use of this method is where a plugin FileServerDetector or AutoServerDetector finds the Admin server and this method discovers the managed server nodes. Such plugins include WebLogic, WebSphere and iPlanet.

Parameters:
config - Configuration of the parent server resource.
Returns:
List of type ServerResource
Throws:
PluginException - If an error occured during discovery.
Since:
1.7
See Also:
discoverServices(org.hyperic.util.config.ConfigResponse), ServerResource

discoverServices

protected java.util.List discoverServices(ConfigResponse config)
                                   throws PluginException
Override to discover services for the server type of the plugin instance.

Parameters:
config - Configuration of the parent server resource.
Returns:
List of type ServiceResource.
Throws:
PluginException - If an error occured during discovery.

discoverServiceTypes

protected java.util.Set discoverServiceTypes(ConfigResponse config)
                                      throws PluginException
Throws:
PluginException

init

public void init(PluginManager manager)
          throws PluginException
Description copied from class: GenericPlugin
Called when the plugin is loaded on the server and on the agent side.

Overrides:
init in class GenericPlugin
Parameters:
manager - The plugin manager for this plugin type.
Throws:
PluginException

getManager

public AutoinventoryPluginManager getManager()
Returns:
The plugin manager for this plugin.

getTypeProperty

public java.lang.String getTypeProperty(java.lang.String type,
                                        java.lang.String name)
Description copied from class: GenericPlugin
Get a value defined by a <property> tag in the plugin's hq-plugin.xml, within a <server> or <service> tag for this plugin's type.

Same as: getProperty(type + "." + name);

Overrides:
getTypeProperty in class GenericPlugin

getRegistryScanKeys

public java.util.List getRegistryScanKeys()
Helper for RegistryServerDetector implementors. Gets the scan keys from hq-plugin.xml


getServerSignature

public ServerSignature getServerSignature()
The server signature is defined by plugins in etc/hq-plugin.xml if the plugin implements FileServerDetector or RegistryServerDetector.


findVersionFile

protected java.io.File findVersionFile(java.io.File dir,
                                       java.util.regex.Pattern pattern)

isInstallTypeVersion

protected boolean isInstallTypeVersion(java.lang.String installpath)
Test if server type version filters apply: VERSION_FILE - Return true if given file exists within installpath INSTALLPATH_MATCH - Return true if installpath matches given substring INSTALLPATH_NOMATCH - Return false if installpath matches given substring

Parameters:
installpath - The server instance installpath
Returns:
false installpath does not match type version criteria, true otherwise

createServerResource

protected ServerResource createServerResource(java.lang.String installpath)
Initialize an ServerResource with default values. Defaults are set for:

Parameters:
installpath - Used to set InstallPath and Identifier

createServiceResource

protected ServiceResource createServiceResource(java.lang.String type)
Returns:
ServiceResource with setType(this, type)

formatName

protected java.lang.String formatName(java.lang.String name,
                                      ConfigResponse parentConfig,
                                      ConfigResponse config,
                                      ConfigResponse cprops)

formatAutoInventoryName

protected java.lang.String formatAutoInventoryName(java.lang.String type,
                                                   ConfigResponse parentConfig,
                                                   ConfigResponse config,
                                                   ConfigResponse cprops)
Format the auto-inventory name as defined by the plugin, for example: %value%s are replaced using the ConfigResponse parameters.

Parameters:
type - The resource type name used to lookup AUTOINVENTORY_NAME
parentConfig - The platform or server configuration
config - The server or services configuration
cprops - Custom properties
Returns:
The formatted name or null if AUTOINVENTORY_NAME is not defined for the given resource type name

getParentDir

protected static java.lang.String getParentDir(java.lang.String path)
See Also:
FileUtil.getParentDir(String)

getParentDir

protected static java.lang.String getParentDir(java.lang.String path,
                                               int levels)
See Also:
FileUtil.getParentDir(String, int)

getCanonicalPath

protected static java.lang.String getCanonicalPath(java.lang.String installpath)
Fixup the installpath. Quotes are removed. Canonicalized to removing double slashes, uppercase drive letter, etc.


getSigar

protected static org.hyperic.sigar.SigarProxy getSigar()
Returns:
A SigarProxyCache instance with an expiration time of 10 minutes. The cache is cleared by the plugin manager after all AutoServerDetectors have been run.

getListenAddress

protected java.lang.String getListenAddress(java.lang.String port)

getListenAddress

protected java.lang.String getListenAddress(long port)

getProcArgs

protected static java.lang.String[] getProcArgs(long pid)
Wrapper for Sigar.getProcArgs which catches SigarException and returns a String[] with length 0 if the SigarException is caught.

Parameters:
pid - Process identifier
Returns:
Arguments that were passed to the process.

getProcModules

protected static java.util.List getProcModules(long pid)
Wrapper for Sigar.getProcModules which catches SigarException and returns a String[] with length 0 if the SigarException is caught.

Parameters:
pid - Process identifier

getProcExe

protected static java.lang.String getProcExe(long pid)

getProcExe

protected static java.lang.String getProcExe(long pid,
                                             java.lang.String name)
Attempt to find the absolute name of the process executable. If the name cannot be determined, null is returned.

Parameters:
pid - Process identifier
name - Binary base name to match against
Returns:
The process executable name.

getProcCwd

protected static java.lang.String getProcCwd(long pid)
Attempt to get the current working directory of a process. If the directory cannot be determined, null is returned.

Parameters:
pid - Process identifier
Returns:
The process current working directory.

getPids

protected static long[] getPids(java.lang.String query)
Wrapper for Sigar's ProcessFinder.find method.

Parameters:
query - SIGAR Process Table Query
Returns:
Array of pids that match the query, length == 0 if there were no matches.

isWin32ServiceRunning

public boolean isWin32ServiceRunning(java.lang.String name)
Parameters:
name - The Service name shown in the Windows service panel Properties General tab, not the Display name. For example, "Terminal Services" is the Display name, "TermService" is the Service name that should be used here.
Returns:
true If the service exists and is running, false otherwise.

isSSLPort

public boolean isSSLPort(java.lang.String port)

getConnectionProtocol

public java.lang.String getConnectionProtocol(java.lang.String port)

getDocument

protected org.w3c.dom.Document getDocument(java.io.File file)
                                    throws java.io.IOException
DocumentBuilder.parse() wrapper

Parameters:
file - File to parse
Returns:
parsed Document
Throws:
java.io.IOException - For any exception

getXPathValue

protected java.lang.String getXPathValue(org.w3c.dom.Node node,
                                         java.lang.String xpath)
XPathAPI.eval() wrapper. XPathAPI.eval never returns null, however this wrapper method will return null if XObject.toString().length() == 0

Parameters:
node - Node to search
xpath - XPath string
Returns:
XObject.toString() or null if Exception is caught

getXPathValue

protected java.lang.String getXPathValue(java.io.File file,
                                         java.lang.String xpath)

getConfigSchema

protected ConfigSchema getConfigSchema(java.lang.String name,
                                       int type)

setProductConfig

protected void setProductConfig(ServerResource server,
                                ConfigResponse config)
Merge default values from server's product ConfigSchema and saves to ServerResource.setProductConfig.


setMeasurementConfig

protected void setMeasurementConfig(ServerResource server,
                                    ConfigResponse config)
Merge default values from server's measurement ConfigSchema and saves to ServerResource.setMeasurementConfig.


setCustomProperties

protected void setCustomProperties(ServerResource server,
                                   ConfigResponse config)
Merge default values from server's Custom Properties schema and saves to ServerResource.setCustomProperties.


setControlConfig

protected void setControlConfig(ServerResource server,
                                ConfigResponse config)
Merge default values from server's control ConfigSchema and saves to ServerResource.setControlConfig.


setProductConfig

protected void setProductConfig(ServiceResource service,
                                ConfigResponse config)
Merge default values from service's product ConfigSchema and saves to ServiceResource.setProductConfig.


setMeasurementConfig

protected void setMeasurementConfig(ServiceResource service,
                                    ConfigResponse config)
Merge default values from service's measurement ConfigSchema and saves to ServiceResource.setMeasurementConfig.


setControlConfig

protected void setControlConfig(ServiceResource service,
                                ConfigResponse config)
Merge default values from services's control ConfigSchema and saves to ServiceResource.setControlConfig.


getServiceInventoryPlugins

public java.util.Map getServiceInventoryPlugins()

getServiceConfigs

public java.util.List getServiceConfigs(java.lang.String type)

Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.