Search in sources :

Example 1 with MBeanServerQueryException

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException in project opennms by OpenNMS.

the class JmxDatacollectionConfiggenerator method queryMbeanServer.

private QueryResult queryMbeanServer(List<String> ids, MBeanServerConnection mBeanServerConnection, boolean runStandardVmBeans) throws MBeanServerQueryException {
    final MBeanServerQuery query = new MBeanServerQuery().withFilters(ids).fetchValues(// we do not fetch values to improve collection speed
    false).showMBeansWithoutAttributes(// we don't need them
    false).sort(// sorting makes finding attributes easier
    true);
    if (!runStandardVmBeans) {
        query.withIgnoresFilter(Collections2.transform(standardVmBeans, input -> input + ":*"));
    }
    final QueryResult result = query.execute(mBeanServerConnection);
    return result;
}
Also used : MBeanServerQuery(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQuery) LogAdapter(org.opennms.features.jmxconfiggenerator.log.LogAdapter) JmxCollection(org.opennms.netmgt.config.collectd.jmx.JmxCollection) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) HashMap(java.util.HashMap) Collections2(com.google.common.collect.Collections2) ArrayList(java.util.ArrayList) QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult) Map(java.util.Map) FilterCriteria(org.opennms.features.jmxconfiggenerator.jmxconfig.query.FilterCriteria) AttributeType(org.opennms.netmgt.collection.api.AttributeType) JaxbUtils(org.opennms.core.xml.JaxbUtils) MBeanServerConnection(javax.management.MBeanServerConnection) Collection(java.util.Collection) Set(java.util.Set) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) CompAttrib(org.opennms.netmgt.config.collectd.jmx.CompAttrib) File(java.io.File) JmxDatacollectionConfig(org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig) Rrd(org.opennms.netmgt.config.collectd.jmx.Rrd) List(java.util.List) Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) CompMember(org.opennms.netmgt.config.collectd.jmx.CompMember) JMException(javax.management.JMException) Attrib(org.opennms.netmgt.config.collectd.jmx.Attrib) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) NameCutter(org.opennms.features.namecutter.NameCutter) MBeanServerQuery(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQuery) QueryResult(org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult)

Example 2 with MBeanServerQueryException

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException 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)

Example 3 with MBeanServerQueryException

use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException in project opennms by OpenNMS.

the class JmxCommand method execute.

protected void execute() throws CmdLineException, CmdRunException {
    try (JMXConnector connector = getJmxConnector()) {
        MBeanServerConnection mbeanServerConnection = connector.getMBeanServerConnection();
        execute(mbeanServerConnection);
    } catch (MBeanServerQueryException | JMException | IOException e) {
        throw new CmdRunException(e);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) JMException(javax.management.JMException) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Aggregations

IOException (java.io.IOException)3 JMException (javax.management.JMException)3 MBeanServerQueryException (org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException)3 MBeanServerConnection (javax.management.MBeanServerConnection)2 JmxDatacollectionConfig (org.opennms.netmgt.config.collectd.jmx.JmxDatacollectionConfig)2 Collections2 (com.google.common.collect.Collections2)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 ObjectName (javax.management.ObjectName)1 CompositeData (javax.management.openmbean.CompositeData)1 JMXConnector (javax.management.remote.JMXConnector)1 JaxbUtils (org.opennms.core.xml.JaxbUtils)1