feat: configurable traffic threshold and Feishu bot alerts
This commit is contained in:
1 parent
3e6e481b79
commit
1273f226fd
16 files changed
+660
-20
No files matched your search
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
}
|
||||
@@ -310,6 +310,10 @@ func (s *Server) RegisterRoutes(r *gin.Engine) {
|
||||
admin.Use(requireRole("admin"))
|
||||
// 主机环境体检与一键初始化(仅 admin)
|
||||
admin.GET("/system/env", s.systemEnv)
|
||||
admin.GET("/system/alerts", s.getAlertSettings)
|
||||
admin.PUT("/system/alerts", s.saveAlertSettings)
|
||||
admin.DELETE("/system/alerts", s.clearAlertSettings)
|
||||
admin.POST("/system/alerts/test", s.testAlertSettings)
|
||||
admin.POST("/system/fix", s.systemFix)
|
||||
admin.GET("/system/tls", s.tlsStatus)
|
||||
admin.GET("/system/identity", idp.Status)
|
||||
|
||||
Reference in new issue
Block a user