final JMXServiceURL jmxUrl =
new JMXServiceURL(jmxGlassFishConnectorString);
final Map<String,String[]> jmxEnv = new HashMap<String, String[]>();
final String[] credentials = new String[] {username, password};
jmxEnv.put( JMXConnector.CREDENTIALS, credentials );
final JMXConnector connector =
JMXConnectorFactory.connect(jmxUrl, jmxEnv);
final MBeanServerConnection mbsc = connector.getMBeanServerConnection();
rr.set("default_domain", mbsc.getDefaultDomain());
rr.set("mbean_count", mbsc.getMBeanCount());
ConcurrentHashMap<ObjectName, ArrayList<String>> cache = null;
if ( ! attribute_cache.containsKey(check.get("name")) ) {
Set<ObjectName> allObjectNames = mbsc.queryNames(null, null);
ArrayList<String> domains = new ArrayList<String>();
if ( mbean_domains != null ) {
domains = new ArrayList<String>(Arrays.asList(mbean_domains.split("\\s+")));
}
cache = new ConcurrentHashMap<ObjectName, ArrayList<String>>();
for (ObjectName objectName : allObjectNames) {
if ( ! domains.isEmpty() && ! domains.contains(objectName.getDomain()) ) {
continue;
}
String oname = objectName.getDomain() + ":" + objectName.getCanonicalKeyPropertyListString();
MBeanInfo mbi = mbsc.getMBeanInfo(objectName);
MBeanAttributeInfo[] attribs = mbi.getAttributes();
ArrayList<String> attributes = new ArrayList<String>(attribs.length);
for (MBeanAttributeInfo attr : attribs) {
String type = attr.getType();
// Whitelist the types of attributes we will pull to only allow "Open MBeans" as defined here:
// http://www.oracle.com/technetwork/java/javase/tech/best-practices-jsp-136021.html#mozTocId817742
if (
type != null &&
(
type.equals("int")
|| type.equals("long")
|| type.equals("double")
|| type.equals("boolean")
|| type.equals("java.lang.String")
|| type.equals("java.lang.Date")
|| type.equals("java.lang.BigDecimal")
|| type.equals("java.lang.BigInteger")
|| type.equals("java.lang.Byte")
|| type.equals("java.lang.Short")
|| type.equals("java.lang.Integer")
|| type.equals("java.lang.Long")
|| type.equals("java.lang.Float")
|| type.equals("java.lang.Double")
|| type.equals("java.lang.Character")
|| type.equals("java.lang.Boolean")
|| type.equals("java.lang.Void")
|| type.startsWith("javax.management.openmbean")
)
) {
attributes.add(attr.getName());
}
}
cache.put(objectName, attributes);
getAttributeValues(mbsc, oname, objectName, attributes, rr);
}
// Don't cache anything for test checks, there is no current good way to identify these
// though so this might change to be something other than the name
if ( ! check.get("name").startsWith("c_test") ) {
attribute_cache.put(check.get("name"), cache);
}
}
else {
cache = attribute_cache.get(check.get("name"));
for (ObjectName objectName : cache.keySet()) {
String oname = objectName.getDomain() + ":" + objectName.getCanonicalKeyPropertyListString();
getAttributeValues(mbsc, oname, objectName, cache.get(objectName), rr);
}
}
connector.close();
}
catch (Exception e) {
Jezebel.exceptionTraceLogger(e);
rr.set("jezebel_status", e.getMessage());
}