|
26 | 26 | log_types = ['conn', 'dns', 'http', 'ssl', 'smb_mapping'] # Added smb_mapping |
27 | 27 | log_files = defaultdict(list) |
28 | 28 | for log_type in log_types: |
29 | | - patterns = [f"{log_type}.log", f"{log_type}.*.log", f"{log_type}.*.log.gz"] |
| 29 | + patterns = [ |
| 30 | + f"{log_type}.log", |
| 31 | + f"{log_type}.log.gz", |
| 32 | + f"{log_type}.*.log", |
| 33 | + f"{log_type}.*.log.gz", |
| 34 | + ] |
| 35 | + found = set() |
30 | 36 | for pattern in patterns: |
31 | | - log_files[log_type] += glob.glob(os.path.join(args.directory, pattern)) |
| 37 | + found.update(glob.glob(os.path.join(args.directory, pattern))) |
| 38 | + log_files[log_type] = sorted(found) |
32 | 39 |
|
33 | 40 | # Read files with TSV header support |
34 | 41 | def read_lines(filepath): |
35 | 42 | open_func = gzip.open if filepath.endswith('.gz') else open |
36 | 43 | mode = 'rt' if filepath.endswith('.gz') else 'r' |
37 | 44 | fields = [] |
| 45 | + is_json = None |
38 | 46 | try: |
39 | 47 | with open_func(filepath, mode, errors='replace') as f: |
40 | | - for line in f: |
41 | | - if line.startswith('#fields'): |
42 | | - fields = line.strip().split('\t')[1:] |
43 | | - elif not line.startswith('#') and fields: |
44 | | - parts = line.strip().split('\t') |
| 48 | + for raw_line in f: |
| 49 | + line = raw_line.strip() |
| 50 | + if not line: |
| 51 | + continue |
| 52 | + if line.startswith('#'): |
| 53 | + if line.startswith('#fields'): |
| 54 | + fields = line.split('\t')[1:] |
| 55 | + continue |
| 56 | + if is_json is None: |
| 57 | + is_json = line.startswith('{') |
| 58 | + if is_json: |
| 59 | + try: |
| 60 | + yield json.loads(raw_line) |
| 61 | + except json.JSONDecodeError: |
| 62 | + continue |
| 63 | + else: |
| 64 | + if not fields: |
| 65 | + continue |
| 66 | + parts = raw_line.rstrip('\n').split('\t') |
45 | 67 | if len(parts) != len(fields): |
46 | 68 | continue |
47 | 69 | yield dict(zip(fields, parts)) |
@@ -389,4 +411,3 @@ def filter_local_set(ipset): |
389 | 411 | legacy_ports_dst = sections['dst_ports_as_dst'].most_common(5) |
390 | 412 | if legacy_ports_dst: |
391 | 413 | console.print(" 🛡️ Dst Ports (as destination, top 5): " + ', '.join(f"{k} ({v})" for k, v in legacy_ports_dst)) |
392 | | - |
|
0 commit comments