feat(oggui): soporte de múltiples SYSLOG_IDENTIFIER en visor de logs de disco
- StatusLogsComponent: @Input identifiers[] en lugar de identifier string, parseo de entries JSON estructurado con formato [timestamp] ID: mensaje - Templates ogboot, ogdhcp, ogrepository, ogcore-status: identifiers correctos por componente y host basado en IP en lugar de nombre del servidor - Añadidos métodos getSelectedXxxIp() en ogboot, ogdhcp y ogrepository statuspull/116/head
parent
3c4d179c86
commit
6099f6be4b
|
|
@ -94,6 +94,8 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then
|
|||
chown -R opengnsys:www-data /opt/opengnsys/ogcore
|
||||
chown www-data:www-data /opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
chmod 664 /opt/opengnsys/ogcore/etc/journal-pull-sources.conf
|
||||
usermod -aG systemd-journal opengnsys
|
||||
usermod -aG systemd-journal-remote opengnsys
|
||||
systemctl daemon-reload
|
||||
systemctl enable og-mercure
|
||||
systemctl enable --now journal-pull-sync.path
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Wants=network-online.target
|
|||
[Service]
|
||||
User=systemd-journal-remote
|
||||
Group=systemd-journal-remote
|
||||
ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG --output=/var/log/journal/remote/%i.journal
|
||||
ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG&SYSLOG_IDENTIFIER=kea-dhcp4&SYSLOG_IDENTIFIER=kea-ctrl-agent&SYSLOG_IDENTIFIER=DhcpLFC&SYSLOG_IDENTIFIER=kea-dhcp6&SYSLOG_IDENTIFIER=tftpd-hpa&SYSLOG_IDENTIFIER=%%28smbd%%29&SYSLOG_IDENTIFIER=%%28nmbd%%29 --split-mode=none --output=/var/log/journal/remote/%i.journal
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
|
||||
|
|
|
|||
|
|
@ -13,29 +13,49 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|||
|
||||
class DiskLogsAction extends AbstractController
|
||||
{
|
||||
private const REMOTE_JOURNAL_DIR = '/var/log/journal/remote';
|
||||
|
||||
#[Route('/opengnsys/system/disk-logs', name: 'api_system_disk_logs', methods: ['GET'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$identifier = $request->query->get('SYSLOG_IDENTIFIER');
|
||||
// Acepta SYSLOG_IDENTIFIER como valor único, array (?SYSLOG_IDENTIFIER[]=a&SYSLOG_IDENTIFIER[]=b)
|
||||
// o lista separada por comas (?SYSLOG_IDENTIFIER=a,b)
|
||||
$rawIdentifiers = $request->query->all()['SYSLOG_IDENTIFIER'] ?? $request->query->get('SYSLOG_IDENTIFIER');
|
||||
if (is_string($rawIdentifiers)) {
|
||||
$rawIdentifiers = array_map('trim', explode(',', $rawIdentifiers));
|
||||
}
|
||||
$identifiers = array_values(array_filter((array) $rawIdentifiers));
|
||||
|
||||
$host = $request->query->get('host');
|
||||
$lines = $request->query->getInt('lines', 100);
|
||||
|
||||
if (!$identifier) {
|
||||
if (empty($identifiers)) {
|
||||
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));
|
||||
|
||||
$lines = max(1, min(1000, $lines));
|
||||
|
||||
$args = ['--no-pager', '--output=json', sprintf('-n %d', $lines)];
|
||||
|
||||
if ($host) {
|
||||
$args[] = sprintf('_HOSTNAME=%s', escapeshellarg($host));
|
||||
// Host remoto: leer del fichero journal nombrado por IP
|
||||
$journalFile = sprintf('%s/%s.journal', self::REMOTE_JOURNAL_DIR, $host);
|
||||
if (!file_exists($journalFile)) {
|
||||
return new JsonResponse(
|
||||
['error' => sprintf('No se encontró el journal para el host %s', $host)],
|
||||
Response::HTTP_NOT_FOUND
|
||||
);
|
||||
}
|
||||
$args[] = sprintf('--file=%s', escapeshellarg($journalFile));
|
||||
}
|
||||
|
||||
$command = sprintf('journalctl %s --no-pager -n %d 2>&1', implode(' ', $args), $lines);
|
||||
// Múltiples SYSLOG_IDENTIFIER se pasan como matches separados → journalctl los aplica con OR
|
||||
foreach ($identifiers as $identifier) {
|
||||
$args[] = sprintf('SYSLOG_IDENTIFIER=%s', escapeshellarg($identifier));
|
||||
}
|
||||
|
||||
$command = sprintf('journalctl %s 2>&1', implode(' ', $args));
|
||||
|
||||
$output = [];
|
||||
$returnVar = 0;
|
||||
|
|
@ -44,16 +64,21 @@ class DiskLogsAction extends AbstractController
|
|||
if ($returnVar !== 0) {
|
||||
return new JsonResponse([
|
||||
'error' => 'Error al ejecutar journalctl',
|
||||
'command' => $command,
|
||||
'output' => implode("\n", $output)
|
||||
], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
// Parsear cada línea como JSON (formato --output=json de journalctl)
|
||||
$entries = array_values(array_filter(array_map(
|
||||
static fn(string $line) => json_decode($line, true),
|
||||
$output
|
||||
)));
|
||||
|
||||
return new JsonResponse([
|
||||
'identifier' => $identifier,
|
||||
'host' => $host,
|
||||
'lines' => $lines,
|
||||
'content' => implode("\n", $output)
|
||||
'identifiers' => $identifiers,
|
||||
'host' => $host ?? 'local',
|
||||
'lines' => count($entries),
|
||||
'entries' => $entries,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue