# alarm-server **Repository Path**: sdffly/alarm-server ## Basic Information - **Project Name**: alarm-server - **Description**: 一体化运维告警平台 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-05 - **Last Updated**: 2026-01-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 告警平台 (Alarm Server) 一个统一的告警接收和处理平台,支持多源数据接入,自动转换为统一格式,并支持发送到钉钉、飞书等webhook。 ## 功能特性 - ✅ **多源数据接入**:支持 Prometheus、Zabbix、Grafana、Elasticsearch 等多种监控系统 - ✅ **统一格式转换**:自动将不同格式的告警转换为平台统一格式 - ✅ **告警去重**:基于指纹自动识别重复告警 - ✅ **静默规则**:支持基于标签匹配的告警静默 - ✅ **抑制规则**:支持告警抑制(当源告警触发时,抑制目标告警) - ✅ **告警认领**:支持告警认领功能 - ✅ **排班管理**:支持值班排班计划 - ✅ **Webhook通知**:支持配置多个钉钉、飞书等webhook ## 快速开始 ### 1. 配置 复制示例配置文件并修改: ```bash cp config.json.example config.json ``` 编辑 `config.json`,配置webhook地址: ```json { "server": { "port": ":8080", "read_timeout": 30, "write_timeout": 30 }, "webhooks": [ { "name": "钉钉告警群", "type": "dingtalk", "url": "https://oapi.dingtalk.com/robot/send?access_token=YOUR_TOKEN", "enabled": true } ] } ``` ### 2. 运行 ```bash go run main.go ``` 或编译后运行: ```bash go build -o alarm-server ./alarm-server ``` ## API 接口 ### 告警接收 #### 标准格式接口 ```bash POST /api/alarm Content-Type: application/json { "source": "custom", "level": "critical", "title": "告警标题", "content": "告警内容", "status": "firing", "timestamp": 1234567890, "labels": { "host": "server1", "service": "web" }, "annotations": {}, "extra": {} } ``` #### Prometheus Alertmanager ```bash POST /webhook/prometheus ``` #### Zabbix ```bash POST /webhook/zabbix ``` #### Grafana ```bash POST /webhook/grafana ``` #### Elasticsearch ```bash POST /webhook/elasticsearch ``` #### 通用格式 ```bash POST /webhook/generic ``` ### 告警管理 #### 认领告警 ```bash POST /api/alarm/claim Content-Type: application/json { "alarm_id": "alarm-xxx", "owner": "张三", "comment": "正在处理" } ``` #### 获取当前值班人员 ```bash GET /api/oncall/current ``` ### 规则管理 #### 创建静默规则 ```bash POST /api/rule/silence Content-Type: application/json { "name": "维护窗口静默", "matchers": { "service": "web", "environment": "prod" }, "start_time": "2024-01-01T00:00:00Z", "end_time": "2024-01-01T02:00:00Z", "creator": "admin", "comment": "系统维护" } ``` #### 创建抑制规则 ```bash POST /api/rule/suppression Content-Type: application/json { "name": "抑制规则示例", "description": "当主机宕机时,抑制该主机上的所有告警", "source_matchers": { "alertname": "HostDown" }, "target_matchers": { "host": "server1" }, "equal_labels": ["host"] } ``` #### 创建排班计划 ```bash POST /api/rule/schedule Content-Type: application/json { "name": "工作日排班", "team_name": "运维团队", "start_time": "2024-01-01T09:00:00Z", "end_time": "2024-01-01T18:00:00Z", "members": ["张三", "李四"] } ``` ### 健康检查 ```bash GET /health ``` ## 告警处理流程 1. **接收告警**:通过webhook接口接收告警 2. **格式转换**:根据数据源类型自动转换为统一格式 3. **去重检查**:基于指纹判断是否为重复告警 4. **规则匹配**:应用静默规则和抑制规则 5. **发送通知**:如果告警未被静默或抑制,发送到配置的webhook ## 告警指纹 告警指纹基于 `source + labels` 生成,相同指纹的告警会被视为同一个告警,新告警会更新已有告警。 ## 配置说明 ### Webhook类型 - `dingtalk`: 钉钉机器人 - `feishu`: 飞书机器人 ### 服务器配置 - `port`: 监听端口,格式如 `:8080` - `read_timeout`: 读取超时时间(秒) - `write_timeout`: 写入超时时间(秒) ## 开发 ### 项目结构 ``` alarm-server/ ├── main.go # 入口文件 ├── config/ # 配置管理 │ └── config.go ├── common/ # 通用模型 │ └── model.go ├── server/ │ ├── server.go # 服务器主逻辑 │ ├── handler/ # HTTP处理器 │ │ └── handler.go │ ├── service/ # 业务逻辑 │ │ └── alarm_service.go │ ├── storage/ # 存储接口 │ │ └── storage.go │ ├── model/ # 数据模型 │ │ └── alarm.go │ └── webhook/ # Webhook客户端和转换器 │ ├── client.go │ └── converter.go └── config.json # 配置文件 ``` ## License MIT