How pkanderi-abio/monitoring works
Purpose and Entry Points
This repository implements a containerized real-time MDR/XDR pipeline: ingest host and AWS CloudTrail activity, stream events through Kafka, detect threats, distribute alerts, and expose operational/dashboard views. The Python service starts through app/main.py; HTTP/WebSocket endpoints are defined in app/api.py. Deployment topology is defined by docker-compose.yml.
Event Ingestion and Streaming
app/monitoring.py watches the configured local authentication log and collects cloud events using configured AWS credentials. It normalizes incoming records and hands them to Kafka publishing logic in app/kafka_handler.py. Kafka is the central decoupling boundary between producers and the detection consumer, allowing event sources and analysis throughput to scale independently.
• app/monitoring.py
• app/kafka_handler.py
• docker-compose.yml
Detection Pipeline
The Kafka consumer receives events and invokes the detection orchestration in app/detection.py. Detection combines known-pattern/rule checks, Isolation Forest anomaly analysis, and compliance-oriented checks such as privileged-access and policy violations. This module is the primary decision boundary: benign events end processing; detected events become alert records.
• app/detection.py
• app/kafka_handler.py
• app/utils.py
Alert Persistence and Notifications
Detected threats flow into alert handling in app/alerting.py, which persists alert history to the configured JSON file and sends external notifications. Slack webhook delivery and SMTP email are controlled through environment-backed settings in app/config.py. The persisted alert file is a cross-service handoff consumed by Logstash.
• app/alerting.py
• app/config.py
• data/alerts.json
Dashboard and Real-Time API
The Python backend serves the monitoring dashboard and exposes alert data/control channels, including WebSocket-based real-time updates. The browser UI is implemented as a server-rendered template, while API behavior and connection management reside in the application layer.
• app/api.py
• app/templates/dashboard.html
• app/main.py
Observability and ELK Export
The service emits Prometheus metrics for detection/alert activity; Prometheus scraping is configured in prometheus.yml. Logstash tails or reads the persisted alert stream and indexes it into Elasticsearch, with Kibana providing downstream search and visualization. This creates two observability paths: Prometheus for service health/metrics and ELK for alert investigation.
• prometheus.yml
• logstash.conf
• docker-compose.yml
Runtime and Infrastructure Boundaries
The primary runtime is a Python application packaged by Dockerfile. Docker Compose provisions the application alongside Kafka/Zookeeper, Elasticsearch, Logstash, Kibana, and Prometheus. External dependencies include AWS CloudTrail APIs, Slack webhooks, and an SMTP server; secrets and endpoint configuration originate from .env based on .env.example.
• Dockerfile
• docker-compose.yml
• .env.example
Main entry points: alerting.py Alert handling · docker-compose.yml Docker Compose · kafka_handler.py Kafka producer/consumer · main.py Python runtime
Components 20
Python service
Containerized MDR/XDR application.
- Python runtime
app/main.py - HTTP & WebSocket API
app/api.py - Monitoring dashboard
app/templates/dashboard.html - Alert handling · Persists detected threats and sends notifications.
app/alerting.py - Environment settings · Provides notification credentials and endpoints.
app/config.py - Alert history · Cross-service handoff for alert investigation.
data/alerts.json
Event pipeline
Decoupled ingestion and threat detection.
- Host & CloudTrail ingestion · Watches authentication logs and collects AWS activity.
app/monitoring.py - Kafka producer/consumer
app/kafka_handler.py - Kafka · Decouples event producers from detection throughput.
docker-compose.yml - Threat detection · Runs rules, anomaly analysis, and compliance checks.
app/detection.py - Detection utilities
app/utils.py
Observability
Metrics and alert investigation paths.
- Prometheus metrics
app/main.py - Prometheus
prometheus.yml - Logstash
logstash.conf - Elasticsearch
docker-compose.yml - Kibana
docker-compose.yml
External services
- AWS CloudTrail APIs
- Slack webhook
- SMTP server
Other components
- Docker Compose · Provisions the application and supporting services.
docker-compose.yml
Connections 23
- Docker Compose → Python runtime: runs
- Docker Compose → Kafka: provisions
- Docker Compose → Elasticsearch: provisions
- Docker Compose → Kibana: provisions
- Python runtime → HTTP & WebSocket API: serves
- HTTP & WebSocket API → Monitoring dashboard: renders
- HTTP & WebSocket API → Alert history: reads alerts
- AWS CloudTrail APIs → Host & CloudTrail ingestion: CloudTrail events
- Host & CloudTrail ingestion → Kafka producer/consumer: normalized events
- Kafka producer/consumer → Kafka: publishes
- Kafka → Kafka producer/consumer: consumes
- Kafka producer/consumer → Threat detection: events
- Threat detection → Detection utilities: analysis helpers
- Threat detection → Alert handling: detected threats
- Alert handling → Alert history: persists
- Environment settings → Alert handling: notification settings
- Alert handling → Slack webhook: webhook alert
- Alert handling → SMTP server: email alert
- Python runtime → Prometheus metrics: emits
- Prometheus → Prometheus metrics: scrapes
- Alert history → Logstash: alert stream
- Logstash → Elasticsearch: indexes
- Kibana → Elasticsearch: searches