in src/main/java/co/elastic/support/diagnostics/commands/RunLogstashQueries.java [40:113]
public void execute(DiagnosticContext context) throws DiagnosticException {
try {
RestClient client = context.resourceCache.getRestClient(Constants.restInputHost);
RestEntryConfig builder = new RestEntryConfig("1.0.0");
Map restCalls = JsonYamlUtils.readYamlFromClasspath(Constants.LS_REST, true);
Map<String, RestEntry> entries = builder.buildEntryMap(restCalls);
List<RestEntry> queries = new ArrayList<>();
queries.addAll(entries.values());
runQueries(client, queries, context.tempDir, 0, 0);
// Get the information we need to run system calls. It's easier to just get it
// off disk after all the REST calls run.
ProcessProfile nodeProfile = new ProcessProfile();
context.targetNode = nodeProfile;
JsonNode nodeData = JsonYamlUtils.createJsonNodeFromFileName(context.tempDir, "logstash_node.json");
nodeProfile.pid = nodeData.path("jvm").path("pid").asText();
nodeProfile.os = SystemUtils.parseOperatingSystemName(nodeData.path("os").path("name").asText());
nodeProfile.javaPlatform = new JavaPlatform(nodeProfile.os);
if (StringUtils.isEmpty(nodeProfile.pid) || nodeProfile.pid.equals("1")) {
context.dockerPresent = true;
context.runSystemCalls = false;
}
// Create and cache the system command type we need, local or remote...
SystemCommand syscmd = null;
switch (context.diagnosticInputs.diagType) {
case Constants.logstashRemote:
String targetOS;
if (context.dockerPresent) {
targetOS = Constants.linuxPlatform;
} else {
targetOS = nodeProfile.os;
}
syscmd = new RemoteSystem(
targetOS,
context.diagnosticInputs.remoteUser,
context.diagnosticInputs.remotePassword,
context.diagnosticInputs.host,
context.diagnosticInputs.remotePort,
context.diagnosticInputs.keyfile,
context.diagnosticInputs.pkiKeystorePass,
context.diagnosticInputs.knownHostsFile,
context.diagnosticInputs.trustRemote,
context.diagnosticInputs.isSudo);
context.resourceCache.addSystemCommand(Constants.systemCommands, syscmd);
break;
case Constants.logstashLocal:
if (context.dockerPresent) {
syscmd = new LocalSystem(SystemUtils.parseOperatingSystemName(SystemProperties.osName));
} else {
syscmd = new LocalSystem(nodeProfile.os);
}
context.resourceCache.addSystemCommand(Constants.systemCommands, syscmd);
break;
default:
// If it's not one of the above types it shouldn't be here but try to keep
// going...
context.runSystemCalls = false;
}
} catch (Throwable t) {
logger.error("Logstash Query error:", t);
throw new DiagnosticException(String.format(
"Error obtaining logstash output and/or process id - will bypass the rest of processing.. %s",
Constants.CHECK_LOG));
}
}