Search in sources :

Example 1 with JmxConnectionConfig

use of org.opennms.netmgt.jmx.connection.JmxConnectionConfig in project opennms by OpenNMS.

the class GenericJMXDetectorFactory method buildRequest.

@Override
public DetectRequest buildRequest(String location, InetAddress address, Integer port, Map<String, String> attributes) {
    // in case port is null, but url is provided, the port is extracted from the url
    if (port == null && attributes.containsKey("url")) {
        try {
            final JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(address, attributes).build();
            port = new JMXServiceURL(config.getUrl()).getPort();
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("url is not valid", e);
        }
    }
    return new DetectRequestImpl(address, port, getRuntimeAttributes(address, port));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) DetectRequestImpl(org.opennms.netmgt.provision.support.DetectRequestImpl) JmxConnectionConfig(org.opennms.netmgt.jmx.connection.JmxConnectionConfig)

Example 2 with JmxConnectionConfig

use of org.opennms.netmgt.jmx.connection.JmxConnectionConfig in project opennms by OpenNMS.

the class JmxUtils method getMBeanServer.

public static MBeanServer getMBeanServer(JmxConfigDao jmxConfigDao, String address, Map<String, String> parameters) {
    Objects.requireNonNull(address);
    Objects.requireNonNull(parameters);
    if (jmxConfigDao != null && jmxConfigDao.getConfig() != null) {
        try {
            final JmxConnectionConfig config = JmxConnectionConfigBuilder.buildFrom(address, parameters).build();
            final int port = new JMXServiceURL(config.getUrl()).getPort();
            final MBeanServer mBeanServer = jmxConfigDao.getConfig().lookupMBeanServer(address, port);
            return mBeanServer;
        } catch (MalformedURLException e) {
            LOG.warn("Unexpected exception: {}", e.getMessage(), e);
        }
    }
    // not found or exception
    return null;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) JmxConnectionConfig(org.opennms.netmgt.jmx.connection.JmxConnectionConfig) MBeanServer(org.opennms.netmgt.config.jmx.MBeanServer)

Example 3 with JmxConnectionConfig

use of org.opennms.netmgt.jmx.connection.JmxConnectionConfig 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.netmgt.config.collectd.jmx.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)

Aggregations

MalformedURLException (java.net.MalformedURLException)3 JmxConnectionConfig (org.opennms.netmgt.jmx.connection.JmxConnectionConfig)3 JMXServiceURL (javax.management.remote.JMXServiceURL)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 JMException (javax.management.JMException)1 JmxDatacollectionConfiggenerator (org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator)1 MBeanServerQueryException (org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException)1 Slf4jLogAdapter (org.opennms.features.jmxconfiggenerator.log.Slf4jLogAdapter)1 JmxDatacollectionConfig (org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)1 MBeanServer (org.opennms.netmgt.config.jmx.MBeanServer)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 DetectRequestImpl (org.opennms.netmgt.provision.support.DetectRequestImpl)1