import json from datetime import datetime, timedelta import random from faker import Faker # Initialize Faker instance fake = Faker() # Sample data actions = ["LOGIN", "LOGOUT", "SELECT", "UPDATE", "DELETE"] objects_accessed = [ "System Configurations", "Employee Records", "Order Details", "User Profiles", "Transaction Logs", "Server Logs", "Product Catalog", "Payment Information", "Customer Feedback", "Internal Reports", "Audit Trails", "Access Logs", "Security Policies", "Employee Attendance", "Network Configurations", "HR Records", "Financial Statements", "Inventory Data", ] status_options = ["Success", "Failure"] # Function to generate a random IP address def generate_ip(): return f"{random.randint(1, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}" # Function to generate a random timestamp within a specific day def generate_random_timestamp(date): random_time = timedelta(seconds=random.randint(0, 86400)) # Random seconds in a day return (date + random_time).isoformat() # Function to generate log entry def generate_log_entry(date): timestamp = generate_random_timestamp(date) user = fake.name() action = random.choice(actions) object_accessed = random.choice(objects_accessed) ip_address = generate_ip() status = random.choice(status_options) return { "timestamp": timestamp, "user": user, "action": action, "objectAccessed": object_accessed, "ipAddress": ip_address, "status": status, } # Define your start and end date start_date = datetime(2025, 1, 1) end_date = datetime(2025, 8, 2) # Generate logs per day log_entries = [] current_date = start_date while current_date <= end_date: logs_per_day = random.randint(15, 20) # Generate 15 to 20 logs per day for _ in range(logs_per_day): log_entries.append(generate_log_entry(current_date)) current_date += timedelta(days=1) # Move to the next day # Define the path to the JSON file file_path = "audit_logs.json" # Write the generated logs to the file with open(file_path, "w") as json_file: json.dump(log_entries, json_file, indent=4) print(f"Logs have been written to {file_path}")