{ "produces": [ "application/json" ], "schemes": [ "https", "http" ], "swagger": "2.0", "info": { "description": "這是 Alert Webhooks 的 Swagger 文件(由 swag 自動產生)。", "title": "Alert Webhooks API", "contact": { "name": "API Support", "email": "vincent119@gmail.com" }, "license": { "name": "MIT", "url": "https://opensource.org/licenses/MIT" }, "version": "1.0" }, "basePath": "/api/v1", "paths": { "/api/v1/slack/level/{level}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "發送訊息到指定等級對應的 Slack 頻道", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "發送 Slack 訊息到指定等級", "parameters": [ { "type": "string", "description": "等級名稱 (例如: emergency, critical, warning, info)", "name": "level", "in": "path", "required": true }, { "description": "發送訊息請求", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/slack.SendMessageRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/api/v1/slack/rich/{channel}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "發送包含附件和字段的富文本訊息到指定 Slack 頻道", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "發送富文本 Slack 訊息", "parameters": [ { "type": "string", "description": "頻道名稱 (例如: alerts, emergency)", "name": "channel", "in": "path", "required": true }, { "description": "富文本訊息請求", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/slack.RichMessageRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/discord/channel/{channel}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "Send a message to a specific Discord channel", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "discord" ], "summary": "Send message to Discord channel", "parameters": [ { "type": "string", "description": "Discord Channel ID", "name": "channel", "in": "path", "required": true }, { "description": "Message request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/discord.SendMessageRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } } } } }, "/discord/chatid_L{level}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "Send a message to a Discord channel based on alert level", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "discord" ], "summary": "Send message to Discord level channel", "parameters": [ { "type": "string", "description": "Alert Level (0-5)", "name": "level", "in": "path", "required": true }, { "description": "Message request", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/discord.SendMessageRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } } } } }, "/discord/status": { "get": { "security": [ { "BasicAuth": [] } ], "description": "Get the status of Discord service and bot information", "produces": [ "application/json" ], "tags": [ "discord" ], "summary": "Get Discord service status", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/discord.StatusResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/discord.StatusResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/discord.StatusResponse" } } } } }, "/discord/test/{channel}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "Send a test message to verify channel accessibility", "tags": [ "discord" ], "summary": "Test Discord channel", "parameters": [ { "type": "string", "description": "Discord Channel ID", "name": "channel", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } } } } }, "/discord/validate/{channel}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "Validate if the bot can access and send messages to the channel", "tags": [ "discord" ], "summary": "Validate Discord channel", "parameters": [ { "type": "string", "description": "Discord Channel ID", "name": "channel", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/discord.SendMessageResponse" } } } } }, "/healthz": { "get": { "security": [ { "BasicAuth": [] } ], "description": "Returns OK if the service is healthy", "produces": [ "application/json" ], "tags": [ "health" ], "summary": "Check health status", "operationId": "Healthz", "responses": { "200": { "description": "Health check response", "schema": { "$ref": "#/definitions/resp.Health" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/v1.ErrorResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/v1.ErrorResponse" } } } } }, "/slack/channel/{channel}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "發送訊息到指定的 Slack 頻道", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "發送 Slack 訊息到指定頻道", "parameters": [ { "type": "string", "description": "頻道名稱 (例如: alerts, emergency)", "name": "channel", "in": "path", "required": true }, { "description": "發送訊息請求", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/slack.SendMessageRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/slack/channels": { "get": { "security": [ { "BasicAuth": [] } ], "description": "獲取當前配置的所有 Slack 頻道映射", "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "獲取 Slack 頻道配置", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.ChannelsResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "503": { "description": "Service Unavailable", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/slack/status": { "get": { "security": [ { "BasicAuth": [] } ], "description": "獲取 Slack 服務的當前狀態和配置信息", "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "獲取 Slack 服務狀態", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.StatusResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/slack/test": { "post": { "security": [ { "BasicAuth": [] } ], "description": "發送測試訊息到預設頻道以驗證 Slack 連接", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "測試 Slack 連接", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "503": { "description": "Service Unavailable", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/slack/validate/{channel}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "檢查 Bot 是否已加入指定頻道,如果未加入會提供加入指引", "produces": [ "application/json" ], "tags": [ "slack" ], "summary": "驗證 Slack 頻道", "parameters": [ { "type": "string", "description": "頻道名稱 (例如: alerts, emergency)", "name": "channel", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } }, "503": { "description": "Service Unavailable", "schema": { "$ref": "#/definitions/slack.SendMessageResponse" } } } } }, "/telegram/chatid_{chatid}": { "post": { "security": [ { "BasicAuth": [] } ], "description": "Send message to specified Telegram chat level", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "telegram" ], "summary": "Send Telegram message", "parameters": [ { "type": "string", "description": "聊天等級 (格式: L{0-4})", "name": "chatid", "in": "path", "required": true }, { "description": "訊息內容", "name": "request", "in": "body", "required": true, "schema": { "$ref": "#/definitions/telegram.SendMessageRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/telegram.SendMessageResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/telegram.SendMessageResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/telegram.SendMessageResponse" } } } } }, "/telegram/info": { "get": { "security": [ { "BasicAuth": [] } ], "description": "獲取 Telegram 機器人的基本資訊", "produces": [ "application/json" ], "tags": [ "telegram" ], "summary": "獲取機器人資訊", "responses": { "200": { "description": "OK", "schema": { "type": "object", "additionalProperties": true } } } } } }, "definitions": { "discord.SendMessageRequest": { "type": "object", "properties": { "alertmanager_data": { "description": "AlertManager webhook data (wrapped format)", "type": "object", "additionalProperties": true }, "alerts": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "commonAnnotations": { "type": "object", "additionalProperties": true }, "commonLabels": { "type": "object", "additionalProperties": true }, "externalURL": { "type": "string" }, "groupKey": { "type": "string" }, "groupLabels": { "type": "object", "additionalProperties": true }, "message": { "description": "Simple text message", "type": "string" }, "receiver": { "description": "Direct AlertManager JSON format (consistent with Slack/Telegram)", "type": "string" }, "status": { "type": "string" }, "truncatedAlerts": { "type": "integer" }, "version": { "type": "string" } } }, "discord.SendMessageResponse": { "type": "object", "properties": { "code": { "type": "string" }, "level": { "type": "string" }, "message": { "type": "string" }, "success": { "type": "boolean" } } }, "discord.StatusResponse": { "type": "object", "properties": { "bot_info": {}, "code": { "type": "string" }, "error": { "type": "string" }, "service": { "type": "string" }, "status": { "type": "string" }, "timestamp": { "type": "string" } } }, "resp.Health": { "type": "object", "properties": { "status": { "type": "string", "example": "ok" } } }, "service.Field": { "type": "object", "properties": { "short": { "type": "boolean" }, "title": { "type": "string" }, "value": { "type": "string" } } }, "slack.ChannelsResponse": { "type": "object", "properties": { "channels": { "type": "object", "additionalProperties": { "type": "string" } }, "success": { "type": "boolean" } } }, "slack.RichMessageRequest": { "type": "object", "properties": { "color": { "description": "顏色 (good, warning, danger, 或 hex)", "type": "string" }, "fields": { "description": "字段列表", "type": "array", "items": { "$ref": "#/definitions/service.Field" } }, "footer_icon": { "description": "頁腳圖示", "type": "string" }, "footer_text": { "description": "頁腳文字", "type": "string" }, "icon_emoji": { "description": "自定義 Bot 表情符號", "type": "string" }, "icon_url": { "description": "自定義 Bot 頭像 URL", "type": "string" }, "message": { "description": "訊息內容", "type": "string" }, "title": { "description": "訊息標題", "type": "string" }, "username": { "description": "自定義 Bot 名稱", "type": "string" } } }, "slack.SendMessageRequest": { "type": "object", "properties": { "alertmanager_data": { "description": "AlertManager webhook 數據(包裝格式)", "type": "object", "additionalProperties": true }, "alerts": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "commonAnnotations": { "type": "object", "additionalProperties": true }, "commonLabels": { "type": "object", "additionalProperties": true }, "externalURL": { "type": "string" }, "groupKey": { "type": "string" }, "groupLabels": { "type": "object", "additionalProperties": true }, "icon_emoji": { "description": "自定義 Bot 表情符號", "type": "string" }, "icon_url": { "description": "自定義 Bot 頭像 URL", "type": "string" }, "message": { "description": "簡單文字訊息", "type": "string" }, "receiver": { "description": "原始 AlertManager JSON 格式(直接接受)", "type": "string" }, "status": { "type": "string" }, "thread_ts": { "description": "線程時間戳(回覆特定訊息)", "type": "string" }, "truncatedAlerts": { "type": "integer" }, "username": { "description": "自定義 Bot 名稱", "type": "string" }, "version": { "type": "string" } } }, "slack.SendMessageResponse": { "type": "object", "properties": { "code": { "type": "string" }, "level": { "type": "string" }, "message": { "type": "string" }, "success": { "type": "boolean" } } }, "slack.StatusResponse": { "type": "object", "properties": { "channels": { "type": "object", "additionalProperties": { "type": "string" } }, "connected": { "type": "boolean" }, "enabled": { "type": "boolean" }, "success": { "type": "boolean" } } }, "telegram.Alert": { "type": "object", "properties": { "annotations": { "type": "object", "additionalProperties": { "type": "string" } }, "endsAt": { "type": "string" }, "fingerprint": { "type": "string" }, "generatorURL": { "type": "string" }, "labels": { "type": "object", "additionalProperties": { "type": "string" } }, "startsAt": { "type": "string" }, "status": { "type": "string" } } }, "telegram.AlertManagerWebhook": { "type": "object", "properties": { "alerts": { "type": "array", "items": { "$ref": "#/definitions/telegram.Alert" } }, "commonAnnotations": { "type": "object", "additionalProperties": { "type": "string" } }, "commonLabels": { "type": "object", "additionalProperties": { "type": "string" } }, "externalURL": { "type": "string" }, "groupKey": { "type": "string" }, "groupLabels": { "type": "object", "additionalProperties": { "type": "string" } }, "receiver": { "type": "string" }, "status": { "type": "string" }, "truncatedAlerts": { "type": "integer" }, "version": { "type": "string" } } }, "telegram.SendMessageRequest": { "type": "object", "properties": { "alertmanager_data": { "description": "AlertManager webhook 數據", "allOf": [ { "$ref": "#/definitions/telegram.AlertManagerWebhook" } ] }, "message": { "description": "可選,當使用 AlertManager 格式時不需要", "type": "string" }, "template_language": { "description": "可選,優先使用配置檔案中的設定", "type": "string" } } }, "telegram.SendMessageResponse": { "type": "object", "properties": { "code": { "type": "string" }, "level": { "type": "integer" }, "message": { "type": "string" }, "success": { "type": "boolean" } } }, "v1.ErrorResponse": { "type": "object", "properties": { "code": { "type": "integer", "example": 401 }, "message": { "type": "string", "example": "unauthorized" } } } }, "securityDefinitions": { "BasicAuth": { "type": "basic" } }, "security": [ { "BasicAuth": [] } ] }