Adds support for host tags (#2140)
## 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: https://github.com/user-attachments/assets/c971f5eb-7e93-4238-bd6b-902cc657c014 https://github.com/user-attachments/assets/5f8996de-684e-4ffa-b98e-8e205c4fc1df - 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 https://github.com/grafana/grafana-zabbix/issues/927 --------- Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3d0895c008
commit
0d64736e86
@@ -233,7 +233,7 @@ func filterAppsByQuery(items []Application, filter string) ([]Application, error
|
||||
return filteredItems, nil
|
||||
}
|
||||
|
||||
func (ds *Zabbix) GetItemTags(ctx context.Context, groupFilter string, hostFilter string, tagFilter string) ([]ItemTag, error) {
|
||||
func (ds *Zabbix) GetItemTags(ctx context.Context, groupFilter string, hostFilter string, tagFilter string) ([]Tag, error) {
|
||||
hosts, err := ds.GetHosts(ctx, groupFilter, hostFilter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -252,8 +252,8 @@ func (ds *Zabbix) GetItemTags(ctx context.Context, groupFilter string, hostFilte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var allTags []ItemTag
|
||||
tagsMap := make(map[string]ItemTag)
|
||||
var allTags []Tag
|
||||
tagsMap := make(map[string]Tag)
|
||||
for _, item := range allItems {
|
||||
for _, itemTag := range item.Tags {
|
||||
tagStr := itemTagToString(itemTag)
|
||||
@@ -267,13 +267,13 @@ func (ds *Zabbix) GetItemTags(ctx context.Context, groupFilter string, hostFilte
|
||||
return filterTags(allTags, tagFilter)
|
||||
}
|
||||
|
||||
func filterTags(items []ItemTag, filter string) ([]ItemTag, error) {
|
||||
func filterTags(items []Tag, filter string) ([]Tag, error) {
|
||||
re, err := parseFilter(filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filteredItems := make([]ItemTag, 0)
|
||||
filteredItems := make([]Tag, 0)
|
||||
for _, i := range items {
|
||||
tagStr := itemTagToString(i)
|
||||
if re != nil {
|
||||
|
||||
Reference in New Issue
Block a user