53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"vpn-platform/backend/internal/alertnotify"
|
|
"vpn-platform/backend/internal/store"
|
|
)
|
|
|
|
func (s *Server) getAlertSettings(c *gin.Context) {
|
|
status, err := alertnotify.Get()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "读取告警配置失败"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, status)
|
|
}
|
|
|
|
func (s *Server) saveAlertSettings(c *gin.Context) {
|
|
var req alertnotify.Input
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数格式错误"})
|
|
return
|
|
}
|
|
status, err := alertnotify.Save(req)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
store.Audit(c.GetString("username"), "update_alert_settings", "traffic", "告警设置已更新")
|
|
c.JSON(http.StatusOK, status)
|
|
}
|
|
|
|
func (s *Server) testAlertSettings(c *gin.Context) {
|
|
if err := alertnotify.Test(); err != nil {
|
|
c.JSON(http.StatusBadGateway, gin.H{"error": "飞书试发失败:" + err.Error()})
|
|
return
|
|
}
|
|
store.Audit(c.GetString("username"), "test_alert_notification", "feishu", "测试消息发送成功")
|
|
c.JSON(http.StatusOK, gin.H{"ok": true})
|
|
}
|
|
|
|
func (s *Server) clearAlertSettings(c *gin.Context) {
|
|
status, err := alertnotify.Clear()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "清除告警配置失败"})
|
|
return
|
|
}
|
|
store.Audit(c.GetString("username"), "clear_alert_settings", "traffic", "群机器人凭据已清除")
|
|
c.JSON(http.StatusOK, status)
|
|
}
|