mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Add journalctl export button (#693)
* Add journalctl export button * Run spotless * Split into 2 tabs
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -84,6 +84,7 @@ public class Server {
|
||||
app.post("/api/settings/import", RequestHandler::onSettingUpload);
|
||||
app.post("/api/settings/offlineUpdate", RequestHandler::onOfflineUpdate);
|
||||
app.get("/api/settings/photonvision_config.zip", RequestHandler::onSettingsDownload);
|
||||
app.get("/api/settings/photonvision-journalctl.txt", RequestHandler::onExportCurrentLogs);
|
||||
app.post("/api/settings/camera", RequestHandler::onCameraSettingsSave);
|
||||
app.post("/api/settings/general", RequestHandler::onGeneralSettings);
|
||||
app.post("/api/settings/endCalibration", RequestHandler::onCalibrationEnd);
|
||||
|
||||
Reference in New Issue
Block a user