use of org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig in project opennms by OpenNMS.
the class JmxDatacollectionConfiggenerator method generateJmxConfigModel.
public JmxDatacollectionConfig generateJmxConfigModel(List<String> ids, MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean skipNonNumber, Map<String, String> dictionary) throws MBeanServerQueryException, IOException, JMException {
logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n dictionary" + dictionary);
aliasList.clear();
aliasMap.clear();
nameCutter.setDictionary(dictionary);
final QueryResult queryResult = queryMbeanServer(ids, mBeanServerConnection, runStandardVmBeans);
final JmxDatacollectionConfig xmlJmxDatacollectionConfig = createJmxDataCollectionConfig(serviceName, rrd);
final JmxCollection xmlJmxCollection = xmlJmxDatacollectionConfig.getJmxCollection().get(0);
for (QueryResult.MBeanResult eachMBeanResult : queryResult.getMBeanResults()) {
final ObjectName objectName = eachMBeanResult.objectName;
final Mbean xmlMbean = createMbean(objectName);
final QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
for (MBeanAttributeInfo jmxBeanAttributeInfo : attributeResult.attributes) {
// check for CompositeData
if ("javax.management.openmbean.CompositeData".equals(jmxBeanAttributeInfo.getType())) {
CompAttrib compAttrib = createCompAttrib(mBeanServerConnection, objectName, jmxBeanAttributeInfo, skipNonNumber);
if (compAttrib != null) {
xmlMbean.getCompAttrib().add(compAttrib);
}
}
if (skipNonNumber && !numbers.contains(jmxBeanAttributeInfo.getType())) {
logger.warn("The type of attribute '{}' is '{}' and '--skipNonNumber' is set. Ignoring.", jmxBeanAttributeInfo.getName(), jmxBeanAttributeInfo.getType());
} else {
Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
xmlMbean.getAttrib().add(xmlJmxAttribute);
}
}
if (!xmlMbean.getAttrib().isEmpty() || !xmlMbean.getCompAttrib().isEmpty()) {
xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
}
}
if (xmlJmxCollection.getMbeans().getMbean().size() != queryResult.getMBeanResults().size()) {
logger.warn("Queried {} MBeans, but only got {} in the result set.", queryResult.getMBeanResults().size(), xmlJmxCollection.getMbeans().getMbean().size());
}
return xmlJmxDatacollectionConfig;
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig in project opennms by OpenNMS.
the class DetectMBeansJob method execute.
@Override
public JmxDatacollectionConfig execute() throws JobManager.TaskRunException {
final JmxConnectionConfig connectionConfig = new JmxConnectionConfigBuilder().withUrl(config.getConnection()).withUsername(config.getUser()).withPassword(config.getPassword()).build();
try (JmxServerConnectionWrapper connector = new DefaultJmxConnector().createConnection(connectionConfig)) {
final JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class));
final JmxDatacollectionConfig generatedJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel(connector.getMBeanServerConnection(), "anyservice", !config.isSkipDefaultVM(), config.isSkipNonNumber(), JmxHelper.loadInternalDictionary());
applyFilters(generatedJmxConfigModel);
return generatedJmxConfigModel;
} catch (IOException | MBeanServerQueryException | JMException | JmxServerConnectionException e) {
if (e instanceof UnknownHostException || e.getCause() instanceof UnknownHostException) {
throw new JobManager.TaskRunException(String.format("Unknown host: %s", config.getConnection()), e);
}
if (e instanceof MalformedURLException || e.getCause() instanceof MalformedURLException) {
throw new JobManager.TaskRunException(String.format("Cannot create valid JMX Connection URL. Connection: '%s'", config.getConnection()), e);
}
throw new JobManager.TaskRunException("Error while retrieving MBeans from server.", e);
}
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig in project opennms by OpenNMS.
the class MBeansView method createJmxDataCollectionAccordingToSelection.
/**
* The whole point was to select/deselect
* Mbeans/Attribs/CompMembers/CompAttribs. In this method we simply create a
* JmxDatacollectionConfig considering the choices we made in the gui. To do
* this, we clone the original <code>JmxDatacollectionConfig</code>
* loaded at the beginning. After that we remove all
* MBeans/Attribs/CompMembers/CompAttribs and add all selected
* MBeans/Attribs/CompMembers/CompAttribs afterwards.
*
* @return
*/
private static JmxDatacollectionConfig createJmxDataCollectionAccordingToSelection(final UiModel uiModel, final SelectionManager selectionManager) {
/*
* At First we clone the original collection. This is done, because if
* we make any modifications (e.g. deleting not selected elements) the
* data isn't available in the GUI, too. To avoid reloading the data
* from server, we just clone it.
*/
JmxDatacollectionConfig clone = JmxCollectionCloner.clone(uiModel.getRawModel());
/*
* At second we remove all MBeans from original data and get only
* selected once.
*/
List<Mbean> exportBeans = clone.getJmxCollection().get(0).getMbeans().getMbean();
exportBeans.clear();
Iterable<Mbean> selectedMbeans = selectionManager.getSelectedMbeans();
for (Mbean mbean : selectedMbeans) {
/*
* We remove all Attributes from Mbean, because we only want
* selected ones.
*/
Mbean exportBean = JmxCollectionCloner.clone(mbean);
// we only want selected ones :)
exportBean.getAttrib().clear();
for (Attrib att : selectionManager.getSelectedAttributes(mbean)) {
exportBean.getAttrib().add(JmxCollectionCloner.clone(att));
}
// we do not add the parent
if (!exportBean.getAttrib().isEmpty()) {
exportBeans.add(exportBean);
}
/*
* We remove all CompAttribs and CompMembers from MBean,
* because we only want selected ones.
*/
exportBean.getCompAttrib().clear();
for (CompAttrib compAtt : selectionManager.getSelectedCompositeAttributes(mbean)) {
CompAttrib cloneCompAtt = JmxCollectionCloner.clone(compAtt);
cloneCompAtt.getCompMember().clear();
for (CompMember compMember : selectionManager.getSelectedCompositeMembers(compAtt)) {
cloneCompAtt.getCompMember().add(JmxCollectionCloner.clone(compMember));
}
// we do not add the child
if (!cloneCompAtt.getCompMember().isEmpty()) {
exportBean.getCompAttrib().add(cloneCompAtt);
}
}
}
// we sort the order, so the result is deterministic
sort(exportBeans);
// Last but not least, we need to update the service name
clone.getJmxCollection().get(0).setName(uiModel.getServiceName());
return clone;
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig in project opennms by OpenNMS.
the class JmxConfigCreateCommand method execute.
@Override
protected void execute(MBeanServerConnection mbeanServerConnection) throws IOException, MBeanServerQueryException, JMException {
JmxDatacollectionConfiggenerator jmxConfigGenerator = new JmxDatacollectionConfiggenerator(LOG);
Map<String, String> dictionary = loadDictionary();
JmxDatacollectionConfig generateJmxConfigModel = jmxConfigGenerator.generateJmxConfigModel(ids, mbeanServerConnection, serviceName, !skipDefaultVM, skipNonNumber, dictionary);
jmxConfigGenerator.writeJmxConfigFile(generateJmxConfigModel, outFile);
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig in project opennms by OpenNMS.
the class JmxDatacollectionConfiggeneratorTest method testGenerateJmxConfigModelSkipJvmMBeans.
@Test
public void testGenerateJmxConfigModelSkipJvmMBeans() throws MBeanServerQueryException, IOException, JMException {
JmxDatacollectionConfig jmxConfigModel = jmxConfiggenerator.generateJmxConfigModel(platformMBeanServer, "testService", false, true, dictionary);
Assert.assertEquals(1, jmxConfigModel.getJmxCollection().size());
Assert.assertEquals(1, jmxConfigModel.getJmxCollection().get(0).getMbeans().getMbean().size());
Assert.assertEquals("org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxTest", jmxConfigModel.getJmxCollection().get(0).getMbeans().getMbean().get(0).getName());
Assert.assertEquals(4, jmxConfigModel.getJmxCollection().get(0).getMbeans().getMbean().get(0).getAttrib().size());
LOG.info(prettyPrint(jmxConfigModel));
}
Aggregations