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,30 @@
|
||||
package trafficmgr
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"vpn-platform/backend/internal/alertnotify"
|
||||
"vpn-platform/backend/internal/model"
|
||||
"vpn-platform/backend/internal/store"
|
||||
)
|
||||
|
||||
func TestConfigurableRateThreshold(t *testing.T) {
|
||||
if err := store.Init(t.TempDir()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := alertnotify.Save(alertnotify.Input{RateThresholdMbps: 80}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if CheckRateAbnormal(1, 100*1024*1024, 0, 15*time.Second) {
|
||||
t.Fatal("below 80 Mbps should not alert")
|
||||
}
|
||||
if !CheckRateAbnormal(1, 200*1024*1024, 0, 15*time.Second) {
|
||||
t.Fatal("above 80 Mbps should alert")
|
||||
}
|
||||
var count int64
|
||||
store.DB.Model(&model.ConnectionLog{}).Where("event = ?", "rate_alert").Count(&count)
|
||||
if count != 1 {
|
||||
t.Fatalf("want one alert, got %d", count)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user