I got it working. Really thank you for your help.
Here the solution:
In the .xml you have to add
<property name="template-config" value="myValue=%myValue%,myUrl=%myUrl%,myTimeout=%myTimeout%,description=%description"/>
and a filter:
<filter name="template"
value="myServer:Type=Server:${query}"/>
then in getValue(Metric metric)
you will get the properties by:
metric.getProperties().getProperty("myValue");
Here my full example:
######################################################
<?xml version="1.0"?>
<plugin package="com.citytechinc.articles.hyperic.plugin">
<property name="template-config"
value="myValue=%myValue%,myUrl=%myUrl%,myTimeout=%myTimeout%,description=%description"/>
<filter name="template"
value="myServer:Type=Server:${query}"/>
<server name="MyAutoDiscoverServer2" version="1.1c" platforms="Unix,Win32">
<plugin type="autoinventory" class="MyAutoDiscoveryServerDetector"/>
<plugin type="measurement" class="MyAutoDiscoveryServerMeasurementPlugin"/>
<config>
<option name="myUrl"
description="Enter the URL for this resource"
default="http://127.0.0.1"/>
<option name="description"
description="Enter the description for this plug-in"
default="Default My Auto Discovery Description"/>
<option name="myTimeout"
description="Timeout for something in My plug-in"
default="0"/>
<option name="myValue"
description="A value for metric"
default="10"/>
</config>
<filter name="template"
value="myServer:Type=Server:${query}"/>
<metric name="Availability"
alias="Availability"
template="system.avail:Type=Platform:Availability"
category="AVAILABILITY"
indicator="true"
collectionType="dynamic"
units="percentage"/>
<metric name="Value"
alias="Value"
template="MyPlugin:Type=Value:Value"
category="UTILIZATION"
indicator="true"
collectionType="dynamic"
units="none"/>
</server>
</plugin>
########################################################
########################################################
public class MyAutoDiscoveryServerMeasurementPlugin extends MeasurementPlugin{
public MetricValue getValue(Metric metric) throws PluginException, MetricNotFoundException, MetricUnreachableException {
Properties propsObject = metric.getObjectProperties();
String type = propsObject.getProperty("Type");
if(type.equals("Platform"))
return new MetricValue(Metric.AVAIL_UP);
else if(type.equals("Value"))
{
printDebugInfos(metric);
Properties props = metric.getProperties();
Double valueD = new Double(0);
try{
valueD = Double.valueOf(props.getProperty("myValue"));
}
catch(Exception e){
writeLine(e.toString());
}
return new MetricValue(valueD);
}
else
throw new MetricNotFoundException(metric.toString());
}
}
###############################################################
###############################################################
public class MyAutoDiscoveryServerDetector extends ServerDetector implements AutoServerDetector {
public List getServerResources(ConfigResponse platformConfig) throws PluginException {
List servers = new ArrayList();
ServerResource server = createServerResource("C:\\fakepath2\\");
ConfigResponse productConfig = new ConfigResponse();
//productConfig.setValue("myTimeout", "1000");
//productConfig.setValue("myUrl", "http://127.0.0.1");
//productConfig.setValue("Description", "Description - My Auto Discovery Description");
//productConfig.setValue("myValue", "10");
server.setProductConfig(productConfig);
server.setMeasurementConfig(productConfig);
servers.add(server);
return servers;
}
}
##############################################################
Next part i will try out the control part of a plugin, maybe there will be come some other questions. 😉
Edit: Really strange, i have to remove to set the default Values in the AutoDiscovery. If i didn't remove these sets, a change in the properties wouldn't effect the properties i get from the metric.
Message was edited by: feschuck