Fix using value mapping from zabbix, closes #1222
This commit is contained in:
@@ -98,8 +98,9 @@ type QueryFilter struct {
|
||||
|
||||
// QueryOptions model
|
||||
type QueryOptions struct {
|
||||
ShowDisabledItems bool `json:"showDisabledItems"`
|
||||
DisableDataAlignment bool `json:"disableDataAlignment"`
|
||||
ShowDisabledItems bool `json:"showDisabledItems"`
|
||||
DisableDataAlignment bool `json:"disableDataAlignment"`
|
||||
UseZabbixValueMapping bool `json:"useZabbixValueMapping"`
|
||||
}
|
||||
|
||||
// QueryOptions model
|
||||
|
||||
@@ -92,17 +92,17 @@ func convertTimeSeriesToDataFrame(series []*timeseries.TimeSeriesData) *data.Fra
|
||||
return wideFrame
|
||||
}
|
||||
|
||||
func convertTimeSeriesToDataFrames(series []*timeseries.TimeSeriesData) []*data.Frame {
|
||||
func convertTimeSeriesToDataFrames(series []*timeseries.TimeSeriesData, valuemaps []zabbix.ValueMap) []*data.Frame {
|
||||
frames := make([]*data.Frame, 0)
|
||||
|
||||
for _, s := range series {
|
||||
frames = append(frames, seriesToDataFrame(s))
|
||||
frames = append(frames, seriesToDataFrame(s, valuemaps))
|
||||
}
|
||||
|
||||
return frames
|
||||
}
|
||||
|
||||
func seriesToDataFrame(series *timeseries.TimeSeriesData) *data.Frame {
|
||||
func seriesToDataFrame(series *timeseries.TimeSeriesData, valuemaps []zabbix.ValueMap) *data.Frame {
|
||||
timeFileld := data.NewFieldFromFieldType(data.FieldTypeTime, 0)
|
||||
timeFileld.Name = data.TimeSeriesTimeFieldName
|
||||
|
||||
@@ -128,6 +128,11 @@ func seriesToDataFrame(series *timeseries.TimeSeriesData) *data.Frame {
|
||||
},
|
||||
}
|
||||
|
||||
if len(valuemaps) > 0 {
|
||||
mappings := getValueMapping(*item, valuemaps)
|
||||
valueField.Config.Mappings = mappings
|
||||
}
|
||||
|
||||
frame := data.NewFrame(seriesName, timeFileld, valueField)
|
||||
|
||||
for _, point := range series.TS {
|
||||
@@ -248,3 +253,28 @@ func parseItemUpdateInterval(delay string) *time.Duration {
|
||||
|
||||
return &interval
|
||||
}
|
||||
|
||||
func getValueMapping(item zabbix.Item, valueMaps []zabbix.ValueMap) data.ValueMappings {
|
||||
mappings := make([]data.ValueMapping, 0)
|
||||
zabbixMap := zabbix.ValueMap{}
|
||||
|
||||
for _, vm := range valueMaps {
|
||||
if vm.ID == item.ValueMapID {
|
||||
zabbixMap = vm
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if zabbixMap.ID == "" {
|
||||
return mappings
|
||||
}
|
||||
|
||||
for _, m := range zabbixMap.Mappings {
|
||||
mappings = append(mappings, data.ValueMapper{
|
||||
m.Value: {
|
||||
Text: m.NewValue,
|
||||
},
|
||||
})
|
||||
}
|
||||
return mappings
|
||||
}
|
||||
|
||||
@@ -145,7 +145,15 @@ func (ds *ZabbixDatasourceInstance) applyDataProcessing(ctx context.Context, que
|
||||
}
|
||||
}
|
||||
|
||||
frames := convertTimeSeriesToDataFrames(series)
|
||||
valueMaps := make([]zabbix.ValueMap, 0)
|
||||
if query.Options.UseZabbixValueMapping {
|
||||
valueMaps, err = ds.zabbix.GetValueMappings(ctx)
|
||||
if err != nil {
|
||||
ds.logger.Error("Error getting value maps", "error", err)
|
||||
valueMaps = []zabbix.ValueMap{}
|
||||
}
|
||||
}
|
||||
frames := convertTimeSeriesToDataFrames(series, valueMaps)
|
||||
return frames, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user