Hi Guys -
Our development team implemented some JMX operations in our application which return all types of statistics - (We didn't use MBean Attributes so that the app only generates the stats when requested.)
Now, I'm not a java programmer, but we needed to support the polling of these JMX operations, so I started hacking.
The following patch on zabbix_java 1.9.9 (should also apply to 1.9.8) adds that support. It works for me, but I have NOT tested this too deeply. For example, I don't know what will happen if the key is neither an existing Attribute or Operation. Also, Operations have only been tested with zero or one parameters. More than that probably won't work.
This code needs work, but it's a start.
-Mike
Our development team implemented some JMX operations in our application which return all types of statistics - (We didn't use MBean Attributes so that the app only generates the stats when requested.)
Now, I'm not a java programmer, but we needed to support the polling of these JMX operations, so I started hacking.
The following patch on zabbix_java 1.9.9 (should also apply to 1.9.8) adds that support. It works for me, but I have NOT tested this too deeply. For example, I don't know what will happen if the key is neither an existing Attribute or Operation. Also, Operations have only been tested with zero or one parameters. More than that probably won't work.
This code needs work, but it's a start.
Code:
--- JMXItemChecker.java.orig 2012-02-16 11:22:23.103907700 +0200
+++ JMXItemChecker.java 2012-02-16 11:22:48.930242800 +0200
@@ -48,6 +48,12 @@
private String username;
private String password;
+ private Object value;
+ private String operationName;
+ private String[] operationSplit;
+ private String[] operationParameters;
+ private String[] operationSignature;
+
public JMXItemChecker(JSONObject request) throws ZabbixException
{
super(request);
@@ -134,7 +140,52 @@
attributeName = attributeName.substring(0, dot);
}
- return getPrimitiveAttributeValue(mbsc.getAttribute(objectName, attributeName), subAttributeNames);
+ /**
+ * The concept here is to attempt to deal with JMX Operations, not just Attributes.
+ * The following solution was good for us: Attempt to poll as an Attribute. If we fail, attempt as an operation.
+ * CURRENTLY, ONLY SUPPORTS PASSING _ONE_ _STRING_ PARAMETER TO AN OPERATION.
+ * TODO: Hypothetically, we could go and pull the list of JMX objects and figure out what type we're requesting,
+ * but that sounds wasteful to pull the whole map on each request. We might be able to do it once for each connection, and store it locally.
+ */
+ try {
+ // Attempt to poll getAttribute
+ value = mbsc.getAttribute(objectName, attributeName);
+ } catch (javax.management.AttributeNotFoundException e) {
+ // We got an exception. Let's try to poll it as an operation...
+ logger.debug("Attempted to get a non-existant Attribute. Trying as an Operation");
+ /**
+ * We got an exception. Let's try to poll it as an operation...
+ * Let's say we got : 'jmx["com.XXXX:group=monitoring,name=ComponentMonitoring,type=server","getCallAccumulatedTime=messages"]'
+ * Split the "attributeName" field ("getCallAccumulatedTime=messages") on '=' to extract the Operation name:
+ */
+ operationSplit = attributeName.split("=",2);
+ operationName = operationSplit[0];
+
+ logger.debug("Operation request: operationName = {} and operationSplit.length = {} ", operationName, operationSplit.length);
+
+ // Clever defaults so "invoke" doesn't croak if there are no parameters:
+ operationParameters = null;
+ operationSignature = null;
+
+ // If we have parameters...
+ if (operationSplit.length > 1)
+ {
+ /* This code needs to be rewritten - I don't have any JMX's with more than one parameter to test on...
+ * Basically, it needs to parse the options and set the signature of each.
+ * Unfortunately, I don't know the format for multiple parameters, and seeing that I used ',' to separate betweeen multiple parameters...
+ * There's a good examples of the RIGHT way to do it at:
+ * https://archive-crawler.svn.sourceforge.net/svnroot/archive-crawler/trunk/cmdline-jmxclient/src/java/org/archive/jmx/Client.java
+ * (near the end)
+ */
+ operationParameters = operationSplit[1].split(",");
+ logger.debug("Operation request: parameters[0] = {}", operationParameters[0]);
+ operationSignature = new String[]{ "java.lang.String"}; //NOI18N
+ }
+ value = mbsc.invoke(objectName, operationName, operationParameters, operationSignature);
+ subAttributeNames="";
+ }
+
+ return getPrimitiveAttributeValue(value,subAttributeNames);
}
else if (item.getKeyId().equals("jmx.discovery"))
{
Comment