shivamrkm/minonops

GitHub: shivamrkm/minonops

基于 Kibana Agent Builder 的自主事件响应系统,能自动检测异常、调查根因、生成代码修复并创建 GitHub PR。

Stars: 0 | Forks: 0

# 🤖 MinionOPS — 自主事件响应系统 基于 **Kibana Agent Builder** 的多智能体系统,可自主检测异常、调查事件、生成代码修复并创建 GitHub Pull Request。 ## 架构 (v2.0 — Kibana-Native) ``` ┌─────────────────────────────────────────────────────────────┐ │ KIBANA AGENT BUILDER │ │ MinionOPS Commander │ │ │ │ System Prompt (6-step pipeline) │ │ | │ │ ▼ │ │ ┌──────────────────────────────────────────────────────┐ │ │ │ ES|QL Tools (read from Elasticsearch) │ │ │ │ ┌─────────────────┐ ┌──────────────────────────┐ │ │ │ │ │ detect_anomaly │ │ search_runbooks │ │ │ │ │ └─────────────────┘ └──────────────────────────┘ │ │ │ │ ┌──────────────────────────────────────────────────┐ │ │ │ │ │ search_incident_history │ │ │ │ │ └──────────────────────────────────────────────────┘ │ │ │ └───────────────────────────────────────────────────────┘ │ │ │ │ Action Tools (via FastAPI backend) │ │ ┌───────────────────┐ ┌───────────────┐ ┌───────────────┐│ │ │generate_code_patch│ │ open_github_pr│ │ notify_slack │| │ └───────────────────┘ └───────────────┘ └───────────────┘│ └──────────────────────────────┬──────────────────────────────┘ │ reads/writes ┌───────────────▼───────────────┐ │ Elasticsearch │ │ ┌─────────────────────────┐ │ │ │ incidents-minionops │ │ │ │ runbooks-minionops │ │ │ │ logs-payments-minionops│ │ │ └─────────────────────────┘ │ └───────────────▲───────────────┘ │ writes logs ┌───────────────┴───────────────┐ │ ingestion/main.go (Go) │ │ t=0–20min: normal logs │ │ t=21+min: fault injection │ │ (21% NullPointerException) │ └───────────────────────────────┘ ``` ## 快速开始 (模拟模式) ``` cp .env.example .env docker compose up --build -d curl http://localhost:8000/health curl -X POST http://localhost:8000/trigger-incident | python -m json.tool ``` ## 完整生产部署 ### 前置条件 | 服务 | 免费? | 用途 | |---------|-------|---------| | Elasticsearch Serverless | ✅ 免费试用 | 数据存储 + Kibana Agent | | Gemini API | ✅ 免费层级 | 代码补丁生成 | | GitHub (PAT) | ✅ 免费 | 创建草稿 PR | | Slack (webhook) | ✅ 免费 | 事件通知 | ### 步骤 1 — 创建模拟 Java 仓库 Agent 需要一个真实的 GitHub 仓库来提交 PR: 1. 在 GitHub 上创建一个名为 `payments-service-stub` 的 **公开** 仓库 2. 推送本项目 `payments-service-stub/` 文件夹中的内容: cd payments-service-stub git init git add . git commit -m "Initial commit — PaymentService with known NPE bug at line 123" git remote add origin https://github.com/YOUR_USERNAME/payments-service-stub.git git push -u origin main ### 步骤 2 — 获取 API Keys | Key | 来源 | |-----|-------| | `ES_URL` + `ES_API_KEY` | Elastic Cloud → View Connection Details | | `KIBANA_URL` + `KIBANA_API_KEY` | Serverless 上与 ES URL 相同 | | `GEMINI_API_KEY` | [aistudio.google.com](https://aistudio.google.com) → Get API Key | | `GITHUB_TOKEN` | GitHub → Settings → Developer Settings → PAT (classic) → `repo` scope | | `SLACK_WEBHOOK_URL` | [api.slack.com/apps](https://api.slack.com/apps) → Incoming Webhooks | ### 步骤 3 — 配置 `.env` ``` ES_URL=https://your-project.es.us-central1.gcp.cloud.es.io ES_API_KEY=your_api_key KIBANA_URL=https://your-project.es.us-central1.gcp.cloud.es.io KIBANA_API_KEY=your_api_key GITHUB_TOKEN=ghp_your_token GITHUB_REPO=yourusername/payments-service-stub SLACK_TOKEN=xoxe.xoxp-your-oauth-token SLACK_CHANNEL=#general GEMINI_API_KEY=your_gemini_key SIMULATION_MODE=false ``` ### 步骤 4 — 初始化 Elasticsearch (Dev Tools) 在 **Kibana → Dev Tools → Console** 中运行以下命令: ``` PUT incidents-minionops/_doc/INC-SIM-001 { "incident_id": "INC-SIM-001", "anomaly_score": 92.4, "error_rate": 0.21, "service": "payments", "endpoint": "/pay", "top_errors": "NullPointerException at PaymentService.java:123", "timestamp": "2026-02-25T16:30:00.000Z", "status": "detected", "diagnosis": "deployment_regression", "resolution": "Added null check at PaymentService.java:123, deployed hotfix v2.1.1", "time_to_resolve": "45m" } ``` ``` PUT runbooks-minionops/_doc/RB-001 { "runbook_id": "RB-001", "title": "NullPointerException Fix — Payment Service", "error_type": "NullPointerException", "fix_steps": "1. Add null check at PaymentService.java:123\n2. Wrap object access in Optional\n3. Deploy hotfix branch\n4. Monitor error rate — should drop below 1%", "estimated_fix_time": "30m" } ``` ``` PUT logs-payments-minionops { "mappings": { "properties": { "@timestamp": { "type": "date" }, "service": { "type": "keyword" }, "endpoint": { "type": "keyword" }, "status_code": { "type": "integer" }, "error_message": { "type": "text" }, "response_time_ms": { "type": "integer" }, "user_id": { "type": "keyword" }, "request_id": { "type": "keyword" } } } } ``` ### 步骤 5 — 设置 Kibana Agent Builder 请参阅 `ELASTICSEARCH_FULL_REFERENCE.md` 获取完整的 agent 配置、系统提示词和 3 个 ES|QL 工具。 ### 步骤 6 — 启动服务 ``` docker compose up --build -d ``` ### 步骤 7 — 启动日志生成器 (故障注入) ``` docker compose --profile generate up log-generator ``` 等待约 20 分钟建立基线,随后故障注入将自动开始。 ### 步骤 8 — 触发流水线 ``` curl -X POST http://localhost:8000/trigger-incident | python -m json.tool ``` **预期结果:** - ✅ Kibana Agent 使用 ES|QL 工具调查事件 - ✅ Gemini 生成 Java 代码补丁 - ✅ 在 `payments-service-stub` 上创建草稿 PR - ✅ 发送包含事件详情的 Slack 通知 ## 项目结构 ``` MinionOPS/ ├── docker-compose.yml # Backend + mocks + log-generator ├── .env.example # Configuration template ├── README.md │ ├── backend/ # FastAPI (Kibana orchestrator + action tools) │ ├── Dockerfile │ ├── requirements.txt │ ├── main.py # Calls Kibana Agent API → actions │ ├── models/ │ │ └── incident.py # Pydantic types │ └── minions/ │ ├── code_gen.py # Gemini Java patch generator │ ├── github_pr.py # GitHub Contents API + draft PR │ ├── slack.py # Slack OAuth notification │ └── verifier.py # Background resolution check │ ├── ingestion/ # Go log generator (fault injection) │ ├── Dockerfile │ └── main.go │ ├── payments-service-stub/ # Fake Java repo (push to GitHub) │ ├── README.md │ └── src/PaymentService.java # Intentional NPE bug at line 123 │ ├── IMPLEMENTATION_DETAILS.md # From-scratch recreation guide ├── ELASTICSEARCH_CHANGES.md # Full migration changelog ├── ELASTICSEARCH_FULL_REFERENCE.md # ES setup reference └── FINAL_PRODUCTION_SETUP.md # Production deployment steps ``` ## 安全防护机制 - ✅ PR 始终以 **草稿** 形式开启 —— 绝不自动合并 - ✅ 仅当置信度 ≥ 85% 时才生成代码补丁 - ✅ 当服务不可用时,流水线会优雅降级 - ✅ 所有步骤均记录日志以保证可观测性 ## 技术栈 | 组件 | 技术 | |-----------|------------| | 智能核心 | Kibana Agent Builder (ES|QL tools) | | 代码修补 | Gemini 2.0 Flash | | 日志采集 | Go (实时故障注入) | | PR 创建 | GitHub REST API v3 | | 数据层 | Elasticsearch Serverless | | API | FastAPI (Python 3.11) | | 通知 | Slack Incoming Webhooks | | 部署 | Docker Compose |
标签:AIOps平台, AI运维, CISA项目, DevSecOps, DLL 劫持, Elasticsearch Serverless, ES|QL, Gemini, GitHub PR, IP 地址批量处理, Kibana Agent Builder, PyRIT, Slack通知, 上游代理, 事件调查, 代码生成, 多智能体系统, 大语言模型, 密码管理, 异常检测, 无人值守运维, 日志审计, 根因分析, 渗透测试工具, 网络安全自动化, 自主事件响应, 自动修复, 请求拦截, 逆向工具