fix(analyze_logs): scan-all-Modus funktionierte nicht

docker logs ohne Container-Argument schlägt fehl → 0 Treffer.
Jetzt: Loop über alle laufenden Container (docker ps), pro Match
Container-Name in sample_matches + containers_with_matches im
Output. Tool-Beschreibung angepasst.
This commit is contained in:
Mikei386 committed 2026-08-18 13:44:01 +02:00
1 parent c8c767d45b
commit c4c9752521
2 files changed
+30 -13

No files matched your search

+29 -12
View File
@@ -325,22 +325,38 @@ export async function analyzeContainerLogs(
const patterns = severityLevels[severity] ?? severityLevels["error"];
const regex = new RegExp(`(${patterns.join("|")})`, "i");
let logCmd = `logs --timestamps --since ${since} --tail ${scanTail}`;
if (container) logCmd += ` ${container}`;
const raw = await dockerExec(logCmd, 120);
const lines = raw.split("\n");
// Ziel-Container: einzelner Container oder alle laufenden
let targets: string[];
if (container) {
targets = [container];
} else {
const psRaw = await dockerExec("ps --format '{{.Names}}'", 30);
targets = psRaw
.split("\n")
.map((l) => l.trim())
.filter((l) => l.length > 0);
}
const matches: { pattern: string; line: string }[] = [];
const matches: { pattern: string; line: string; container: string }[] = [];
const counts: Record<string, number> = {};
for (const line of lines) {
const m = line.match(regex);
if (m) {
const key = m[1].toLowerCase();
counts[key] = (counts[key] ?? 0) + 1;
if (matches.length < maxResults) {
matches.push({ pattern: m[1], line: line.trim().slice(0, 300) });
const containersWithMatches: Record<string, number> = {};
for (const name of targets) {
const logCmd = `logs --timestamps --since ${since} --tail ${scanTail} ${name}`;
const raw = await dockerExec(logCmd, 120);
let containerMatches = 0;
for (const line of raw.split("\n")) {
const m = line.match(regex);
if (m) {
const key = m[1].toLowerCase();
counts[key] = (counts[key] ?? 0) + 1;
containerMatches++;
if (matches.length < maxResults) {
matches.push({ pattern: m[1], line: line.trim().slice(0, 300), container: name });
}
}
}
if (containerMatches > 0) containersWithMatches[name] = containerMatches;
}
return JSON.stringify({
@@ -351,6 +367,7 @@ export async function analyzeContainerLogs(
scan_tail: scanTail,
total_matches: Object.values(counts).reduce((a, b) => a + b, 0),
pattern_counts: counts,
containers_with_matches: containersWithMatches,
sample_matches: matches,
});
}