-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_triage.py
More file actions
67 lines (52 loc) · 1.84 KB
/
batch_triage.py
File metadata and controls
67 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""
Batch CI Log Analyzer
Processes multiple log files and generates summary report
"""
import sys
from pathlib import Path
from colorama import Fore, init
from ci_triage import CITriageAssistant
init(autoreset=True)
def analyze_directory(log_dir, patterns_file):
"""
Analyze all log files in a directory.
Args:
log_dir: Directory containing log files
patterns_file: Path to patterns YAML file
"""
log_files = sorted(Path(log_dir).glob("*.log"))
if not log_files:
print(f"{Fore.RED}No log files found in {log_dir}")
return
print(f"{Fore.CYAN}Analyzing {len(log_files)} log files...\n")
assistant = CITriageAssistant(patterns_file)
results = []
for log_file in log_files:
matches = assistant.analyze_log(str(log_file))
results.append(
{
"file": log_file.name,
"matches": matches,
}
)
print(f"{Fore.CYAN}{'=' * 70}")
print(f"{Fore.CYAN}BATCH ANALYSIS SUMMARY")
print(f"{Fore.CYAN}{'=' * 70}\n")
for result in results:
print(f"{Fore.YELLOW}{result['file']}")
if result["matches"]:
top_match = result["matches"][0]
print(f" {Fore.GREEN}Top Issue: {top_match['pattern']['name']}")
print(f" {Fore.WHITE}Severity: {top_match['pattern']['severity']}")
print(f" {Fore.WHITE}Confidence Score: {top_match['score']}")
print(
f" {Fore.WHITE}Matched Keywords: "
f"{', '.join(top_match['matched_keywords'])}\n"
)
else:
print(f" {Fore.RED}No patterns detected\n")
if __name__ == "__main__":
log_dir = sys.argv[1] if len(sys.argv) > 1 else "logs"
patterns_file = "patterns/failure_patterns.yaml"
analyze_directory(log_dir, patterns_file)