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));
}
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;
}
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);
}
}
Aggregations