Sort response by item id

This commit is contained in:
Alexander Zobnin
2021-05-31 18:37:00 +03:00
parent 7276e4ba09
commit 6e6797653e
2 changed files with 20 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ func convertHistoryToTimeSeries(history zabbix.History, items []*zabbix.Item) []
series = append(series, tsd) series = append(series, tsd)
} }
timeseries.SortByItem(series)
return series return series
} }

View File

@@ -2,6 +2,7 @@ package timeseries
import ( import (
"sort" "sort"
"strconv"
) )
// SortBy sorts series by value calculated with provided aggFunc in given order // SortBy sorts series by value calculated with provided aggFunc in given order
@@ -31,3 +32,21 @@ func SortBy(series []*TimeSeriesData, order string, aggFunc AggFunc) []*TimeSeri
return series return series
} }
func SortByItem(series []*TimeSeriesData) []*TimeSeriesData {
sort.Slice(series, func(i, j int) bool {
itemIDi, err := strconv.Atoi(series[i].Meta.Item.ID)
if err != nil {
return false
}
itemIDj, err := strconv.Atoi(series[j].Meta.Item.ID)
if err != nil {
return false
}
return itemIDi < itemIDj
})
return series
}