원격 syslog 기능 제거

This commit is contained in:
seo committed 2026-08-01 11:32:15 +09:00
1 parent 95a4750137
commit c0dadcc8a9
5 files changed
+4 -482

No files matched your search

-173
View File
@@ -177,76 +177,6 @@ function text_log_tail(string $path, string $label, int $limit = 500, ?callable
];
}
function synology_remote_log_visible(string $line): bool
{
if (str_contains($line, 'Last message ') && str_contains($line, 'suppressed by syslog-ng')) {
return false;
}
if (preg_match('/\ssynotifyd\[\d+\]\s/', $line)) {
return false;
}
if (preg_match('/\ssynoelasticd\[\d+\]\s/', $line)) {
$noise = [
'(UpsertByID)',
'(SetByID)',
'(DelByID)',
'(DelByQuery)',
'(Commit) Commit: fileindex_',
];
foreach ($noise as $needle) {
if (str_contains($line, $needle)) {
return false;
}
}
}
if (preg_match('/\sfileindexd\[\d+\]\s/', $line)) {
$noise = [
'ProcessOP BEGIN: IndexUpsert',
'ProcessOP DONE!: IndexUpsert',
'ProcessOP SKIPPED: IndexUpsert',
'ProcessOP BEGIN: IndexReindex',
'ProcessOP DONE!: IndexReindex',
'ProcessOP SKIPPED: IndexReindex',
'(Process) Worker<',
'PrepareTmpOPtree',
'CheckClearOldTmpOPtree',
'BuildTree',
'Commit [fileindex_',
];
foreach ($noise as $needle) {
if (str_contains($line, $needle)) {
return false;
}
}
}
if (preg_match('/\sscemd\[\d+\]\s/', $line)) {
$noise = [
'Could not open file `/dev/i2c-1',
'Could not open file `/dev/i2c/1',
'Fail to initLedBrightnessConfig',
'No brightness setting',
'Fail to init config list',
'Fail to set led brightness.',
];
foreach ($noise as $needle) {
if (str_contains($line, $needle)) {
return false;
}
}
}
return true;
}
function synology_remote_log(): array
{
return text_log_tail('/var/log/remote/synology/chaegeon.log', 'synology remote', 5000, 'synology_remote_log_visible');
}
function command_first_line(array $cmd, bool $root = false, int $timeout = 3): string
{
$result = sh($cmd, $root, $timeout);
@@ -258,112 +188,16 @@ function command_first_line(array $cmd, bool $root = false, int $timeout = 3): s
return (int)$result['code'] === 0 && $lines ? (string)$lines[0] : '';
}
function remote_log_file_status(string $dir): array
{
$files = [];
$totalBytes = 0;
$newest = null;
foreach (glob(rtrim($dir, '/') . '/*.log') ?: [] as $path) {
$size = filesize($path) ?: 0;
$mtime = filemtime($path) ?: 0;
$totalBytes += $size;
$row = [
'name' => basename($path),
'path' => $path,
'size_bytes' => $size,
'size' => bytes_human($size),
'updated_at' => $mtime > 0 ? date('Y-m-d H:i:s', $mtime) : null,
'age_seconds' => $mtime > 0 ? max(0, time() - $mtime) : null,
];
$files[] = $row;
if ($newest === null || (int)$row['age_seconds'] < (int)($newest['age_seconds'] ?? PHP_INT_MAX)) {
$newest = $row;
}
}
usort($files, static fn($a, $b): int => (int)($a['age_seconds'] ?? PHP_INT_MAX) <=> (int)($b['age_seconds'] ?? PHP_INT_MAX));
return [
'path' => $dir,
'available' => is_dir($dir),
'file_count' => count($files),
'total_bytes' => $totalBytes,
'total_size' => bytes_human($totalBytes),
'newest' => $newest,
'files' => array_slice($files, 0, 5),
];
}
function remote_log_queue_status(): array
{
$result = sh([
'/usr/bin/find',
'/var/spool/rsyslog',
'-maxdepth',
'1',
'-name',
'control_synology_fwd*',
'-printf',
'%s\n',
], true, 3);
if ((int)$result['code'] !== 0) {
return [
'available' => false,
'file_count' => null,
'total_bytes' => null,
'total_size' => '-',
];
}
$sizes = array_values(array_filter(
array_map('trim', preg_split('/\R/', trim((string)$result['out'])) ?: []),
static fn($line): bool => $line !== ''
));
$total = array_sum(array_map('intval', $sizes));
return [
'available' => true,
'file_count' => count($sizes),
'total_bytes' => $total,
'total_size' => bytes_human($total),
];
}
function remote_log_status(): array
{
$journalDir = '/var/log/journal';
$journalDisk = command_first_line(['/usr/bin/journalctl', '--disk-usage', '--no-pager'], false, 3);
$journalBoots = command_first_line(['/usr/bin/bash', '-lc', 'journalctl --list-boots --no-pager 2>/dev/null | wc -l'], false, 3);
$rsyslogActive = command_first_line(['/usr/bin/systemctl', 'is-active', 'rsyslog'], false, 3) ?: 'unknown';
$rsyslogEnabled = command_first_line(['/usr/bin/systemctl', 'is-enabled', 'rsyslog'], false, 3) ?: 'unknown';
$pstoreActive = command_first_line(['/usr/bin/systemctl', 'is-active', 'control-pstore-collect.service'], false, 3) ?: 'inactive';
$listener = sh(['/usr/bin/ss', '-lnt', 'sport', '=', ':6514'], false, 3);
$listenerOk = (int)$listener['code'] === 0 && str_contains((string)$listener['out'], ':6514');
$remoteFiles = remote_log_file_status('/var/log/remote/synology');
$queue = remote_log_queue_status();
$savedCrashFiles = glob('/var/log/pstore/*') ?: [];
$pstoreFiles = glob('/sys/fs/pstore/*') ?: [];
return [
'raspberry_to_synology' => [
'target' => 'chaegeon.com:6514',
'transport' => 'TCP/TLS',
'rsyslog_active' => $rsyslogActive,
'rsyslog_enabled' => $rsyslogEnabled,
'queue' => $queue,
'ok' => $rsyslogActive === 'active',
],
'synology_to_raspberry' => [
'listen_port' => 6514,
'transport' => 'TCP/TLS',
'listener' => $listenerOk,
'logs' => $remoteFiles,
'ok' => $listenerOk && $remoteFiles['file_count'] > 0,
],
'journal' => [
'path' => $journalDir,
'persistent' => is_dir($journalDir),
@@ -4877,13 +4711,6 @@ function control_api_dispatch(): void
]);
}
if ($action === 'synology_log') {
json_out([
'ok' => true,
'data' => synology_remote_log(),
]);
}
if ($action === 'status') {
json_out([
'ok' => true,