VMware Cloud Community
feschuck
Contributor
Contributor
Jump to solution

Problems with java plugin and configuration properties

Hi,

i did test the java plugin from the hyperic documentation. Auto discovery is working fine. Now i got the problem if i want to change any "configuration properties" i will get followed error message:
"The configuration has not been set for this resource due to : Invalid configuration: Error reported by Agent @ 141.73.130.146:2144: java.lang.NullPointerException"
Expect i use the default properties, then i dont get any errors.

What is the problem?

MyAutoDiscoveryServerDetector.java
---------------------------------------------------------------------------------------------------------------------------
public class MyAutoDiscoveryServerDetector extends ServerDetector implements

AutoServerDetector {

public List getServerResources(ConfigResponse platformConfig)

throws PluginException {

List servers = new ArrayList();

ServerResource server = createServerResource("My Auto-Discovery Server -> " + (x+1));

ConfigResponse productConfig = new ConfigResponse();

productConfig.setValue("myTimeout", String.valueOf((x+1)*1000));
productConfig.setValue("myUrl", "http://127.0.0." + (x+1));
productConfig.setValue("Description", "Description - My Auto Discovery Description ->"+(x+1));
productConfig.setValue("myValue", 10);

server.setProductConfig(productConfig);

servers.add(server);

return servers;

}
---------------------------------------------------------------------------------------------------------------------------




hq-plugin.xml
---------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0"?>
<plugin package="com.citytechinc.articles.hyperic.plugin">

<filter name="domain" value="My Auto Discovery"/>

<server name="MyAutoDiscoverServer" version="0.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>


<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>
---------------------------------------------------------------------------------------------------------------------------
0 Kudos
1 Solution

Accepted Solutions
JoaquimFreitas
Enthusiast
Enthusiast
Jump to solution

Hum,

That must be due to some inconsistency between the plugin definitions in the server (and/or database) and the agent.

First of all, always check the server log, the errors that appear there should lead to the cause.

Did the plugin xml initialized ok at the server, or any errors appeared?

Do you go to Administration -> Monitoring Defaults and see your plugin (Server Type: MyAutoDiscoverServer) and everything is there?
If not, errors occurred during server startup, check log.

Did you start from a clean slate - created the plugin, added to both server and agent, autodiscovery, added the platform/server in Hyperic - or you already had the platform/server added into Hyperic and that made some changes in the plugin xml that can be conflicting with what is already in the Hyperic database?

These are usually the pitfalls that originate these errors.

Been there, done that.

View solution in original post

0 Kudos
16 Replies
donitatravis101
Contributor
Contributor
Jump to solution

Hello,

I really thought it was only me who encountered the same kind of error. Hope we'll be able to find the solution.

Good day! 🙂
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

well i got no idea what to do now. If you get any solution i would be appreciate it, if you post it here in the forum.

Doesn't look like that here in the forum are many active Hyperic user/developers.
0 Kudos
JoaquimFreitas
Enthusiast
Enthusiast
Jump to solution

Related with your AutoServerDetector...
where is «x» declared? (why you are using (x+1)?)

And the argument to createServerResource is installation path (String installpath), and not what you've set there.

Related with the error:
The hq-plugin.xml must be present in both HQ Server and the HQ Agent. If it is not present in the HQ Server (after a restart), you'll get these errors when you try to change any configuration properties.

Message was edited by: Joaquim Freitas
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

Well the x comes from a for loop which i did remove for the example.

I deployed the plugin to the server and the agent, restarted both and the same problem occurs.

It's curious that with default values it is working proberly.

Any other suggestions?

Message was edited by: feschuck

Message was edited by: feschuck
0 Kudos
JoaquimFreitas
Enthusiast
Enthusiast
Jump to solution

Hum,

That must be due to some inconsistency between the plugin definitions in the server (and/or database) and the agent.

First of all, always check the server log, the errors that appear there should lead to the cause.

Did the plugin xml initialized ok at the server, or any errors appeared?

Do you go to Administration -> Monitoring Defaults and see your plugin (Server Type: MyAutoDiscoverServer) and everything is there?
If not, errors occurred during server startup, check log.

Did you start from a clean slate - created the plugin, added to both server and agent, autodiscovery, added the platform/server in Hyperic - or you already had the platform/server added into Hyperic and that made some changes in the plugin xml that can be conflicting with what is already in the Hyperic database?

These are usually the pitfalls that originate these errors.

Been there, done that.
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

Well i added the Plugin with a new name and new -plugin.jar name and the same error occurs.

I did search in the log files for error about my plugin. I found this error, but this shouldn't effect the problem i have?

2011-09-28 15:37:32,725 ERROR [Thread-0] [CommandDispatcher] Error while processing request
java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at com.citytechinc.articles.hyperic.plugin.MyAutoDiscoveryServerMeasurementPlugin.getValue(MyAutoDiscoveryServerMeasurementPlugin.java:37)
at org.hyperic.hq.product.MeasurementPluginManager.getPluginValue(MeasurementPluginManager.java:176)
at org.hyperic.hq.product.MeasurementPluginManager.getValue(MeasurementPluginManager.java:274)
at org.hyperic.hq.product.MeasurementPluginManager.getValue(MeasurementPluginManager.java:135)
at org.hyperic.hq.product.MeasurementPluginManager.getValue(MeasurementPluginManager.java:127)
at org.hyperic.hq.measurement.agent.server.MeasurementCommandsService.getMeasurements(MeasurementCommandsService.java:201)
at org.hyperic.hq.measurement.agent.server.MeasurementCommandsServer.dispatchCommand(MeasurementCommandsServer.java:169)
at org.hyperic.hq.agent.server.CommandDispatcher.processRequest(CommandDispatcher.java:112)
at org.hyperic.hq.agent.server.CommandListener.listenLoop(CommandListener.java:191)
at org.hyperic.hq.agent.server.AgentDaemon.start(AgentDaemon.java:848)
at org.hyperic.hq.agent.server.AgentDaemon$RunnableAgent.run(AgentDaemon.java:930)
at java.lang.Thread.run(Unknown Source)


And i found that the plugin was load successful:
2011-09-28 15:35:30,983 INFO [Thread-0] [ProductPluginManager] Loading plugin: example2-plugin.jar

I have no idea what's wrong? 😕
0 Kudos
JoaquimFreitas
Enthusiast
Enthusiast
Jump to solution

The Java exception is occuring at com.citytechinc.articles.hyperic.plugin.MyAutoDiscoveryServerMeasurementPlugin.getValue(MyAutoDiscoveryServerMeasurementPlugin.java:37)

Check your code at line 37 (missing a class declaration or a cast, probably).
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

Thx alot you have located the error. It comes from the MeasurementPlugin.

First of all i will explain what my goal was with that test plugin. I wanted to read the variable "Value" out of properties. That doesn't work as supposed.

First of all the Code:
--------------------------------------
public class MyAutoDiscoveryServerMeasurementPlugin extends MeasurementPlugin{
public MetricValue getValue(Metric metric)
throws PluginException,
MetricNotFoundException,
MetricUnreachableException {

Properties props = metric.getObjectProperties();
String type = props.getProperty("Type");

if(type.equals("Platform"))
return new MetricValue(Metric.AVAIL_UP);
else if(type.equals("Value"))
{
ConfigResponse productConfig = new ConfigResponse();
String value = productConfig.getValue("value");
Double valueD = new Double(0);
try{
valueD = Double.valueOf(value);
}
catch(NumberFormatException nfe){
return new MetricValue(2);
}

return new MetricValue(valueD);
}
else
throw new MetricNotFoundException(metric.toString());

}
}
----------------------------------------------------

If i change this plugin to simply just return 100 as Value.
Example:
----------------------------------------------------
public class MyAutoDiscoveryServerMeasurementPlugin extends MeasurementPlugin{
public MetricValue getValue(Metric metric)
throws PluginException,
MetricNotFoundException,
MetricUnreachableException {

Properties props = metric.getObjectProperties();
String type = props.getProperty("Type");

if(type.equals("Platform"))
return new MetricValue(Metric.AVAIL_UP);
else if(type.equals("Value"))
{
ConfigResponse productConfig = new ConfigResponse();
String value = productConfig.getValue("value");
Double valueD = new Double(0);

return new MetricValue(100);
}
else
throw new MetricNotFoundException(metric.toString());

}
}
------------------------------------------------

Then everything is working properly. With this MeasurementPlugin i can change the properties without any errors.

Any mistakes i do in this MeasurementPlugin?


Edit:
Ok i did catch the wrong Exception from Double.valueOf(). If i change this to catch all exception i will get my value of 2 in the metrics.

But why do i get not the value of my Variable Value, which is a number? 😕

Message was edited by: feschuck
0 Kudos
linjinxiao_hype
Contributor
Contributor
Jump to solution

You should change you code like this:

String value = productConfig.getValue("value");
Double valueD = new Double(0);
if(value == null)
return new MetricValue(valueD);
This is your code bug.

Message was edited by: lin jinxiao
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

Ok i got this problem. But now the next problem is that i only get "null" from productConfig.getValue()

I did see that i wrote productConfig.getValue("value"), i changed it to productConfig.getValue("myValue") as it is in the hq-plugin.xml and the ServerDetector without any success. 😕

Here my updated code:

public class MyAutoDiscoveryServerMeasurementPlugin extends MeasurementPlugin{
public MetricValue getValue(Metric metric)
throws PluginException,
MetricNotFoundException,
MetricUnreachableException {

Properties props = metric.getObjectProperties();
String type = props.getProperty("Type");

if(type.equals("Platform"))
return new MetricValue(Metric.AVAIL_UP);
else if(type.equals("Value"))
{
ConfigResponse productConfig = new ConfigResponse();
String value = productConfig.getValue("myValue");

// Logging for debugging
java.util.Date now = new java.util.Date();
writeLine("Debugfile.txt", (now.toString() +" getValue was: "+value) );

Double valueD = new Double(0);
try{
valueD = Double.valueOf(value);
}
catch(Exception e){
writeLine("Debugfile.txt", 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();

servers.add(server);
return servers;

}

}

###############################################################

<?xml version="1.0"?>
<plugin package="com.citytechinc.articles.hyperic.plugin">

<filter name="domain" value="My Auto Discovery"/>

<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>


<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>



Edit:
I tried out how many keys i get from the ConfigResponse with the function getKeys(). I get 0 keys.

I thought Hyperics would store the ConfigRepsonse for each Plugin and you will get your ConfigResponse which you created in the ServerDetector?

Message was edited by: feschuck
0 Kudos
linjinxiao_hype
Contributor
Contributor
Jump to solution

#
ConfigResponse productConfig = new ConfigResponse();
String value = productConfig.getValue("myValue");

The value must be null...
0 Kudos
linjinxiao_hype
Contributor
Contributor
Jump to solution

try this:
ConfigResponse productConfig = getConfig();
String value = productConfig.getValue("myValue");
feschuck
Contributor
Contributor
Jump to solution

well getConfig() returns me null. 😕

No idea how i can get access to my config.
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

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
0 Kudos
linjinxiao_hype
Contributor
Contributor
Jump to solution

Well done!
I did not run your plugin.
the property should be,description=%description%":
<property name="template-config" value="myValue=%myValue%,myUrl=%myUrl%,myTimeout=%myTimeout%,description=%description%"/>,


<filter name="template"
value="myServer:Type=Server:${query}"/>, why should define this filter ?


if you do not use the property, you can get the "myValue" as this:
System.out.println(getPluginData().getConfigSchema(getTypeInfo(), 0).getOption("myValue").getDefault());
0 Kudos
feschuck
Contributor
Contributor
Jump to solution

I did find the mistake. In the autodiscovery.
server.setProductConfig(productConfig);
server.setMeasurementConfig(productConfig); <--- This is wrong

With followed code everything is working with or without setting the values of the properties in the autodiscovery.
server.setProductConfig(productConfig);
server.setMeasurementConfig();

You have to use the template, without it you can't access the properties in the measurementplugin.
0 Kudos