Search in sources :

Example 1 with JmxDatacollectionConfiggenerator

use of org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator 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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) Slf4jLogAdapter(org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) JmxDatacollectionConfig(org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig) IOException(java.io.IOException) JmxConnectionConfig(org.opennms.netmgt.jmx.connection.JmxConnectionConfig) JmxServerConnectionException(org.opennms.netmgt.jmx.connection.JmxServerConnectionException) JmxDatacollectionConfiggenerator(org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator) DefaultJmxConnector(org.opennms.netmgt.jmx.impl.connection.connectors.DefaultJmxConnector) JMException(javax.management.JMException) JmxServerConnectionWrapper(org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper) JmxConnectionConfigBuilder(org.opennms.netmgt.jmx.connection.JmxConnectionConfigBuilder)

Example 2 with JmxDatacollectionConfiggenerator

use of org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator 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);
}
Also used : JmxDatacollectionConfiggenerator(org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator) JmxDatacollectionConfig(org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig)

Aggregations

JmxDatacollectionConfiggenerator (org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator)2 JmxDatacollectionConfig (org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 JMException (javax.management.JMException)1 MBeanServerQueryException (org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException)1 Slf4jLogAdapter (org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter)1 JmxConnectionConfig (org.opennms.netmgt.jmx.connection.JmxConnectionConfig)1 JmxConnectionConfigBuilder (org.opennms.netmgt.jmx.connection.JmxConnectionConfigBuilder)1 JmxServerConnectionException (org.opennms.netmgt.jmx.connection.JmxServerConnectionException)1 JmxServerConnectionWrapper (org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper)1 DefaultJmxConnector (org.opennms.netmgt.jmx.impl.connection.connectors.DefaultJmxConnector)1