-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor_regex.py
More file actions
28 lines (26 loc) · 1.36 KB
/
Copy pathprocessor_regex.py
File metadata and controls
28 lines (26 loc) · 1.36 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
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("User User123 logged in."))
print(classify_with_regex("Backup started at 2020-01-01 12:00:00"))
print(classify_with_regex("File report.pdf uploaded successfully by user User123"))
print(classify_with_regex("Account with ID 123 created by Admin"))
print(classify_with_regex("System updated to version 1.2.3"))
print(classify_with_regex("Disk cleanup completed successfully."))
print(classify_with_regex("System reboot initiated by user Admin"))
print(classify_with_regex("Backup completed successfully."))
print(classify_with_regex("Guten Appetit!"))