|
| 1 | +from processor_regex import classify_with_regex |
| 2 | +from processor_bert import classify_with_bert |
| 3 | +from processor_llm import classify_with_llm |
| 4 | + |
| 5 | +def classify(logs): |
| 6 | + labels = [] |
| 7 | + for source, log_msg in logs: |
| 8 | + label = classify_log(source, log_msg) |
| 9 | + labels.append(label) |
| 10 | + return labels |
| 11 | + |
| 12 | + |
| 13 | +def classify_log(source, log_msg): |
| 14 | + if source == "LegacyCRM": |
| 15 | + label = classify_with_llm(log_msg) |
| 16 | + else: |
| 17 | + label = classify_with_regex(log_msg) |
| 18 | + if not label: |
| 19 | + label = classify_with_bert(log_msg) |
| 20 | + return label |
| 21 | + |
| 22 | +def classify_csv(input_file): |
| 23 | + import pandas as pd |
| 24 | + df = pd.read_csv(input_file) |
| 25 | + |
| 26 | + # Perform classification |
| 27 | + df["target_label"] = classify(list(zip(df["source"], df["log_message"]))) |
| 28 | + |
| 29 | + # Save the modified file |
| 30 | + output_file = "output.csv" |
| 31 | + df.to_csv(output_file, index=False) |
| 32 | + |
| 33 | + return output_file |
| 34 | + |
| 35 | +if __name__ == '__main__': |
| 36 | + classify_csv("test.csv") |
| 37 | + # logs = [ |
| 38 | + # ("ModernCRM", "IP 192.168.133.114 blocked due to potential attack"), |
| 39 | + # ("BillingSystem", "User 12345 logged in."), |
| 40 | + # ("AnalyticsEngine", "File data_6957.csv uploaded successfully by user User265."), |
| 41 | + # ("AnalyticsEngine", "Backup completed successfully."), |
| 42 | + # ("ModernHR", "GET /v2/54fadb412c4e40cdbaed9335e4c35a9e/servers/detail HTTP/1.1 RCODE 200 len: 1583 time: 0.1878400"), |
| 43 | + # ("ModernHR", "Admin access escalation detected for user 9429"), |
| 44 | + # ("LegacyCRM", "Case escalation for ticket ID 7324 failed because the assigned support agent is no longer active."), |
| 45 | + # ("LegacyCRM", "Invoice generation process aborted for order ID 8910 due to invalid tax calculation module."), |
| 46 | + # ("LegacyCRM", "The 'BulkEmailSender' feature is no longer supported. Use 'EmailCampaignManager' for improved functionality."), |
| 47 | + # ("LegacyCRM", " The 'ReportGenerator' module will be retired in version 4.0. Please migrate to the 'AdvancedAnalyticsSuite' by Dec 2025") |
| 48 | + # ] |
| 49 | + # labels = classify(logs) |
| 50 | + # |
| 51 | + # for log, label in zip(logs, labels): |
| 52 | + # print(log[0], "->", label) |
| 53 | + |
| 54 | + |
0 commit comments