Zabbix MCP Server
Middleware service sử dụng Model Context Protocol để phân tích và tự động hóa các sự kiện Zabbix với AI.
Tính năng
- Phân tích sự kiện Zabbix bằng AI (OpenAI/Ollama)
- Tự động hóa phản hồi sự cố
- Tích hợp với n8n cho workflow automation
- Caching và Rate Limiting
- Health Check System
- Logging System
- Unit Tests
- API Documentation
Yêu cầu hệ thống
Cài đặt bằng Docker
- Docker 20.10+
- Docker Compose 2.0+
- 4GB RAM trở lên
- 20GB ổ cứng trống
Cài đặt
Cài đặt bằng Docker (Khuyến nghị)
- Clone repository:
git clone https://github.com/thichcode/zabbix_mcp.git
cd zabbix_mcp
- Cấu hình môi trường:
cp .env.example .env
# Chỉnh sửa file .env với cấu hình của bạn
- Build và chạy containers:
docker-compose up -d
- Kiểm tra logs:
docker-compose logs -f app
- Kiểm tra health:
curl http://localhost:8000/api/v1/health
Cài đặt thủ công
- Clone repository:
git clone https://github.com/thichcode/zabbix_mcp.git
cd zabbix_mcp
- Tạo và kích hoạt môi trường ảo:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
- Cài đặt dependencies:
pip install -r requirements.txt
- Cấu hình môi trường:
cp .env.example .env
# Chỉnh sửa file .env với cấu hình của bạn
- Cài đặt và cấu hình MongoDB:
# Ubuntu/Debian
sudo apt-get install mongodb
sudo systemctl start mongodb
# Windows
# Tải và cài đặt từ https://www.mongodb.com/try/download/community
- Cài đặt và cấu hình Redis:
# Ubuntu/Debian
sudo apt-get install redis-server
sudo systemctl start redis-server
# Windows
# Tải từ https://github.com/microsoftarchive/redis/releases
- Cấu hình Zabbix:
# Chạy script cấu hình
python scripts/setup_zabbix.py
Chạy ứng dụng
Docker
# Khởi động
docker-compose up -d
# Dừng
docker-compose down
# Xem logs
docker-compose logs -f app
# Restart
docker-compose restart app
Thủ công
- Chạy tests:
pytest tests/
- Chạy server:
uvicorn app.main:app --reload
- Kiểm tra health:
curl http://localhost:8000/api/v1/health
- Xem logs:
tail -f logs/api_*.log
Cấu hình Docker
Volumes
mongodb_data
: Lưu trữ dữ liệu MongoDBredis_data
: Lưu trữ dữ liệu Redisollama_data
: Lưu trữ models Ollama./logs
: Log files./.env
: Environment variables
Networks
zabbix_network
: Network cho các services
Ports
8000
: API server27017
: MongoDB6379
: Redis11434
: Ollama (tùy chọn)
API Endpoints
GET /api/v1/health
: Kiểm tra trạng thái hệ thốngPOST /api/v1/webhook
: Webhook endpoint cho ZabbixGET /docs
: API documentation (Swagger UI)
Cấu trúc dự án
zabbix_mcp/
├── app/
│ ├── api/
│ │ ├── webhook.py
│ │ └── health.py
│ ├── core/
│ │ └── logging.py
│ ├── models/
│ │ └── event.py
│ ├── services/
│ │ ├── analysis.py
│ │ ├── auth_service.py
│ │ ├── cache_service.py
│ │ ├── database.py
│ │ ├── deep_research.py
│ │ └── ollama_service.py
│ └── main.py
├── tests/
│ └── test_analysis.py
├── scripts/
│ └── setup_zabbix.py
├── logs/
├── .env.example
├── .gitignore
├── Dockerfile
├── docker-compose.yml
├── README.md
└── requirements.txt
Monitoring
- Health Check:
/api/v1/health
- Logs:
logs/
directory hoặcdocker-compose logs
- Metrics: Prometheus metrics (coming soon)
Development
- Cài đặt development dependencies:
pip install -r requirements-dev.txt
- Chạy code formatting:
black .
isort .
- Chạy linting:
flake8
mypy .
- Chạy tests với coverage:
pytest --cov=app tests/
Contributing
- Fork repository
- Tạo branch mới
- Commit changes
- Push lên branch
- Tạo Pull Request
License
MIT License