private Set<String> enumerateIndexes(ProbeDescSummary summary) { MBeanServerConnection mbean = cnx.getConnection().connection; Set<String> indexes = new HashSet<String>(); for (String name : summary.specifics.get("mbeanNames").split(" *; *")) { try { Set<ObjectName> mbeanNames = mbean.queryNames(new ObjectName(name), null); Pattern p = Pattern.compile(summary.specifics.get("mbeanIndex")); for (ObjectName oneMbean : mbeanNames) { log(Level.DEBUG, "%s", oneMbean.getCanonicalName()); Matcher m = p.matcher(oneMbean.toString()); if (m.matches() && !m.group(1).isEmpty()) { log(Level.DEBUG, "index found: %s for %s", m.group(1), summary.name); indexes.add(m.group(1)); } } } catch (MalformedObjectNameException e) { log( Level.WARN, "invalid name for auto discovery of probe %s: %s", summary.name, e.getMessage()); } catch (IOException e) { log( Level.WARN, "Connection failed for auto discovery of probe %s: %s", summary.name, e.getMessage()); } } return indexes; }
@Override public boolean isGoodProbeDesc(ProbeDescSummary summary) { MBeanServerConnection mbean = cnx.getConnection().connection; boolean valid = true; boolean enumerated = false; for (String name : summary.specifics.get("mbeanNames").split(" *; *")) { enumerated = true; try { Set<ObjectName> mbeanNames = mbean.queryNames(new ObjectName(name), null); log(Level.TRACE, "%s", "found mbeans %s for %s", mbeanNames, summary.name); if (mbeanNames.size() > 1 && !summary.isIndexed) { log(Level.WARN, "not indexed probe %s return more than one mbean", summary.name); valid = false; } else if (mbeanNames.size() > 0) { valid &= true; } else { valid = false; } } catch (MalformedObjectNameException e) { log( Level.WARN, "invalid name for auto discovery of probe %s: %s", summary.name, e.getMessage()); } catch (IOException e) { log( Level.WARN, "Connection failed for auto discovery of probe %s: %s", summary.name, e.getMessage()); } } return valid && enumerated; }
@Override public void discoverPost( String hostname, JrdsElement hostEleme, Map<String, JrdsDocument> probdescs, HttpServletRequest request) { cnx.stopConnection(); }
private MBeanServerConnection connect(String hostname, HttpServletRequest request) { this.hostname = hostname; String protocolName = request.getParameter("discoverJmxProtocol"); if (protocolName != null && !protocolName.trim().isEmpty()) { cnx.setProtocol(JmxProtocol.valueOf(protocolName.trim())); } Integer port = jrds.Util.parseStringNumber(request.getParameter("discoverJmxPort"), 0); if (port != 0) { cnx.setPort(port); } cnx.setUser(request.getParameter("discoverJmxUser")); cnx.setPassword(request.getParameter("discoverJmxPassword")); if (cnx.startConnection()) { return cnx.getConnection().connection; } else { return null; } }
@Override public void addConnection(JrdsElement hostElement, HttpServletRequest request) { JrdsElement cnxElem = hostElement.addElement("connection", "type=jrds.probe.JMXConnection"); cnxElem.addElement("attr", "name=protocol").setTextContent(cnx.getProtocol().toString()); cnxElem.addElement("attr", "name=port").setTextContent(Integer.toString(cnx.getPort())); }