Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get audit list by id #2424

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions center/router/router_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,16 +406,15 @@ func haveNeverGroupedIdent(ctx *ctx.Context, idents []string) (bool, error) {
if err != nil {
return false, err
}

if len(bgids) <= 0 {
return true, nil
}
}
}

return false, nil
}


func (rt *Router) targetBindBgids(c *gin.Context) {
var f targetBgidsForm
var err error
Expand Down
56 changes: 56 additions & 0 deletions models/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,62 @@ func TargetsGetIdentsByIdentsAndHostIps(ctx *ctx.Context, idents, hostIps []stri
return inexistence, identSet.ToSlice(), nil
}

func TargetsGetIdsByIdentsAndHostIps(ctx *ctx.Context, idents, hostIps []string) (
map[string]string, []int64, error) {
inexistence := make(map[string]string)
idSet := set.NewInt64Set()

if len(idents) > 0 {
var identToIdMap []struct {
Ident string
Id int64
}
err := DB(ctx).Model(&Target{}).Select("id, ident").Where("ident IN ?", idents).Scan(&identToIdMap).Error
if err != nil {
return nil, nil, err
}

identSet := set.NewStringSet()
for _, entry := range identToIdMap {
idSet.Add(entry.Id)
identSet.Add(entry.Ident)
}

for _, ident := range idents {
if !identSet.Exists(ident) {
inexistence[ident] = "Ident not found"
}
}
}

// Query the hostIp corresponding to idents
if len(hostIps) > 0 {
var hostIpMap []struct {
HostIp string
Ident string
Id int64
}
err := DB(ctx).Model(&Target{}).Select("id, host_ip").Where("host_ip IN ?", hostIps).Scan(&hostIpMap).Error
if err != nil {
return nil, nil, err
}

hostIpSet := set.NewStringSet()
for _, entry := range hostIpMap {
hostIpSet.Add(entry.HostIp)
idSet.Add(entry.Id)
}

for _, hostIp := range hostIps {
if !hostIpSet.Exists(hostIp) {
inexistence[hostIp] = "HostIp not found"
}
}
}

return inexistence, idSet.ToSlice(), nil
}

func TargetGetTags(ctx *ctx.Context, idents []string, ignoreHostTag bool, bgLabelKey string) (
[]string, error) {
session := DB(ctx).Model(new(Target))
Expand Down