Index: src/zabbix_java/src/com/zabbix/gateway/JMXItemChecker.java =================================================================== --- src/zabbix_java/src/com/zabbix/gateway/JMXItemChecker.java (revision 41390) +++ src/zabbix_java/src/com/zabbix/gateway/JMXItemChecker.java (working copy) @@ -20,12 +20,16 @@ package com.zabbix.gateway; import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map.Entry; +import java.util.Set; import java.util.Vector; import javax.management.MBeanAttributeInfo; import javax.management.MBeanInfo; import javax.management.MBeanServerConnection; import javax.management.ObjectName; +import javax.management.ObjectInstance; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularDataSupport; import javax.management.remote.JMXConnector; @@ -192,6 +196,44 @@ mapping.put(ItemChecker.JSON_TAG_DATA, counters); return mapping.toString(); } + else if (item.getKeyId().equals("jmx.discovery.filter")) + { + if (1 != item.getArgumentCount()) + throw new ZabbixException("required key format: jmx.discovery.filter[]"); + + ObjectName filter = new ObjectName(item.getArgument(1)); + JSONArray beanList = new JSONArray(); + JSONObject mapping = new JSONObject(); + + Set beans = mbsc.queryMBeans(filter, null); + for (Object obj : beans) { + JSONObject bean = new JSONObject(); + ObjectName beanName; + + // Return the ObjectName instance correctly for both Objects and Instances + if (obj instanceof ObjectName) + beanName = (ObjectName) obj; + else if (obj instanceof ObjectInstance) + beanName = ((ObjectInstance) obj).getObjectName(); + else + throw new RuntimeException("Unexpected object type: " + obj); + + // Build the standing info, description and object path + MBeanInfo mbi = mbsc.getMBeanInfo(beanName); + bean.put("{#JMXDESC}", mbi.getDescription()); + bean.put("{#JMXOBJ}", beanName.getCanonicalName()); + + // Build a list of all the MBean properties as {#PROP} + Hashtable pt = beanName.getKeyPropertyList(); + for (Entry prop : pt.entrySet()) + bean.put(String.format("{#PROP%s}", prop.getKey().toUpperCase()), prop.getValue()); + + beanList.put(bean); + } + + mapping.put(ItemChecker.JSON_TAG_DATA, beanList); + return mapping.toString(); + } else throw new ZabbixException("key ID '%s' is not supported", item.getKeyId()); }