File size: 961 Bytes
cd218ce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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):
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."))
print(classify_with_regex("Hey Bro, chill ya!"))
|