Fix backend linter errors
This commit is contained in:
@@ -145,6 +145,10 @@ func applyFunctionsPre(query *QueryModel, items []*zabbix.Item) error {
|
||||
|
||||
func applyGroupBy(series timeseries.TimeSeries, params ...interface{}) (timeseries.TimeSeries, error) {
|
||||
pInterval, err := MustString(params[0])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
|
||||
pAgg, err := MustString(params[1])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
@@ -169,6 +173,10 @@ func applyGroupBy(series timeseries.TimeSeries, params ...interface{}) (timeseri
|
||||
|
||||
func applyPercentile(series timeseries.TimeSeries, params ...interface{}) (timeseries.TimeSeries, error) {
|
||||
pInterval, err := MustString(params[0])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
|
||||
percentile, err := MustFloat64(params[1])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
@@ -275,6 +283,10 @@ func applyExponentialMovingAverage(series timeseries.TimeSeries, params ...inter
|
||||
|
||||
func applyAggregateBy(series []*timeseries.TimeSeriesData, params ...interface{}) ([]*timeseries.TimeSeriesData, error) {
|
||||
pInterval, err := MustString(params[0])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
|
||||
pAgg, err := MustString(params[1])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
@@ -303,6 +315,10 @@ func applySumSeries(series []*timeseries.TimeSeriesData, params ...interface{})
|
||||
|
||||
func applyPercentileAgg(series []*timeseries.TimeSeriesData, params ...interface{}) ([]*timeseries.TimeSeriesData, error) {
|
||||
pInterval, err := MustString(params[0])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
|
||||
percentile, err := MustFloat64(params[1])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
@@ -331,6 +347,10 @@ func applyPercentileAgg(series []*timeseries.TimeSeriesData, params ...interface
|
||||
|
||||
func applyTop(series []*timeseries.TimeSeriesData, params ...interface{}) ([]*timeseries.TimeSeriesData, error) {
|
||||
n, err := MustFloat64(params[0])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
|
||||
pAgg, err := MustString(params[1])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
@@ -343,6 +363,10 @@ func applyTop(series []*timeseries.TimeSeriesData, params ...interface{}) ([]*ti
|
||||
|
||||
func applyBottom(series []*timeseries.TimeSeriesData, params ...interface{}) ([]*timeseries.TimeSeriesData, error) {
|
||||
n, err := MustFloat64(params[0])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
}
|
||||
|
||||
pAgg, err := MustString(params[1])
|
||||
if err != nil {
|
||||
return nil, errParsingFunctionParam(err)
|
||||
@@ -413,7 +437,7 @@ func applyTimeShiftPost(series timeseries.TimeSeries, params ...interface{}) (ti
|
||||
if interval == 0 {
|
||||
return series, nil
|
||||
}
|
||||
if shiftForward == true {
|
||||
if shiftForward {
|
||||
interval = -interval
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ package datasource
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/zabbix"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
||||
)
|
||||
|
||||
@@ -17,7 +19,11 @@ import (
|
||||
func (ds *ZabbixDatasource) RootHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
ds.logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method)
|
||||
|
||||
rw.Write([]byte("Hello from Zabbix data source!"))
|
||||
_, err := rw.Write([]byte("Hello from Zabbix data source!"))
|
||||
if err != nil {
|
||||
ds.logger.Warn("Error writing response")
|
||||
}
|
||||
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
@@ -26,7 +32,7 @@ func (ds *ZabbixDatasource) ZabbixAPIHandler(rw http.ResponseWriter, req *http.R
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
defer req.Body.Close()
|
||||
if err != nil || len(body) == 0 {
|
||||
writeError(rw, http.StatusBadRequest, err)
|
||||
@@ -67,7 +73,7 @@ func (ds *ZabbixDatasource) DBConnectionPostProcessingHandler(rw http.ResponseWr
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
defer req.Body.Close()
|
||||
if err != nil || len(body) == 0 {
|
||||
writeError(rw, http.StatusBadRequest, err)
|
||||
@@ -95,6 +101,9 @@ func (ds *ZabbixDatasource) DBConnectionPostProcessingHandler(rw http.ResponseWr
|
||||
reqData.Query.TimeRange.To = time.Unix(reqData.TimeRange.To, 0)
|
||||
|
||||
frames, err := dsInstance.applyDataProcessing(req.Context(), &reqData.Query, reqData.Series, true)
|
||||
if err != nil {
|
||||
writeError(rw, http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
resultJson, err := json.Marshal(frames)
|
||||
if err != nil {
|
||||
@@ -103,7 +112,11 @@ func (ds *ZabbixDatasource) DBConnectionPostProcessingHandler(rw http.ResponseWr
|
||||
|
||||
rw.Header().Add("Content-Type", "application/json")
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.Write(resultJson)
|
||||
|
||||
_, err = rw.Write(resultJson)
|
||||
if err != nil {
|
||||
ds.logger.Warn("Error writing response")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,7 +128,11 @@ func writeResponse(rw http.ResponseWriter, result *ZabbixAPIResourceResponse) {
|
||||
|
||||
rw.Header().Add("Content-Type", "application/json")
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.Write(resultJson)
|
||||
|
||||
_, err = rw.Write(resultJson)
|
||||
if err != nil {
|
||||
log.DefaultLogger.Warn("Error writing response")
|
||||
}
|
||||
}
|
||||
|
||||
func writeError(rw http.ResponseWriter, statusCode int, err error) {
|
||||
@@ -132,5 +149,9 @@ func writeError(rw http.ResponseWriter, statusCode int, err error) {
|
||||
|
||||
rw.Header().Add("Content-Type", "application/json")
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
rw.Write(b)
|
||||
|
||||
_, err = rw.Write(b)
|
||||
if err != nil {
|
||||
log.DefaultLogger.Warn("Error writing response")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ func (ds *ZabbixDatasourceInstance) queryNumericItems(ctx context.Context, query
|
||||
var items []*zabbix.Item
|
||||
var err error
|
||||
zabbixVersion, err := ds.zabbix.GetVersion(ctx)
|
||||
if err != nil {
|
||||
ds.logger.Warn("Error getting Zabbix version")
|
||||
}
|
||||
|
||||
if zabbixVersion >= 54 {
|
||||
items, err = ds.zabbix.GetItems(ctx, groupFilter, hostFilter, itemTagFilter, itemFilter, "num", showDisabled)
|
||||
} else {
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
)
|
||||
|
||||
var emptyParams = map[string]interface{}{}
|
||||
|
||||
var basicDatasourceInfo = &backend.DataSourceInstanceSettings{
|
||||
ID: 1,
|
||||
Name: "TestDatasource",
|
||||
@@ -17,13 +15,6 @@ var basicDatasourceInfo = &backend.DataSourceInstanceSettings{
|
||||
JSONData: []byte(`{"username":"username", "password":"password", "cacheTTL":"10m", "authType":"token"}`),
|
||||
}
|
||||
|
||||
func mockZabbixQuery(method string, params zabbix.ZabbixAPIParams) *zabbix.ZabbixAPIRequest {
|
||||
return &zabbix.ZabbixAPIRequest{
|
||||
Method: method,
|
||||
Params: params,
|
||||
}
|
||||
}
|
||||
|
||||
func MockZabbixDataSource(body string, statusCode int) *ZabbixDatasourceInstance {
|
||||
zabbixSettings, _ := settings.ReadZabbixSettings(basicDatasourceInfo)
|
||||
zabbixClient, _ := zabbix.MockZabbixClient(basicDatasourceInfo, body, statusCode)
|
||||
|
||||
Reference in New Issue
Block a user