Collector for Active Directory Logs

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2023-10-04

Problem Statement

Design and implement a Log Collector system that can connect to Active Directory servers, fetch authentication and access logs, process them, and store them in a structured format for downstream analysis or monitoring tools.


This problem evaluates your understanding of:


•Class design for distributed systems
•Log ingestion pipelines
•Modular, extensible architecture
•Handling real-world challenges like scheduling, retries, and error management


📋 Problem Description


Organizations use Active Directory (AD) to manage user authentication, permissions, and access control.


To detect security incidents or policy violations, logs from multiple AD servers need to be collected, aggregated, and stored centrally.


You need to design an Active Directory Log Collector module that can:


•Connect to multiple AD servers
•Periodically fetch logs
•Normalize and store logs for analysis
•Handle errors, duplicates, and retries gracefully


🧱 Functional Requirements


1.Server Registration:
•Support adding/removing AD servers to the collector configuration.
2.Log Fetching:
•Fetch logs (e.g., user login events, failed authentications, group changes) from AD servers periodically.
3.Parsing and Normalization:
•Convert logs from various formats into a consistent internal structure.
4.Storage:
•Store normalized logs in a local repository (e.g., file, database, or queue).
5.Error Handling & Retry:
•If log retrieval fails, retry with exponential backoff.
6.Scheduling:
•Fetch logs periodically (e.g., every 5 minutes).
7.Metrics & Monitoring:
•Expose statistics (e.g., number of logs collected, failed attempts).


⚙️ Non-Functional Requirements


AspectDescription


Scalability


Support multiple AD servers concurrently


Reliability


Ensure no logs are lost during network failures


Extensibility


Easy to add new log types or data sources


Maintainability


Clean, modular class design


Performance



Efficiently process large log volumes


🧩 Key System Components

Component and Responsibility


CollectorManager

Manages configuration and lifecycle of collectors


ADCollector

Connects to a single AD server, fetches logs


LogParser

Parses raw AD logs into structured objects


LogStorage

Handles storage (DB/File/Queue)


Scheduler

Triggers periodic collection


ErrorHandler

Handles retries and failure reporting


🧱 Example Class Structure

1 2class CollectorManager: 3 def __init__(self): 4 self.collectors = [] 5 6 def register_collector(self, ad_server): 7 collector = ADCollector(ad_server) 8 self.collectors.append(collector) 9 10 def start_all(self): 11 for collector in self.collectors: 12 collector.start_collection() 13 14 15class ADCollector: 16 def __init__(self, ad_server): 17 self.ad_server = ad_server 18 self.parser = LogParser() 19 self.storage = LogStorage() 20 21 def fetch_logs(self): 22 # Simulate fetching logs from AD via LDAP/WinRM 23 return self.ad_server.get_logs() 24 25 def start_collection(self): 26 logs = self.fetch_logs() 27 parsed_logs = self.parser.parse(logs) 28 self.storage.save(parsed_logs) 29 30 31class LogParser: 32 def parse(self, raw_logs): 33 structured_logs = [] 34 for line in raw_logs: 35 # Convert to structured format 36 structured_logs.append(self._parse_line(line)) 37 return structured_logs 38 39 def _parse_line(self, line): 40 # Extract timestamp, event type, username, etc. 41 return {"timestamp": "2025-10-24T12:00Z", "event": "Login", "user": "admin"} 42 43 44class LogStorage: 45 def save(self, logs): 46 # Could write to DB, file, or message queue 47 for log in logs: 48 print("Saving:", log)

⚙️ Data Model Example


FieldTypeDescription


timestamp

datetime

Time of the log event


event_type

string

Type of AD event (login, group_change, etc.)


user

string

User associated with the event


server

string

Source AD server


details

string/json


Additional event info


🔄 Flow of Execution


1.CollectorManager initializes collectors for each AD server.
2.Each ADCollector connects to its assigned server and fetches raw logs.
3.LogParser normalizes the raw data into structured events.
4.LogStorage persists these events to storage.
5.Scheduler periodically triggers step (2) every N minutes.
6.ErrorHandler retries failed collections or logs errors.


🧠 Design Discussion Points


•How would you design for concurrent log collection from multiple AD servers?
•How do you ensure idempotency (avoid reprocessing duplicate logs)?
•What mechanisms ensure fault tolerance if one AD server goes down?
•How would you make the collector pluggable for different log sources (e.g., AWS CloudTrail)?
•How would you integrate this collector with Kafka / ELK Stack downstream?


🧾 Example API Design (Optional)


Method, Endpoint and Description


POST

/servers/register

Register a new AD server


GET

/logs/recent

Retrieve latest collected logs


GET

/metrics

View collection stats


DELETE

/servers/{id}

Deregister an AD server


✅ Deliverables


•UML class diagram for core components
•Sequence diagram of the collection process
•Sample class skeletons (Collector, Parser, Storage)
•Discussion on concurrency and fault tolerance


🚀 Stretch Goals


•Implement multi-threaded or async collectors
•Add log filtering (e.g., only failed login events)
•Include real-time stream processing (e.g., via Kafka)
•Add metrics exporter for Prometheus


Solution

Comments