Files
LoganandClaude 76ec9387f0 feat(rdp): 新增 RDP 远程桌面/SMB/账单同步能力 + 清理编译产物
主要变更:
- RDP 远程桌面:新增 backend/pkg/rdp(RDP 引擎 + credssp/display/rle/trace)、
  backend/controller/rdp*(连接/凭证/文件/会话/实时)、frontend RDP 组件与 API
- Windows SMB 文件传输:backend/pkg/winsmb
- 云账单同步:backend/pkg/billingsync + billing_sync/aliyun_billing,前端账单详情
- Agent CLI Kubernetes 工具:kubernetes_action/get、pod_execute/logs
- 服务器导入助手:server_import_helpers、ImportCredentialSettings
- 国际化与组件重构(cloud/deploy/monitor/server/system 等多模块)
- 清理编译产物二进制:移除 backend/server、backend/agent/bin/aiops-agent-*
- .gitignore:新增 backend/agent/ 与 .cache/(避免 334MB go-build 缓存误入库)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-04 01:50:36 +08:00

305 lines
8.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AIOps 后端服务
AIOps 是一个专业的 AIOps 智能运维平台后端服务,基于 Go + Gin 框架开发。
## 功能特性
### 核心模块
- **用户管理**: 用户认证、角色权限管理
- **资产管理**: 服务器资产、云账号、域名管理
- **Kubernetes 管理**: 集群、节点、Pod、Deployment、Service、Ingress 管理
- **监控告警**: 告警规则、告警事件、通知渠道
- **应用发布**: CI/CD 流水线、发布审批
- **自动化运维**: 定时任务、脚本管理、任务执行
- **审批流程**: 审批模板、审批流程管理
- **站内导航**: 导航分组、链接管理
- **审计日志**: 操作日志记录、查询、统计
## 技术栈
- **框架**: Gin Web Framework
- **ORM**: GORM
- **数据库**: MySQL / PostgreSQL
- **缓存**: Redis (可选)
- **认证**: JWT
- **日志**: Zap
- **配置**: Viper
- **文档**: Swagger
## 快速开始
### 环境要求
- Go 1.21+
- MySQL 8.0+ 或 PostgreSQL 14+
- Redis 6.0+ (可选)
### 安装依赖
```bash
cd backend
go mod download
```
### 配置
1. 复制配置文件示例:
```bash
cp config.yaml.example config.yaml
```
2. 编辑 `config.yaml`,根据实际情况修改数据库等配置
### 数据库初始化
```bash
# 创建数据库
mysql -u root -p -e "CREATE DATABASE ezops CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
# 或者使用 PostgreSQL
# createdb -U postgres ezops
```
### 运行
```bash
# 开发模式
go run cmd/main.go
# 或者编译后运行
go build -o ezops cmd/main.go
./ezops
```
服务启动后,访问 http://localhost:8080 查看 API 文档。
## API 文档
启动服务后,可以通过以下地址访问 Swagger API 文档:
- Swagger UI: http://localhost:8080/swagger/index.html
- API 规范: http://localhost:8080/swagger/doc.json
## 项目结构
```
backend/
├── cmd/
│ └── main.go # 应用入口
├── internal/
│ ├── api/
│ │ ├── handlers/ # HTTP 处理器
│ │ ├── middleware/ # 中间件
│ │ └── routes/ # 路由注册
│ ├── config/ # 配置管理
│ └── models/ # 数据模型
├── pkg/
│ ├── database/ # 数据库连接
│ └── logger/ # 日志工具
├── config.yaml.example # 配置文件示例
├── go.mod # Go 模块定义
├── go.sum # Go 模块校验
└── README.md # 项目说明
```
## API 路由
### 认证相关
- `POST /api/v1/auth/login` - 用户登录
- `POST /api/v1/auth/register` - 用户注册
- `GET /api/v1/user/profile` - 获取用户信息
- `PUT /api/v1/user/profile` - 更新用户信息
- `PUT /api/v1/user/password` - 修改密码
### 用户管理 (管理员)
- `GET /api/v1/admin/users` - 用户列表
- `GET /api/v1/admin/users/:id` - 用户详情
- `POST /api/v1/admin/users` - 创建用户
- `PUT /api/v1/admin/users/:id` - 更新用户
- `DELETE /api/v1/admin/users/:id` - 删除用户
### 仪表盘
- `GET /api/v1/dashboard/stats` - 统计数据
- `GET /api/v1/dashboard/recent-alerts` - 最近告警
- `GET /api/v1/dashboard/recent-releases` - 最近发布
- `GET /api/v1/dashboard/metrics` - 指标数据
### 服务器管理
- `GET /api/v1/servers` - 服务器列表
- `GET /api/v1/servers/stats` - 服务器统计
- `GET /api/v1/servers/:id` - 服务器详情
- `POST /api/v1/servers` - 创建服务器
- `PUT /api/v1/servers/:id` - 更新服务器
- `DELETE /api/v1/servers/:id` - 删除服务器
- `POST /api/v1/servers/batch-delete` - 批量删除
### 云账号管理
- `GET /api/v1/cloud-accounts` - 云账号列表
- `POST /api/v1/cloud-accounts` - 创建云账号
- `DELETE /api/v1/cloud-accounts/:id` - 删除云账号
### 域名管理
- `GET /api/v1/domains` - 域名列表
- `POST /api/v1/domains` - 创建域名
- `DELETE /api/v1/domains/:id` - 删除域名
### Kubernetes 管理
- `GET /api/v1/k8s-clusters` - 集群列表
- `GET /api/v1/k8s-clusters/:id` - 集群详情
- `POST /api/v1/k8s-clusters` - 创建集群
- `PUT /api/v1/k8s-clusters/:id` - 更新集群
- `DELETE /api/v1/k8s-clusters/:id` - 删除集群
- `GET /api/v1/k8s-clusters/:id/nodes` - 节点列表
- `GET /api/v1/k8s-clusters/:id/pods` - Pod 列表
- `GET /api/v1/k8s-clusters/:id/deployments` - Deployment 列表
- `GET /api/v1/k8s-clusters/:id/services` - Service 列表
- `GET /api/v1/k8s-clusters/:id/ingresses` - Ingress 列表
### 监控告警
- `GET /api/v1/alerts` - 告警事件列表
- `GET /api/v1/alerts/rules` - 告警规则列表
- `POST /api/v1/alerts/rules` - 创建告警规则
- `PUT /api/v1/alerts/rules/:id` - 更新告警规则
- `DELETE /api/v1/alerts/rules/:id` - 删除告警规则
- `POST /api/v1/alerts/rules/:id/toggle` - 启用/禁用规则
- `POST /api/v1/alerts/:id/ack` - 确认告警
### 应用发布
- `GET /api/v1/pipelines` - 流水线列表
- `POST /api/v1/pipelines` - 创建流水线
- `GET /api/v1/pipelines/:id` - 流水线详情
- `PUT /api/v1/pipelines/:id` - 更新流水线
- `DELETE /api/v1/pipelines/:id` - 删除流水线
- `POST /api/v1/pipelines/:id/trigger` - 触发流水线
- `GET /api/v1/pipelines/:id/runs` - 运行记录
- `GET /api/v1/releases` - 发布列表
- `POST /api/v1/releases` - 创建发布
- `POST /api/v1/releases/:id/approve` - 审批发布
- `POST /api/v1/releases/:id/deploy` - 执行发布
- `POST /api/v1/releases/:id/rollback` - 回滚发布
### 自动化运维
- `GET /api/v1/cron-jobs` - 定时任务列表
- `POST /api/v1/cron-jobs` - 创建定时任务
- `GET /api/v1/cron-jobs/:id` - 定时任务详情
- `PUT /api/v1/cron-jobs/:id` - 更新定时任务
- `DELETE /api/v1/cron-jobs/:id` - 删除定时任务
- `POST /api/v1/cron-jobs/:id/toggle` - 启用/禁用任务
- `POST /api/v1/cron-jobs/:id/execute` - 立即执行
- `GET /api/v1/scripts` - 脚本列表
- `POST /api/v1/scripts` - 创建脚本
- `GET /api/v1/scripts/:id` - 脚本详情
- `PUT /api/v1/scripts/:id` - 更新脚本
- `DELETE /api/v1/scripts/:id` - 删除脚本
- `POST /api/v1/scripts/:id/execute` - 执行脚本
### 审批流程
- `GET /api/v1/approvals/templates` - 审批模板列表
- `POST /api/v1/approvals/templates` - 创建审批模板
- `GET /api/v1/approvals/templates/:id` - 模板详情
- `PUT /api/v1/approvals/templates/:id` - 更新模板
- `DELETE /api/v1/approvals/templates/:id` - 删除模板
- `GET /api/v1/approvals/processes` - 审批流程列表
- `POST /api/v1/approvals/processes` - 创建审批流程
- `GET /api/v1/approvals/processes/:id` - 流程详情
- `POST /api/v1/approvals/processes/:id/approve` - 审批通过
- `POST /api/v1/approvals/processes/:id/reject` - 审批驳回
### 站内导航
- `GET /api/v1/navigations/groups` - 导航分组列表
- `POST /api/v1/navigations/groups` - 创建分组
- `PUT /api/v1/navigations/groups/:id` - 更新分组
- `DELETE /api/v1/navigations/groups/:id` - 删除分组
- `GET /api/v1/navigations/links` - 导航链接列表
- `POST /api/v1/navigations/links` - 创建链接
- `PUT /api/v1/navigations/links/:id` - 更新链接
- `DELETE /api/v1/navigations/links/:id` - 删除链接
- `POST /api/v1/navigations/links/:id/favorite` - 收藏/取消收藏
### 审计日志
- `GET /api/v1/audit/logs` - 审计日志列表
- `GET /api/v1/audit/logs/:id` - 日志详情
- `GET /api/v1/audit/modules` - 模块列表
- `GET /api/v1/audit/actions` - 操作类型列表
- `GET /api/v1/audit/logs/export` - 导出日志
- `GET /api/v1/audit/statistics` - 统计信息
- `POST /api/v1/audit/logs/clear` - 清理日志
## 开发指南
### 添加新的 API
1. 在 `internal/models/` 下定义数据模型
2. 在 `internal/api/handlers/` 下创建处理器
3. 在 `internal/api/routes/routes.go` 中注册路由
### 生成 Swagger 文档
```bash
go install github.com/swaggo/swag/cmd/swag@latest
swag init -g cmd/main.go
```
## 部署
### Docker 部署
```dockerfile
FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY . .
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o ezops cmd/main.go
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/ezops .
COPY config.yaml .
EXPOSE 8080
CMD ["./ezops"]
```
构建并运行:
```bash
docker build -t ezops-backend .
docker run -p 8080:8080 -v $(pwd)/config.yaml:/root/config.yaml ezops-backend
```
### 生产环境建议
1. 使用反向代理(Nginx/Traefik)
2. 配置 HTTPS
3. 使用环境变量覆盖配置文件
4. 配置日志轮转
5. 启用数据库连接池
6. 配置监控告警
## 贡献指南
1. Fork 本仓库
2. 创建特性分支 (`git checkout -b feature/xxx`)
3. 提交更改 (`git commit -am 'Add xxx'`)
4. 推送到分支 (`git push origin feature/xxx`)
5. 创建 Pull Request
## 许可证
GNU General Public License v3.0 or later (GPL-3.0-or-later). See the root `LICENSE` file.