🚸 可以使指定服务器不参与服务监控

This commit is contained in:
naiba
2021-04-22 21:53:31 +08:00
parent 6f565ba022
commit 585cf538d0
10 changed files with 419 additions and 292 deletions

View File

@@ -1,7 +1,10 @@
package model
import (
"encoding/json"
pb "github.com/naiba/nezha/proto"
"gorm.io/gorm"
)
const (
@@ -14,10 +17,13 @@ const (
type Monitor struct {
Common
Name string
Type uint8
Target string
Notify bool
Name string
Type uint8
Target string
SkipServersRaw string
Notify bool
SkipServers map[uint64]bool `gorm:"-" json:"-"`
}
func (m *Monitor) PB() *pb.Task {
@@ -27,3 +33,15 @@ func (m *Monitor) PB() *pb.Task {
Data: m.Target,
}
}
func (m *Monitor) AfterFind(tx *gorm.DB) error {
var skipServers []uint64
if err := json.Unmarshal([]byte(m.SkipServersRaw), &skipServers); err != nil {
return err
}
m.SkipServers = make(map[uint64]bool)
for i := 0; i < len(skipServers); i++ {
m.SkipServers[skipServers[i]] = true
}
return nil
}