in src/main/java/co/elastic/support/monitoring/MonitoringExportService.java [41:138]
public void execExtract(MonitoringExportInputs inputs) throws DiagnosticException {
// Initialize outside the block for Exception handling
RestClient client = null;
MonitoringExportConfig config = null;
String tempDir = SystemProperties.fileSeparator + Constants.MONITORING_DIR;
String monitoringUri = "";
try {
if (StringUtils.isEmpty(inputs.outputDir)) {
tempDir = SystemProperties.userDir + tempDir;
} else {
tempDir = inputs.outputDir + tempDir;
}
// Initialize the temp directory first.
// Set up the log file manually since we're going to package it with the
// diagnostic.
// It will go to wherever we have the temp dir set up.
SystemUtils.nukeDirectory(tempDir);
Files.createDirectories(Paths.get(tempDir));
createFileAppender(tempDir, "extract.log");
Map configMap = JsonYamlUtils.readYamlFromClasspath(Constants.DIAG_CONFIG, true);
config = new MonitoringExportConfig(configMap);
client = RestClient.getClient(
inputs.host,
inputs.port,
inputs.scheme,
inputs.user,
inputs.password,
inputs.proxyHost,
inputs.proxyPort,
inputs.proxyUser,
inputs.proxyPassword,
inputs.pkiKeystore,
inputs.pkiKeystorePass,
inputs.skipVerification,
config.extraHeaders,
config.connectionTimeout,
config.connectionRequestTimeout,
config.socketTimeout);
config.semver = CheckElasticsearchVersion.getElasticsearchVersion(client);
String version = config.semver.getVersion();
RestEntryConfig builder = new RestEntryConfig(version);
Map restCalls = JsonYamlUtils.readYamlFromClasspath(Constants.MONITORING_REST, true);
Map<String, RestEntry> versionedRestCalls = builder.buildEntryMap(restCalls);
monitoringUri = versionedRestCalls.get("monitoring-uri").getUrl();
if (inputs.listClusters) {
logger.info(Constants.CONSOLE, "Displaying a list of available clusters.");
showAvailableClusters(config, client, monitoringUri);
return;
}
if (inputs.type.equalsIgnoreCase("all") || inputs.type.equalsIgnoreCase("monitoring")) {
if (StringUtils.isEmpty(inputs.clusterId)) {
throw new DiagnosticException("missingClusterId");
}
validateClusterId(inputs.clusterId, config, client, monitoringUri);
}
runExportQueries(tempDir, client, config, inputs, versionedRestCalls);
} catch (DiagnosticException de) {
switch (de.getMessage()) {
case "clusterQueryError":
logger.error(Constants.CONSOLE,
"The cluster id could not be validated on this monitoring cluster due to retrieval errors.");
break;
case "missingClusterId":
logger.error(Constants.CONSOLE, "Cluster id is required. Diaplaying a list of available clusters.");
showAvailableClusters(config, client, monitoringUri);
break;
case "noClusterIdFound":
logger.error(Constants.CONSOLE,
"Entered cluster id not found. Please enure you have a valid cluster_uuid for the monitored clusters.");
showAvailableClusters(config, client, monitoringUri);
break;
default:
logger.info(Constants.CONSOLE,
"Entered cluster id not found - unexpected exception. Please enure you have a valid cluster_uuid for the monitored clusters. Check diagnostics.log for more details.");
logger.error(de);
}
logger.error(Constants.CONSOLE, "Cannot continue processing. Exiting {}", Constants.CHECK_LOG);
} catch (IOException e) {
logger.error(Constants.CONSOLE, "Access issue with temp directory", e);
throw new RuntimeException("Issue with creating temp directory - see logs for details.");
} catch (Throwable t) {
logger.error("Unexpected error occurred", t);
logger.error(Constants.CONSOLE, "Unexpected error. {}", Constants.CHECK_LOG);
} finally {
closeLogs();
createArchive(tempDir);
client.close();
SystemUtils.nukeDirectory(tempDir);
}
}