-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor_regex.py
More file actions
20 lines (19 loc) · 920 Bytes
/
processor_regex.py
File metadata and controls
20 lines (19 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import re
def classify_with_regex(log_message):
regex_patterns = {
r"User User\d+ logged (in|out).": "User Action",
r"Backup (started|ended) at .*": "System Notification",
r"Backup completed successfully.": "System Notification",
r"System updated to version .*": "System Notification",
r"File .* uploaded successfully by user .*": "System Notification",
r"Disk cleanup completed successfully.": "System Notification",
r"System reboot initiated by user .*": "System Notification",
r"Account with ID .* created by .*": "User Action"
}
for pattern, label in regex_patterns.items():
if re.search(pattern, log_message, re.IGNORECASE):
return label
return None
if __name__ == "__main__":
print(classify_with_regex("Backup completed successfully."))
print(classify_with_regex("Account with ID 1234 created by User1."))