Skip to content

Commit

Permalink
[Controller] vinterface support filter
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie authored and SongZhen0704 committed May 28, 2024
1 parent 08bf9f6 commit dfdcae9
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion server/controller/http/router/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package router

import (
"errors"
"fmt"
"strconv"

"github.com/gin-gonic/gin"
Expand All @@ -28,6 +29,7 @@ import (
. "github.com/deepflowio/deepflow/server/controller/http/router/common"
"github.com/deepflowio/deepflow/server/controller/http/service"
"github.com/deepflowio/deepflow/server/controller/manager"
"github.com/deepflowio/deepflow/server/controller/model"
)

type Debug struct {
Expand Down Expand Up @@ -241,7 +243,42 @@ func getGenesisSyncData(g *genesis.Genesis, isLocal bool) gin.HandlerFunc {
case "ip":
data = ret.IPLastSeens
case "vinterface":
data = ret.Vinterfaces
teamIDList := map[uint32]bool{}
teamIDs, _ := c.GetQueryArray("team_id")
for _, t := range teamIDs {
teamID, err := strconv.Atoi(t)
if err != nil {
log.Warningf(err.Error())
continue
}
teamIDList[uint32(teamID)] = false
}

filterType := c.Query("team_id_filter")
switch filterType {
case "":
data = ret.Vinterfaces
case "whitelist":
retVinterfaces := []model.GenesisVinterface{}
for _, v := range ret.Vinterfaces {
if _, ok := teamIDList[v.TeamID]; !ok {
continue
}
retVinterfaces = append(retVinterfaces, v)
}
data = retVinterfaces
case "blacklist":
retVinterfaces := []model.GenesisVinterface{}
for _, v := range ret.Vinterfaces {
if _, ok := teamIDList[v.TeamID]; ok {
continue
}
retVinterfaces = append(retVinterfaces, v)
}
data = retVinterfaces
default:
err = fmt.Errorf("invalid team_id_filter (%s) for vinterface", filterType)
}
case "process":
data = ret.Processes
case "vip":
Expand Down

0 comments on commit dfdcae9

Please sign in to comment.