Finish
This commit is contained in:
6
go.mod
6
go.mod
@@ -5,6 +5,7 @@ go 1.12
|
||||
require (
|
||||
github.com/bitly/go-simplejson v0.5.0
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
|
||||
github.com/golang/protobuf v1.3.2 // indirect
|
||||
github.com/google/go-cmp v0.3.1 // indirect
|
||||
github.com/grafana/grafana_plugin_model v0.0.0-20180518082423-84176c64269d
|
||||
github.com/hashicorp/go-hclog v0.9.2
|
||||
@@ -12,7 +13,8 @@ require (
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
|
||||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
|
||||
golang.org/x/text v0.3.2 // indirect
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
|
||||
13
go.sum
13
go.sum
@@ -9,6 +9,8 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekf
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/grafana/grafana_plugin_model v0.0.0-20180518082423-84176c64269d h1:Ep6bjWDwurT9NpUATiqa8NYIllmZbLDXLn6Ib4lCtAA=
|
||||
@@ -42,18 +44,21 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc h1:WiYx1rIFmx8c0mXAFtv5D/mHyKe1+jmuP7PViuwqwuQ=
|
||||
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
|
||||
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v1.14.0 h1:ArxJuB1NWfPY6r9Gp9gqwplT0Ge7nqv9msgu03lHLmo=
|
||||
|
||||
@@ -79,9 +79,9 @@
|
||||
"style-loader": "^0.23.1",
|
||||
"tether-drop": "^1.4.2",
|
||||
"ts-jest": "^23.10.5",
|
||||
"ts-loader": "^4.4.1",
|
||||
"ts-loader": "^6.2.0",
|
||||
"tslint": "^5.11.0",
|
||||
"typescript": "^2.9.2",
|
||||
"typescript": "^3.6.4",
|
||||
"webpack": "^4.22.0",
|
||||
"webpack-cli": "^3.1.2"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@@ -37,10 +38,11 @@ func (b *ZabbixBackend) Query(ctx context.Context, tsdbReq *datasource.Datasourc
|
||||
switch queryType {
|
||||
case "zabbixAPI":
|
||||
return zabbixDs.ZabbixAPIQuery(ctx, tsdbReq)
|
||||
case "zabbixConnectionTest":
|
||||
case "connectionTest":
|
||||
return zabbixDs.TestConnection(ctx, tsdbReq)
|
||||
default:
|
||||
return nil, errors.New("Query is not implemented yet")
|
||||
err = errors.New("Query not implemented")
|
||||
return BuildErrorResponse(err), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,3 +75,32 @@ func GetQueryType(tsdbReq *datasource.DatasourceRequest) (string, error) {
|
||||
}
|
||||
return queryType, nil
|
||||
}
|
||||
|
||||
// BuildResponse transforms a Zabbix API response to a DatasourceResponse
|
||||
func BuildResponse(responseData interface{}) (*datasource.DatasourceResponse, error) {
|
||||
jsonBytes, err := json.Marshal(responseData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: string(jsonBytes),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BuildErrorResponse creates a QueryResult that forwards an error to the front-end
|
||||
func BuildErrorResponse(err error) *datasource.DatasourceResponse {
|
||||
return &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
Error: err.Error(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ package main
|
||||
import (
|
||||
"testing"
|
||||
|
||||
simplejson "github.com/bitly/go-simplejson"
|
||||
"github.com/grafana/grafana_plugin_model/go/datasource"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func TestZabbixBackend_getCachedDatasource(t *testing.T) {
|
||||
@@ -79,3 +81,63 @@ func TestZabbixBackend_getCachedDatasource(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildResponse(t *testing.T) {
|
||||
jsonData := simplejson.New()
|
||||
jsonData.Set("testing", []int{5, 12, 75})
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
responseData interface{}
|
||||
want *datasource.DatasourceResponse
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "simplejson Response",
|
||||
responseData: jsonData,
|
||||
want: &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: `{"testing":[5,12,75]}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Connetion Status Response",
|
||||
responseData: connectionTestResponse{
|
||||
ZabbixVersion: "2.4",
|
||||
DbConnectorStatus: &dbConnectionStatus{
|
||||
DsType: "mysql",
|
||||
DsName: "MyDatabase",
|
||||
},
|
||||
},
|
||||
want: &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: `{"zabbixVersion":"2.4","dbConnectorStatus":{"dsType":"mysql","dsName":"MyDatabase"}}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Unmarshalable",
|
||||
responseData: 2i,
|
||||
wantErr: "json: unsupported type: complex128",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := BuildResponse(tt.responseData)
|
||||
if tt.wantErr != "" {
|
||||
assert.Error(t, err, tt.wantErr)
|
||||
assert.Assert(t, cmp.Nil(got))
|
||||
return
|
||||
}
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, got, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func (ds *ZabbixDatasource) ZabbixAPIQuery(ctx context.Context, tsdbReq *datasou
|
||||
resultByte, _ := result.(*simplejson.Json).MarshalJSON()
|
||||
ds.logger.Debug("ZabbixAPIQuery", "result", string(resultByte))
|
||||
|
||||
return ds.BuildResponse(result)
|
||||
return BuildResponse(result)
|
||||
}
|
||||
|
||||
// TestConnection checks authentication and version of the Zabbix API and returns that info
|
||||
@@ -119,14 +119,14 @@ func (ds *ZabbixDatasource) TestConnection(ctx context.Context, tsdbReq *datasou
|
||||
|
||||
auth, err := ds.loginWithDs(ctx, dsInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return BuildErrorResponse(fmt.Errorf("Authentication failed: %w", err)), nil
|
||||
}
|
||||
ds.authToken = auth
|
||||
|
||||
response, err := ds.zabbixAPIRequest(ctx, dsInfo.GetUrl(), "apiinfo.version", map[string]interface{}{}, "")
|
||||
if err != nil {
|
||||
ds.logger.Debug("TestConnection", "error", err)
|
||||
return nil, err
|
||||
return BuildErrorResponse(fmt.Errorf("Version check failed: %w", err)), nil
|
||||
}
|
||||
|
||||
resultByte, _ := response.MarshalJSON()
|
||||
@@ -136,24 +136,7 @@ func (ds *ZabbixDatasource) TestConnection(ctx context.Context, tsdbReq *datasou
|
||||
ZabbixVersion: response.MustString(),
|
||||
}
|
||||
|
||||
return ds.BuildResponse(testResponse)
|
||||
}
|
||||
|
||||
// BuildResponse transforms a Zabbix API response to a DatasourceResponse
|
||||
func (ds *ZabbixDatasource) BuildResponse(responseData interface{}) (*datasource.DatasourceResponse, error) {
|
||||
jsonBytes, err := json.Marshal(responseData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: string(jsonBytes),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
return BuildResponse(testResponse)
|
||||
}
|
||||
|
||||
// ZabbixRequest checks authentication and makes a request to the Zabbix API
|
||||
|
||||
@@ -1,71 +1 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
simplejson "github.com/bitly/go-simplejson"
|
||||
"github.com/grafana/grafana_plugin_model/go/datasource"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/assert/cmp"
|
||||
)
|
||||
|
||||
func TestZabbixDatasource_BuildResponse(t *testing.T) {
|
||||
jsonData := simplejson.New()
|
||||
jsonData.Set("testing", []int{5, 12, 75})
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
responseData interface{}
|
||||
want *datasource.DatasourceResponse
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "simplejson Response",
|
||||
responseData: jsonData,
|
||||
want: &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: `{"testing":[5,12,75]}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Connetion Status Response",
|
||||
responseData: connectionTestResponse{
|
||||
ZabbixVersion: "2.4",
|
||||
DbConnectorStatus: &dbConnectionStatus{
|
||||
DsType: "mysql",
|
||||
DsName: "MyDatabase",
|
||||
},
|
||||
},
|
||||
want: &datasource.DatasourceResponse{
|
||||
Results: []*datasource.QueryResult{
|
||||
&datasource.QueryResult{
|
||||
RefId: "zabbixAPI",
|
||||
MetaJson: `{"zabbixVersion":"2.4","dbConnectorStatus":{"dsType":"mysql","dsName":"MyDatabase"}}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Unmarshalable",
|
||||
responseData: 2i,
|
||||
wantErr: "json: unsupported type: complex128",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ds := NewZabbixDatasource()
|
||||
got, err := ds.BuildResponse(tt.responseData)
|
||||
if tt.wantErr != "" {
|
||||
assert.Error(t, err, tt.wantErr)
|
||||
assert.Assert(t, cmp.Nil(got))
|
||||
return
|
||||
}
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, got, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,12 @@ import responseHandler from './responseHandler';
|
||||
import { Zabbix } from './zabbix/zabbix';
|
||||
import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore';
|
||||
import {
|
||||
PluginMeta,
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
DataQueryError,
|
||||
DataQueryRequest,
|
||||
DataQueryResponse,
|
||||
AnnotationQueryRequest,
|
||||
MetricFindValue,
|
||||
} from '@grafana/ui';
|
||||
import { BackendSrv, DataSourceSrv } from '@grafana/runtime';
|
||||
import { ZabbixAlertingService } from './zabbixAlerting.service'
|
||||
import { ZabbixConnectionTestQuery, ZabbixMetricsQuery, ZabbixConnectionInfo, TemplateSrv } from './types'
|
||||
import { ZabbixConnectionTestQuery, ZabbixConnectionInfo, TemplateSrv, TSDBResponse } from './types'
|
||||
|
||||
const DEFAULT_ZABBIX_VERSION = 3
|
||||
|
||||
@@ -211,7 +205,7 @@ export class ZabbixDatasource extends DataSourceApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<ZabbixConnectionInfo>}
|
||||
* @returns {Promise<TSDBResponse>}
|
||||
*/
|
||||
doTSDBConnectionTest() {
|
||||
/**
|
||||
@@ -422,9 +416,13 @@ export class ZabbixDatasource extends DataSourceApi {
|
||||
/**
|
||||
* Test connection to Zabbix API and external history DB.
|
||||
*/
|
||||
testDatasource() {
|
||||
return this.doTSDBConnectionTest().then(result => {
|
||||
const { zabbixVersion, dbConnectorStatus } = result;
|
||||
async testDatasource() {
|
||||
try {
|
||||
const result = await this.doTSDBConnectionTest();
|
||||
/**
|
||||
* @type {ZabbixConnectionInfo}
|
||||
*/
|
||||
const { zabbixVersion, dbConnectorStatus } = result.results["zabbixAPI"].meta;
|
||||
let message = `Zabbix API version: ${zabbixVersion}`;
|
||||
if (dbConnectorStatus) {
|
||||
message += `, DB connector type: ${dbConnectorStatus.dsType}`;
|
||||
@@ -434,26 +432,30 @@ export class ZabbixDatasource extends DataSourceApi {
|
||||
title: "Success",
|
||||
message: message
|
||||
};
|
||||
}).catch(error => {
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof ZabbixAPIError) {
|
||||
return {
|
||||
status: "error",
|
||||
title: error.message,
|
||||
message: error.message
|
||||
};
|
||||
} else if (error.data && error.data.message) {
|
||||
}
|
||||
else if (error.data && error.data.message) {
|
||||
return {
|
||||
status: "error",
|
||||
title: "Connection failed",
|
||||
message: "Connection failed: " + error.data.message
|
||||
title: "Zabbix Client Error",
|
||||
message: error.data.message
|
||||
};
|
||||
} else if (typeof(error) === 'string') {
|
||||
}
|
||||
else if (typeof (error) === 'string') {
|
||||
return {
|
||||
status: "error",
|
||||
title: "Connection failed",
|
||||
message: "Connection failed: " + error
|
||||
title: "Unknown Error",
|
||||
message: error
|
||||
};
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
console.log(error);
|
||||
return {
|
||||
status: "error",
|
||||
@@ -461,7 +463,7 @@ export class ZabbixDatasource extends DataSourceApi {
|
||||
message: "Could not connect to given url"
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,5 +31,55 @@ export interface ZabbixMetricsQuery extends DataQuery {
|
||||
itemFilter: string;
|
||||
}
|
||||
|
||||
export { TemplateSrv } from 'grafana/app/features/templating/template_srv';
|
||||
export { DashboardSrv } from 'grafana/app/features/dashboard/dashboard_srv';
|
||||
// export { TemplateSrv } from 'grafana/app/features/templating/template_srv';
|
||||
// export { DashboardSrv } from 'grafana/app/features/dashboard/dashboard_srv';
|
||||
|
||||
// The paths of these files have moved around in Grafana and they don't resolve properly
|
||||
// either. Safer not to bother trying to import them just for type hinting.
|
||||
|
||||
export interface TemplateSrv {
|
||||
variables: {
|
||||
name: string;
|
||||
};
|
||||
highlightVariablesAsHtml(str: any): any;
|
||||
replace(target: any, scopedVars?: any, format?: any): any;
|
||||
}
|
||||
|
||||
export interface DashboardSrv {
|
||||
dash: any
|
||||
}
|
||||
|
||||
// Grafana types from backend code
|
||||
|
||||
type RowValues = object[];
|
||||
type TimePoint = [number?, number?];
|
||||
type TimeSeriesPoints = TimePoint[];
|
||||
type TimeSeriesSlice = TimeSeries[];
|
||||
|
||||
interface TimeSeries {
|
||||
name: string;
|
||||
points: TimeSeriesPoints;
|
||||
tags: { [key: string]: string };
|
||||
}
|
||||
|
||||
interface TableColumn {
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface Table {
|
||||
columns: TableColumn[];
|
||||
rows: RowValues[];
|
||||
}
|
||||
|
||||
interface QueryResult {
|
||||
error: string;
|
||||
refId: string;
|
||||
meta: any;
|
||||
series: TimeSeriesSlice[];
|
||||
tables: Table[];
|
||||
}
|
||||
|
||||
export interface TSDBResponse {
|
||||
results: { [key: string]: QueryResult };
|
||||
message: string;
|
||||
}
|
||||
|
||||
@@ -110,37 +110,37 @@ export class Zabbix {
|
||||
}
|
||||
```
|
||||
*/
|
||||
testDataSource() {
|
||||
let zabbixVersion;
|
||||
let dbConnectorStatus;
|
||||
return this.getVersion()
|
||||
.then(version => {
|
||||
zabbixVersion = version;
|
||||
return this.login();
|
||||
})
|
||||
.then(() => {
|
||||
if (this.enableDirectDBConnection) {
|
||||
return this.dbConnector.testDataSource();
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (error instanceof ZabbixNotImplemented) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
.then(testResult => {
|
||||
if (testResult) {
|
||||
dbConnectorStatus = {
|
||||
dsType: this.dbConnector.datasourceTypeName,
|
||||
dsName: this.dbConnector.datasourceName
|
||||
};
|
||||
}
|
||||
return { zabbixVersion, dbConnectorStatus };
|
||||
});
|
||||
}
|
||||
// testDataSource() {
|
||||
// let zabbixVersion;
|
||||
// let dbConnectorStatus;
|
||||
// return this.getVersion()
|
||||
// .then(version => {
|
||||
// zabbixVersion = version;
|
||||
// return this.login();
|
||||
// })
|
||||
// .then(() => {
|
||||
// if (this.enableDirectDBConnection) {
|
||||
// return this.dbConnector.testDataSource();
|
||||
// } else {
|
||||
// return Promise.resolve();
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// if (error instanceof ZabbixNotImplemented) {
|
||||
// return Promise.resolve();
|
||||
// }
|
||||
// return Promise.reject(error);
|
||||
// })
|
||||
// .then(testResult => {
|
||||
// if (testResult) {
|
||||
// dbConnectorStatus = {
|
||||
// dsType: this.dbConnector.datasourceTypeName,
|
||||
// dsName: this.dbConnector.datasourceName
|
||||
// };
|
||||
// }
|
||||
// return { zabbixVersion, dbConnectorStatus };
|
||||
// });
|
||||
// }
|
||||
|
||||
getItemsFromTarget(target, options) {
|
||||
let parts = ['group', 'host', 'application', 'item'];
|
||||
|
||||
@@ -2,9 +2,11 @@ import _ from 'lodash';
|
||||
import $ from 'jquery';
|
||||
import angular from 'angular';
|
||||
|
||||
class ZabbixAlertingService {
|
||||
export class ZabbixAlertingService {
|
||||
|
||||
/** @ngInject */
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
constructor(dashboardSrv) {
|
||||
this.dashboardSrv = dashboardSrv;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
externals: [
|
||||
// remove the line below if you don't want to use builtin versions
|
||||
'jquery', 'lodash', 'moment', 'angular',
|
||||
'react', 'react-dom', '@grafana/ui',
|
||||
'react', 'react-dom', '@grafana/ui', '@grafana/runtime',
|
||||
function (context, request, callback) {
|
||||
var prefix = 'grafana/';
|
||||
if (request.indexOf(prefix) === 0) {
|
||||
|
||||
Reference in New Issue
Block a user