Control Plugins
Topics marked with * relate to HQ Enterprise-only features.
The ControlPlugin defines control actions and implements the doAction() method used to control resources. Like the Measurement Plugin, the method of control is left entirely to the plugin. Support classes are provided to assist with certain types of control:
- JDBC
- JMX
- Script Execution
- Windows Service Manager
Following are some examples of collection methods used by various plugins:
| Collection Method | Plugins that Use It |
|---|---|
| JMX | JBoss, WebLogic, WebSphere |
| JDBC | Mysql, PostgreSQL |
| Script Execution | Apache, Tomcat |
| Windows Service Manager | IIS, Apache, Tomcat |
Feedback is welcome. Click Add Comment at the bottom of the page.
Properties
| Property | Use | |
|---|---|---|
| BACKGROUND_COMMAND | background.sh command silently fails when running | |
| DEFAULT_PROGRAM | default control program |
Script Execution
... <server name="Zope" version="2.x"> ... <!-- Use this helper class --> <plugin type="control" class="org.hyperic.hq.product.ScriptControlPlugin"/> ... <!-- default script, visible and configurable in UI --> <property name="DEFAULT_PROGRAM" value="zopectl"/> ... <!-- Actions visible in UI--> <actions include="start,restart,stop,kill,status,test"/> ... </server>
Windows Service Manager
Code snippet with the required code to run Control Actions on a Windows Service.
Always specify the platform (platform="Win32") if you use a common plugin for Unix/Windows platforms.
<!-- Use this helper class for your Control Actions --> <plugin type="control" platform="Win32" class="org.hyperic.hq.product.Win32ControlPlugin"/> <!-- Actions are only valid on Windows platforms --> <actions platform="Win32" include="start,stop,restart"/> <!-- Specify service name as a configurable option and setting the default value--> <config type="control" platform="Win32"> <option name="service_name" default="Apache2" description="Apache Service Name"/>
ControlPlugin.doAction Method
Control actions are defined in the Plugin XML Descriptor. Server and Service resources can include an <actions> tag that will define the control actions that resource supports. Multiple control actions can be defined by separating the actions with a comma. For example:
<actions include="start,stop,restart"/>
These actions are passed into doAction as a String argument. The plugin can then act accordingly. Each resource that supports control will have its own ControlPlugin instance. Configuration parameters defined within the Plugin XML Descriptor <config> tags can be retrieved using the ControlPlugin.getConfig method.
An example using a JBoss JMS Destination, which uses JMX for its control actions:
<!-- ObjectName properties used in the control plugins --> <property name="JMSQueue" value="jboss.mq.destination:service=Queue,name=%jms.destination%"/> ... <service name="JMS Destination"> <config> <option name="jms.destination" description="JMS Destination" default=""/> </config> <actions include="removeAllMessages"/> ... </service> ...
public class JBossJMSControlPlugin extends ControlPlugin { public void doAction(String action) throws PluginException { // ObjectName to invoke the method on String oName = getProperty("JMSQueue"); //From hq-plugin.xml try { ... // Get a reference to the MBeanServer mBeanServer.invoke(oName, action, new Object[0], new String[0]); ... } catch (Exception e) { throw new PluginException("Unable to invoke method '" + action + "'", e); } } }
Comments (5)
Feb 04, 2009
Shrinidhi Shastri says:
Does the Script Execution Control plugin allow us to configure two control progr...Does the Script Execution Control plugin allow us to configure two control programs, for example, one for Start and one for Stop. I have an application which I want to control but has a separate script for starting and stopping the application.
– EDIT –
By the way, I am using XML form of plugin deployment.
Feb 04, 2009
Mirko Pluhar says:
Hi, sorry but you can only configure one control program. What do you think abo...Hi,
sorry but you can only configure one control program. What do you think about using a wrapper that executes your scripts ?
Cheers,
Mirko
Feb 04, 2009
Shrinidhi Shastri says:
Yea. Thats what I am planning to do. Thanks for replying.Yea. Thats what I am planning to do. Thanks for replying.
Feb 05, 2009
Mirko Pluhar says:
Great, please use the forums (http://forums.hyperic.com) if there are any upcomi...Great, please use the forums (http://forums.hyperic.com) if there are any upcoming questions about implementing your Control Actions.
Cheers,
Mirko
Apr 30, 2009
BJ Chippindale says:
A short context of how the "action" string gets invoked might be helpful. Especi...A short context of how the "action" string gets invoked might be helpful. Especially of interest would be how to nest plugins such that a supporting plugin might be invoked by another such. e.g. If a measurement plugin (which is not simple) needs information to be refreshed, how might IT pass this string to a control plugin?