use of org.opennms.netmgt.jmx.connection.JmxConnectionConfigBuilder 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