Fix item tag filter, #1594

This commit is contained in:
Alexander Zobnin
2023-03-23 14:40:22 +01:00
parent fc1d809dc1
commit 24285a9483
4 changed files with 39 additions and 20 deletions

View File

@@ -2,7 +2,6 @@ package zabbix
import (
"context"
"regexp"
"strconv"
"strings"
@@ -243,8 +242,15 @@ func (ds *Zabbix) GetItemTags(ctx context.Context, groupFilter string, hostFilte
allItems, err = ds.GetAllItems(ctx, hostids, nil, itemType, showDisabled, "")
var allTags []ItemTag
tagsMap := make(map[string]ItemTag)
for _, item := range allItems {
allTags = append(allTags, item.Tags...)
for _, itemTag := range item.Tags {
tagStr := itemTagToString(itemTag)
tagsMap[tagStr] = itemTag
}
}
for _, t := range tagsMap {
allTags = append(allTags, t)
}
return filterTags(allTags, tagFilter)
@@ -376,18 +382,15 @@ func (ds *Zabbix) GetAllItems(ctx context.Context, hostids []string, appids []st
params["selectTags"] = "extend"
if len(itemTagFilter) > 0 {
allTags := strings.Split(itemTagFilter, ",")
re := regexp.MustCompile(`(?m).*?([a-zA-Z0-9\s\-_]*):\s*([a-zA-Z0-9\-_\/:]*)`)
var tagsParams []map[string]string
for i := 0; i < len(allTags); i++ {
res := re.FindAllStringSubmatch(allTags[i], -1)
for i := range res {
tagParam := map[string]string{
"tag": res[i][1],
"value": res[i][2],
"operator": "1",
}
tagsParams = append(tagsParams, tagParam)
tagsParams := make([]map[string]string, 0)
for _, tagStr := range allTags {
tag := parseItemTag(tagStr)
tagParam := map[string]string{
"tag": tag.Tag,
"value": tag.Value,
"operator": "1",
}
tagsParams = append(tagsParams, tagParam)
}
params["tags"] = tagsParams
params["evaltype"] = 2