Fix show disabled items toggle, closes #1249

This commit is contained in:
Alexander Zobnin
2022-05-04 12:08:54 +03:00
parent 9d6abf3164
commit c0a33f2e7e
2 changed files with 19 additions and 5 deletions

View File

@@ -50,8 +50,9 @@ func (ds *ZabbixDatasourceInstance) queryNumericItems(ctx context.Context, query
appFilter := query.Application.Filter
itemTagFilter := query.ItemTag.Filter
itemFilter := query.Item.Filter
showDisabled := query.Options.ShowDisabledItems
items, err := ds.zabbix.GetItems(ctx, groupFilter, hostFilter, appFilter, itemTagFilter, itemFilter, "num")
items, err := ds.zabbix.GetItems(ctx, groupFilter, hostFilter, appFilter, itemTagFilter, itemFilter, "num", showDisabled)
if err != nil {
return nil, err
}

View File

@@ -80,7 +80,16 @@ func (ds *Zabbix) getTrend(ctx context.Context, itemids []string, timeRange back
return trend, err
}
func (ds *Zabbix) GetItems(ctx context.Context, groupFilter string, hostFilter string, appFilter string, itemTagFilter string, itemFilter string, itemType string) ([]*Item, error) {
func (ds *Zabbix) GetItems(
ctx context.Context,
groupFilter string,
hostFilter string,
appFilter string,
itemTagFilter string,
itemFilter string,
itemType string,
showDisabled bool,
) ([]*Item, error) {
hosts, err := ds.GetHosts(ctx, groupFilter, hostFilter)
if err != nil {
return nil, err
@@ -105,9 +114,9 @@ func (ds *Zabbix) GetItems(ctx context.Context, groupFilter string, hostFilter s
var allItems []*Item
if len(appids) > 0 {
allItems, err = ds.GetAllItems(ctx, nil, appids, itemType)
allItems, err = ds.GetAllItems(ctx, nil, appids, itemType, showDisabled)
} else if len(hostids) > 0 {
allItems, err = ds.GetAllItems(ctx, hostids, nil, itemType)
allItems, err = ds.GetAllItems(ctx, hostids, nil, itemType, showDisabled)
}
if isZabbix54orHigher && itemTagFilter != "" {
@@ -285,7 +294,7 @@ func filterGroupsByQuery(items []Group, filter string) ([]Group, error) {
return filteredItems, nil
}
func (ds *Zabbix) GetAllItems(ctx context.Context, hostids []string, appids []string, itemtype string) ([]*Item, error) {
func (ds *Zabbix) GetAllItems(ctx context.Context, hostids []string, appids []string, itemtype string, showDisabled bool) ([]*Item, error) {
params := ZabbixAPIParams{
"output": []string{"itemid", "name", "key_", "value_type", "hostid", "status", "state", "units", "valuemapid", "delay"},
"sortfield": "name",
@@ -307,6 +316,10 @@ func (ds *Zabbix) GetAllItems(ctx context.Context, hostids []string, appids []st
params["selectTags"] = "extend"
}
if showDisabled == false {
params["monitored"] = true
}
result, err := ds.Request(ctx, &ZabbixAPIRequest{Method: "item.get", Params: params})
if err != nil {
return nil, err