A vigilant messenger that watches over your Docker containers and reports their status to Slack. Like a digital herald for your containerized applications, Harbinger provides real-time notifications about container lifecycle events.
- 📊 Real-time monitoring of Docker container events
- 🐳 Support for both standalone containers and docker-compose services
- 🔔 Elegant Slack notifications with detailed container information
- 📝 Automatic log capture when containers exit
- 🎨 Color-coded status messages for different events
- ⚡ Low overhead and resource usage
- 🛠️ Easy configuration through environment variables
- Python 3.6+
- Docker Engine
- Slack Webhook URL
- Linux environment (tested on Ubuntu)
- Clone the repository
git clone https://github.com/luis15pt/Harbinger.git
cd Harbinger
- Configure environment variables
# Create .env file
cp .env.example .env
# Edit your configuration
vim .env
- Run as a service
#make sure to change the path to the script
vim harbinger.service
# Copy service file
sudo cp harbinger.service /etc/systemd/system/
# Enable and start service
sudo systemctl enable harbinger
sudo systemctl start harbinger
- Check if its running
#Check the logs
sudo journalctl -u harbinger -f
Create a .env
file with the following variables:
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
MONITOR_ENV=production
MONITOR_HOST=your-host-name
LOG_LINES=5
Harbinger provides detailed, color-coded notifications for various container events:
- 🟢 Container starts
Harbinger can be run as a systemd service for reliable operation:
[Unit]
Description=Harbinger Docker Monitor
After=docker.service
Requires=docker.service
[Service]
Type=simple
User=root
Group=docker
Environment=PYTHONUNBUFFERED=1
WorkingDirectory=/path/to/Harbinger
ExecStart=/usr/bin/python3 harbinger.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Monitor Harbinger's operation through its logs:
# View service logs
sudo journalctl -u harbinger -f
# Check application logs
tail -f /var/log/harbinger.log
Harbinger automatically detects and provides additional context for docker-compose services, including:
- Project name
- Service name
- Container relationships
- Compose-specific events
After setting up Harbinger, you can verify it's working correctly using these test scenarios:
# Start a test container that exits immediately
docker run --name test-container alpine echo "Hello Harbinger!"
# This will trigger both START and EXIT notifications
# Run a container that generates multiple log lines
docker run --name test-logs alpine sh -c '
echo "Starting application..."
echo "Loading configuration..."
echo "Simulating error..."
exit 1
'
# This will show EXIT notification with logs
# Simulate a container crash with error code
docker run --name test-crash alpine sh -c '
echo "Running..."
sleep 1
echo "About to crash..."
kill -9 1
'
# This will trigger an error exit notification
# Create a test docker-compose.yml file
cat << EOF > test-compose.yml
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
EOF
# Start the service
docker-compose -f test-compose.yml up -d
# Wait a few seconds, then stop it
docker-compose -f test-compose.yml down
# Test container with memory limit
docker run --name test-oom \
--memory=10m \
alpine sh -c 'cat /dev/zero > /dev/null'
# This will trigger an OOM (Out of Memory) exit
# Start a container
docker run -d --name test-kill alpine sleep 3600
# Wait a moment, then kill it
docker kill test-kill
# This will show a KILLED notification
# Remove all test containers
docker rm -f test-container test-logs test-crash test-oom test-kill 2>/dev/null
# Remove test compose file
rm test-compose.yml
Each test will generate different types of notifications in Slack, allowing you to verify:
- 📥 Container start notifications
- 📤 Clean exit notifications
- ❌ Error notifications with logs
- 💾 Memory limit violations
- 🚫 Container kill events
- 🐳 Docker Compose events
Expected Notifications:
- Start events will show green indicators
- Clean exits will show normal status
- Error exits will show red indicators with logs
- OOM kills will show error status with memory information
- Compose events will include service context
Monitor the logs while testing:
# Watch Harbinger logs
sudo journalctl -u harbinger -f
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Luis Sarabando
- GitHub: @luissarabando
- Thanks to the Docker team for their excellent API
- Inspired by the need for better container monitoring
- Built with Python and ❤️
May Harbinger watch over your containers with unwavering vigilance.