Use backend queries for item id mode
This commit is contained in:
@@ -122,15 +122,22 @@ func (ds *ZabbixDatasource) QueryData(ctx context.Context, req *backend.QueryDat
|
||||
ds.logger.Debug("DS query", "query", q)
|
||||
if err != nil {
|
||||
res.Error = err
|
||||
} else if query.Mode != 0 {
|
||||
res.Error = ErrNonMetricQueryNotSupported
|
||||
} else {
|
||||
} else if query.QueryType == MODE_METRICS {
|
||||
frames, err := zabbixDS.queryNumericItems(ctx, &query)
|
||||
if err != nil {
|
||||
res.Error = err
|
||||
} else {
|
||||
res.Frames = append(res.Frames, frames...)
|
||||
}
|
||||
} else if query.QueryType == MODE_ITEMID {
|
||||
frames, err := zabbixDS.queryItemIdData(ctx, &query)
|
||||
if err != nil {
|
||||
res.Error = err
|
||||
} else {
|
||||
res.Frames = append(res.Frames, frames...)
|
||||
}
|
||||
} else {
|
||||
res.Error = ErrNonMetricQueryNotSupported
|
||||
}
|
||||
qdr.Responses[q.RefID] = res
|
||||
}
|
||||
|
||||
@@ -8,6 +8,15 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
)
|
||||
|
||||
const (
|
||||
MODE_METRICS = "0"
|
||||
MODE_ITSERVICE = "1"
|
||||
MODE_TEXT = "2"
|
||||
MODE_ITEMID = "3"
|
||||
MODE_TRIGGERS = "4"
|
||||
MODE_PROBLEMS = "5"
|
||||
)
|
||||
|
||||
// ZabbixDatasourceSettingsDTO model
|
||||
type ZabbixDatasourceSettingsDTO struct {
|
||||
Trends bool `json:"trends"`
|
||||
@@ -44,13 +53,19 @@ type ZabbixAPIResourceResponse struct {
|
||||
|
||||
// QueryModel model
|
||||
type QueryModel struct {
|
||||
Mode int64 `json:"mode"`
|
||||
Group QueryFilter `json:"group"`
|
||||
Host QueryFilter `json:"host"`
|
||||
Application QueryFilter `json:"application"`
|
||||
Item QueryFilter `json:"item"`
|
||||
Functions []QueryFunction `json:"functions,omitempty"`
|
||||
Options QueryOptions `json:"options"`
|
||||
// Deprecated `mode` field, use QueryType instead
|
||||
Mode int64 `json:"mode"`
|
||||
|
||||
Group QueryFilter `json:"group"`
|
||||
Host QueryFilter `json:"host"`
|
||||
Application QueryFilter `json:"application"`
|
||||
Item QueryFilter `json:"item"`
|
||||
|
||||
// Item ID mode
|
||||
ItemIDs string `json:"itemids,omitempty"`
|
||||
|
||||
Functions []QueryFunction `json:"functions,omitempty"`
|
||||
Options QueryOptions `json:"options"`
|
||||
|
||||
// Direct from the gRPC interfaces
|
||||
RefID string `json:"-"`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package datasource
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/zabbix"
|
||||
@@ -60,6 +61,25 @@ func (ds *ZabbixDatasourceInstance) queryNumericItems(ctx context.Context, query
|
||||
return frames, nil
|
||||
}
|
||||
|
||||
func (ds *ZabbixDatasourceInstance) queryItemIdData(ctx context.Context, query *QueryModel) ([]*data.Frame, error) {
|
||||
itemids := strings.Split(query.ItemIDs, ",")
|
||||
for i, id := range itemids {
|
||||
itemids[i] = strings.Trim(id, " ")
|
||||
}
|
||||
|
||||
items, err := ds.zabbix.GetItemsByIDs(ctx, itemids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
frames, err := ds.queryNumericDataForItems(ctx, query, items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return frames, nil
|
||||
}
|
||||
|
||||
func (ds *ZabbixDatasourceInstance) queryNumericDataForItems(ctx context.Context, query *QueryModel, items []*zabbix.Item) ([]*data.Frame, error) {
|
||||
trendValueType := ds.getTrendValueType(query)
|
||||
consolidateBy := ds.getConsolidateBy(query)
|
||||
|
||||
Reference in New Issue
Block a user