in src/main/java/co/elastic/support/diagnostics/commands/CollectKibanaLogs.java [39:79]
public void execute(DiagnosticContext context) {
// If we hit a snafu earlier in determining the details on where and how to run, then just get out.
if(!context.runSystemCalls){
logger.info(Constants.CONSOLE, "There was an issue in setting up system logs collection - bypassing. {}", Constants.CHECK_LOG);
return;
}
// the defaults are only set for RPM / Debian or Homebrew, in windows we can not collect any Kibana logs.
if (context.targetNode.os.equals(Constants.winPlatform)) {
logger.info(Constants.CONSOLE, "Kibana logs can not be collected for Windows, the log path is not shared in the Kibana APIs and there is no defaults.");
return;
}
SystemCommand sysCmd = context.resourceCache.getSystemCommand(Constants.systemCommands);
String targetDir = context.tempDir + SystemProperties.fileSeparator + "logs";
ProcessProfile targetNode = context.targetNode;
Map<String, Map<String, String>> osCmds = context.diagsConfig.getSysCalls(context.targetNode.os);
Map<String, String> logCalls = osCmds.get("logs");
try{
// Create the log directory - should never exist but always pays to be cautious.
File tempLogDir = new File(targetDir);
if(!tempLogDir.exists()){
tempLogDir.mkdir();
}
String logStatement = logCalls.get("kibana");
String logListing = sysCmd.runCommand(logStatement).trim();
if (StringUtils.isEmpty(logListing) || logListing.contains("No such file or directory")) {
sysCmd.copyLogsFromJournalctl("kibana.service", targetDir);
logger.info(Constants.CONSOLE, "No Kibana logs could be located at the default path. Searching for Journalctl logs with kibana.service name.");
return;
}
List<String> fileList = extractFilesFromList(logListing, 3);
String kibanaPath = logCalls.get("kibana-default-path");
sysCmd.copyLogs(fileList, kibanaPath, targetDir);
logger.info(Constants.CONSOLE, "Collecting logs from Kibana default path.");
} catch (Exception e) {
logger.info(Constants.CONSOLE, "An error occurred while copying the logs. It may not have completed normally {}.", Constants.CHECK_LOG);
logger.error( e.getMessage(), e);
}
}