ZABBIX Forums  
  #1  
Old 16-02-2012, 10:34
tewner tewner is offline
Junior Member
 
Join Date: Aug 2005
Posts: 7
Default Initial support for JMX Operations in Java Proxy

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.

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"))
                {
-Mike
Reply With Quote
  #2  
Old 07-03-2012, 09:31
tewner tewner is offline
Junior Member
 
Join Date: Aug 2005
Posts: 7
Default Any update here?

Hi Guys -
Has anyone taken a look? Is there any plan for Zabbix to support JMX Operations?
Reply With Quote
  #3  
Old 30-11-2012, 21:14
nnoori nnoori is offline
Junior Member
 
Join Date: Nov 2012
Location: Ottawa Canada
Posts: 6
Default Zabbix JAVA Gateway - JMX operations support

Hello,

Has there been any development on the support for the JMX operations, even if we implement the hack mentioned below, how can we pass via the WEB Interface?

A JMX operation is not a value to be displayed it needs an interface to invoke operations like start/stop or reset items etc, or and sometimes we need to pass parameters and receive return values.. have anyone tried that? again any hints would help as well!

Thanks.

Nadia

Last edited by nnoori; 24-01-2013 at 19:37.
Reply With Quote
  #4  
Old 24-01-2013, 19:42
nnoori nnoori is offline
Junior Member
 
Join Date: Nov 2012
Location: Ottawa Canada
Posts: 6
Default

Here is something I found recently about extending the Zabbix Java Gateway that would help executing JMX operations
https://www.zabbix.com/forum/showthr...992#post124992
Reply With Quote
Reply

Tags
java, zabbix_java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:21.