From c019eef8f0a536af5d391c88041e222f72e618e9 Mon Sep 17 00:00:00 2001 From: Ferran Orriols Date: Thu, 14 Mar 2019 12:32:33 +0100 Subject: [PATCH] IHOST-1609 added remoting-jmx url connection format --- src/org/newrelic/nrjmx/Application.java | 3 ++- src/org/newrelic/nrjmx/Arguments.java | 9 +++++++++ src/org/newrelic/nrjmx/JMXFetcher.java | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/org/newrelic/nrjmx/Application.java b/src/org/newrelic/nrjmx/Application.java index d4f76092..950ca4e8 100644 --- a/src/org/newrelic/nrjmx/Application.java +++ b/src/org/newrelic/nrjmx/Application.java @@ -45,7 +45,8 @@ public static void main(String[] args) { cliArgs.getHostname(), cliArgs.getPort(), cliArgs.getUsername(), cliArgs.getPassword(), cliArgs.getKeyStore(), cliArgs.getKeyStorePassword(), - cliArgs.getTrustStore(), cliArgs.getTrustStorePassword() + cliArgs.getTrustStore(), cliArgs.getTrustStorePassword(), + cliArgs.getIsRemoteJMX() ); } catch (ConnectionError e) { logger.severe(e.getMessage()); diff --git a/src/org/newrelic/nrjmx/Arguments.java b/src/org/newrelic/nrjmx/Arguments.java index 59cf11c9..e6c5537b 100644 --- a/src/org/newrelic/nrjmx/Arguments.java +++ b/src/org/newrelic/nrjmx/Arguments.java @@ -19,6 +19,7 @@ public class Arguments { private String trustStorePassword; private boolean verbose; private boolean debug; + private boolean isRemoteJMX; Arguments(String[] args) { @@ -59,6 +60,9 @@ public class Arguments { Option help = Option.builder("h") .longOpt("help").desc("Show help").hasArg(false).build(); options.addOption(help); + Option remote = Option.builder("r") + .longOpt("remote").desc("Remote JMX mode").hasArg(false).build(); + options.addOption(remote); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new DefaultParser(); @@ -87,6 +91,7 @@ public class Arguments { this.trustStorePassword = cmd.getOptionValue("trustStorePassword", ""); this.verbose = cmd.hasOption("verbose"); this.debug = cmd.hasOption("debug"); + this.isRemoteJMX = cmd.hasOption("remote"); } public String getHostname() { @@ -101,6 +106,10 @@ public String getUsername() { return username; } + public Boolean getIsRemoteJMX() { + return isRemoteJMX; + } + public String getPassword() { return password; } diff --git a/src/org/newrelic/nrjmx/JMXFetcher.java b/src/org/newrelic/nrjmx/JMXFetcher.java index 0cfde13a..80c1d5d4 100644 --- a/src/org/newrelic/nrjmx/JMXFetcher.java +++ b/src/org/newrelic/nrjmx/JMXFetcher.java @@ -41,8 +41,12 @@ public class ValueError extends Exception { public ValueError(String message) { super(message); } }; - public JMXFetcher(String hostname, int port, String username, String password , String keyStore, String keyStorePassword, String trustStore, String trustStorePassword) throws ConnectionError { + public JMXFetcher(String hostname, int port, String username, String password , String keyStore, String keyStorePassword, String trustStore, String trustStorePassword, Boolean isRemote) throws ConnectionError { String connectionString = String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", hostname, port); + if (isRemote) { + connectionString = String.format("service:jmx:remoting-jmx://%s:%s", hostname, port); + } + Map env = new HashMap<>(); if (username != "") { env.put(JMXConnector.CREDENTIALS, new String[] { username, password });