12-05-2026 Frontend dev
This commit is contained in:
parent
405df0a122
commit
5b8bdf4182
779 changed files with 480564 additions and 6241 deletions
87
app/Console/Commands/AnalyzeLegacyApiAccessLogs.php
Normal file
87
app/Console/Commands/AnalyzeLegacyApiAccessLogs.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\Api\LegacyApiAccessLogAnalyzer;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AnalyzeLegacyApiAccessLogs extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'api:analyze-legacy-access-logs
|
||||
{paths* : Access-log files or glob patterns}
|
||||
{--top=20 : Number of top entries per section}
|
||||
{--no-report : Keinen JSON-Report schreiben}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Analysiert Legacy-API-Zugriffe aus Webserver-Access-Logs.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(LegacyApiAccessLogAnalyzer $analyzer): int
|
||||
{
|
||||
$paths = array_map('strval', (array) $this->argument('paths'));
|
||||
$top = max(1, (int) $this->option('top'));
|
||||
$report = $analyzer->analyze($paths, $top);
|
||||
|
||||
$this->info('Legacy-API-Access-Log-Auswertung');
|
||||
$this->newLine();
|
||||
$this->line("Dateien: {$report['summary']['files']}");
|
||||
$this->line("Log-Zeilen: {$report['summary']['total_lines']}");
|
||||
$this->line("Legacy-API-Requests: {$report['summary']['matched_requests']}");
|
||||
$this->line("Requests mit api_key: {$report['summary']['legacy_key_requests']}");
|
||||
$this->line("Eindeutige Client-IPs: {$report['summary']['unique_client_ips']}");
|
||||
$this->line("Eindeutige API-Key-Fingerprints: {$report['summary']['unique_api_key_fingerprints']}");
|
||||
|
||||
if ($report['missing_paths'] !== []) {
|
||||
$this->newLine();
|
||||
$this->warn('Nicht lesbare Pfade:');
|
||||
foreach ($report['missing_paths'] as $path) {
|
||||
$this->line(" - {$path}");
|
||||
}
|
||||
}
|
||||
|
||||
$this->renderTopTable('Top Endpoints', $report['endpoints']);
|
||||
$this->renderTopTable('Top Client-IPs', $report['client_ips']);
|
||||
$this->renderTopTable('Statuscodes', $report['status_codes']);
|
||||
|
||||
if (! (bool) $this->option('no-report')) {
|
||||
$path = 'migration/legacy-api-access-'.now()->format('Ymd-His').'.json';
|
||||
Storage::disk('local')->put($path, json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
$this->newLine();
|
||||
$this->line("Report geschrieben: storage/app/private/{$path}");
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int> $rows
|
||||
*/
|
||||
private function renderTopTable(string $title, array $rows): void
|
||||
{
|
||||
if ($rows === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->line($title);
|
||||
$this->table(
|
||||
['Wert', 'Requests'],
|
||||
collect($rows)
|
||||
->map(fn (int $count, string $value): array => [$value, $count])
|
||||
->values()
|
||||
->all()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue