From 02f5d5248a663f3684a3c1876e1f85d28f4bb276 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 14 May 2026 13:18:10 +0200 Subject: [PATCH] Creado endpoint para mostrar logs desde disco de los distintos componentes de OG --- src/Controller/System/DiskLogsAction.php | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/Controller/System/DiskLogsAction.php diff --git a/src/Controller/System/DiskLogsAction.php b/src/Controller/System/DiskLogsAction.php new file mode 100644 index 0000000..6d3db4d --- /dev/null +++ b/src/Controller/System/DiskLogsAction.php @@ -0,0 +1,59 @@ +query->get('SYSLOG_IDENTIFIER'); + $host = $request->query->get('host'); + $lines = $request->query->getInt('lines', 100); + + if (!$identifier) { + return new JsonResponse(['error' => 'El parámetro SYSLOG_IDENTIFIER es obligatorio.'], Response::HTTP_BAD_REQUEST); + } + + // Sanitización básica + $lines = max(1, min(1000, $lines)); // Limitar entre 1 y 1000 líneas por seguridad/rendimiento + + $args = []; + $args[] = sprintf('SYSLOG_IDENTIFIER=%s', escapeshellarg($identifier)); + + if ($host) { + $args[] = sprintf('_HOSTNAME=%s', escapeshellarg($host)); + } + + $command = sprintf('journalctl %s --no-pager -n %d 2>&1', implode(' ', $args), $lines); + + $output = []; + $returnVar = 0; + exec($command, $output, $returnVar); + + if ($returnVar !== 0) { + return new JsonResponse([ + 'error' => 'Error al ejecutar journalctl', + 'command' => $command, + 'output' => implode("\n", $output) + ], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return new JsonResponse([ + 'identifier' => $identifier, + 'host' => $host, + 'lines' => $lines, + 'content' => implode("\n", $output) + ]); + } +}