Skip to content

Conversation

@jcolladokuri
Copy link
Contributor

@jcolladokuri jcolladokuri commented Dec 17, 2025

Sumary

When dealing with multiple hosts, it can be hard for customers filter through and figure out which host to query metric data from. This PR aims to make this easier by adding support for host tags so that there is another layer of filtering / grouping applied for hosts.

Detailed explanation

  • Adds new UI components to allow adding one or more host tag filter, and a switch to choose between AND/OR and OR operators when using more than one filter following Zabbix's UI:

    Screen.Recording.2025-12-09.at.3.19.14.PM.mov
    Screen.Recording.2025-12-09.at.3.21.14.PM.mov
  • Modifies the existing getHosts function to make a call to the backend with a few additional parameters to extend (essentially extract) the host tags for a given selected group. No backend changes were required for this.

Why

To make it easier for customers to query metric data when dealing with multiple hosts.

How to test

  • Go to explore or a dashboard and create a Zabbix query where the query type is Metrics
  • The easiest way to test is by selecting /.*/ for Groups, checking the returned Hosts they should all be there
  • Add a host tag filter and change the keys and operators as well as switching from AND/OR to OR you should see how the values returned for Host changes

Future work

Adding variable support for host tags once this is completed.

Fixes: https://github.com/orgs/grafana/projects/457/views/40?pane=issue&itemId=3609900134&issue=grafana%7Coss-big-tent-squad%7C126 and #927

Copy link
Contributor

@itsmylife itsmylife left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pointed mostly the nitpicks.
But when I apply a weird host tag it still returns data. I'm not sure if that how it should be.

Image

When I try to do the same in zabbix it doesn't show anything. I think hostTags are not really affecting the query that is sent to the Zabbix.

Image

return uniqueHostTags;
}

/** Get the label for a host tag option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Get the label for a host tag option
/**
* Get the label for a host tag option

@@ -1,4 +1,7 @@
import _ from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can import uniqBy just using import { uniqBy } from 'lodash';. What do you think?

}

/** Get the label for a host tag option
* Zabbix chaneged some of the operator labels in version 7.0.0 but the value equivalents remained the same.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Zabbix chaneged some of the operator labels in version 7.0.0 but the value equivalents remained the same.
* Zabbix changed some of the operator labels in version 7.0.0 but the value equivalents remained the same.

export function processHostTags(hosts: Host[]): Tag[] {
const hostTags = hosts.map((host) => host.tags || []).flat();
// deduplicate tags
const uniqueHostTags = _.uniqBy(hostTags, (tag) => `${tag.tag}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't tag.tag is already string? Why are we using backticks?

useEffect(() => {
onHostTagFilterChange(hostTagFilters);
}, [hostTagFilters]);
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (
return (

evalTypeValue?: ZabbixTagEvalType;
onHostTagFilterChange?: (hostTags: HostTagFilter[]) => void;
onHostTagEvalTypeChange?: (evalType: ZabbixTagEvalType) => void;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Comment on lines +114 to +120
<Input
value={filter.value}
onChange={(evt: FormEvent<HTMLInputElement>) =>
setHostTagFilterValue(index, evt?.currentTarget?.value)
}
width={19}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short placeholder would be useful. At first glance I've missed what I need to do with the input field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my each keystroke it sends another request to the backend. Can we have a debounce logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants