Add journalctl export button (#693)

* Add journalctl export button

* Run spotless

* Split into 2 tabs
This commit is contained in:
Matt
2023-01-03 19:42:19 -08:00
committed by GitHub
parent 0b5256df12
commit af6f5eb0c4
6 changed files with 349 additions and 81 deletions

View File

@@ -25,6 +25,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
@@ -193,6 +194,43 @@ public class RequestHandler {
}
}
private static ShellExec shell = new ShellExec();
public static void onExportCurrentLogs(Context ctx) {
if (!Platform.isLinux()) {
logger.warn("Cannot export journalctl on non-Linux platforms! Ignoring");
ctx.status(500);
return;
}
try {
var tempPath = Files.createTempFile("photonvision-journalctl", ".txt");
shell.executeBashCommand(
"journalctl -u photonvision.service > " + tempPath.toAbsolutePath().toString());
while (!shell.isOutputCompleted()) {
// TODO: add timeout
}
if (shell.getExitCode() == 0) {
// Wrote to the temp file! Add it to the ctx
var stream = new FileInputStream(tempPath.toFile());
logger.info("Uploading settings with size " + stream.available());
ctx.result(stream);
ctx.contentType("application/zip");
ctx.header("Content-Disposition: attachment; filename=\"photonvision-journalctl.txt\"");
ctx.status(200);
} else {
logger.error("Could not export journactl logs! (exit code != 0)");
ctx.status(500);
}
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("Could not export journactl logs! (IOexception)", e);
ctx.status(500);
}
}
public static void onCalibrationEnd(Context ctx) {
logger.info("Calibrating camera! This will take a long time...");
var index = Integer.parseInt(ctx.body());