This commit is contained in:
Alec Sears
2019-10-18 16:02:23 -05:00
parent ca145c9acb
commit e153473421
13 changed files with 6490 additions and 962 deletions

6
go.mod
View File

@@ -5,6 +5,7 @@ go 1.12
require ( require (
github.com/bitly/go-simplejson v0.5.0 github.com/bitly/go-simplejson v0.5.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect 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/google/go-cmp v0.3.1 // indirect
github.com/grafana/grafana_plugin_model v0.0.0-20180518082423-84176c64269d github.com/grafana/grafana_plugin_model v0.0.0-20180518082423-84176c64269d
github.com/hashicorp/go-hclog v0.9.2 github.com/hashicorp/go-hclog v0.9.2
@@ -12,7 +13,8 @@ require (
github.com/kr/pretty v0.1.0 // indirect github.com/kr/pretty v0.1.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.8.1 // indirect github.com/pkg/errors v0.8.1 // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
golang.org/x/text v0.3.2 // indirect
gotest.tools v2.2.0+incompatible gotest.tools v2.2.0+incompatible
) )

13
go.sum
View File

@@ -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/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 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 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 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 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= 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/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 h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
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/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 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-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 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-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 h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 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 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.14.0 h1:ArxJuB1NWfPY6r9Gp9gqwplT0Ge7nqv9msgu03lHLmo= google.golang.org/grpc v1.14.0 h1:ArxJuB1NWfPY6r9Gp9gqwplT0Ge7nqv9msgu03lHLmo=

View File

@@ -79,9 +79,9 @@
"style-loader": "^0.23.1", "style-loader": "^0.23.1",
"tether-drop": "^1.4.2", "tether-drop": "^1.4.2",
"ts-jest": "^23.10.5", "ts-jest": "^23.10.5",
"ts-loader": "^4.4.1", "ts-loader": "^6.2.0",
"tslint": "^5.11.0", "tslint": "^5.11.0",
"typescript": "^2.9.2", "typescript": "^3.6.4",
"webpack": "^4.22.0", "webpack": "^4.22.0",
"webpack-cli": "^3.1.2" "webpack-cli": "^3.1.2"
}, },

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
@@ -37,10 +38,11 @@ func (b *ZabbixBackend) Query(ctx context.Context, tsdbReq *datasource.Datasourc
switch queryType { switch queryType {
case "zabbixAPI": case "zabbixAPI":
return zabbixDs.ZabbixAPIQuery(ctx, tsdbReq) return zabbixDs.ZabbixAPIQuery(ctx, tsdbReq)
case "zabbixConnectionTest": case "connectionTest":
return zabbixDs.TestConnection(ctx, tsdbReq) return zabbixDs.TestConnection(ctx, tsdbReq)
default: 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 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(),
},
},
}
}

View File

@@ -3,10 +3,12 @@ package main
import ( import (
"testing" "testing"
simplejson "github.com/bitly/go-simplejson"
"github.com/grafana/grafana_plugin_model/go/datasource" "github.com/grafana/grafana_plugin_model/go/datasource"
hclog "github.com/hashicorp/go-hclog" hclog "github.com/hashicorp/go-hclog"
cache "github.com/patrickmn/go-cache" cache "github.com/patrickmn/go-cache"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/assert/cmp"
) )
func TestZabbixBackend_getCachedDatasource(t *testing.T) { 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)
})
}
}

View File

@@ -110,7 +110,7 @@ func (ds *ZabbixDatasource) ZabbixAPIQuery(ctx context.Context, tsdbReq *datasou
resultByte, _ := result.(*simplejson.Json).MarshalJSON() resultByte, _ := result.(*simplejson.Json).MarshalJSON()
ds.logger.Debug("ZabbixAPIQuery", "result", string(resultByte)) 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 // 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) auth, err := ds.loginWithDs(ctx, dsInfo)
if err != nil { if err != nil {
return nil, err return BuildErrorResponse(fmt.Errorf("Authentication failed: %w", err)), nil
} }
ds.authToken = auth ds.authToken = auth
response, err := ds.zabbixAPIRequest(ctx, dsInfo.GetUrl(), "apiinfo.version", map[string]interface{}{}, "") response, err := ds.zabbixAPIRequest(ctx, dsInfo.GetUrl(), "apiinfo.version", map[string]interface{}{}, "")
if err != nil { if err != nil {
ds.logger.Debug("TestConnection", "error", err) ds.logger.Debug("TestConnection", "error", err)
return nil, err return BuildErrorResponse(fmt.Errorf("Version check failed: %w", err)), nil
} }
resultByte, _ := response.MarshalJSON() resultByte, _ := response.MarshalJSON()
@@ -136,24 +136,7 @@ func (ds *ZabbixDatasource) TestConnection(ctx context.Context, tsdbReq *datasou
ZabbixVersion: response.MustString(), ZabbixVersion: response.MustString(),
} }
return ds.BuildResponse(testResponse) return 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
} }
// ZabbixRequest checks authentication and makes a request to the Zabbix API // ZabbixRequest checks authentication and makes a request to the Zabbix API

View File

@@ -1,71 +1 @@
package main 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)
})
}
}

View File

@@ -10,18 +10,12 @@ import responseHandler from './responseHandler';
import { Zabbix } from './zabbix/zabbix'; import { Zabbix } from './zabbix/zabbix';
import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore'; import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore';
import { import {
PluginMeta,
DataSourceApi, DataSourceApi,
DataSourceInstanceSettings, DataSourceInstanceSettings,
DataQueryError,
DataQueryRequest,
DataQueryResponse,
AnnotationQueryRequest,
MetricFindValue,
} from '@grafana/ui'; } from '@grafana/ui';
import { BackendSrv, DataSourceSrv } from '@grafana/runtime'; import { BackendSrv, DataSourceSrv } from '@grafana/runtime';
import { ZabbixAlertingService } from './zabbixAlerting.service' import { ZabbixAlertingService } from './zabbixAlerting.service'
import { ZabbixConnectionTestQuery, ZabbixMetricsQuery, ZabbixConnectionInfo, TemplateSrv } from './types' import { ZabbixConnectionTestQuery, ZabbixConnectionInfo, TemplateSrv, TSDBResponse } from './types'
const DEFAULT_ZABBIX_VERSION = 3 const DEFAULT_ZABBIX_VERSION = 3
@@ -211,7 +205,7 @@ export class ZabbixDatasource extends DataSourceApi {
} }
/** /**
* @returns {Promise<ZabbixConnectionInfo>} * @returns {Promise<TSDBResponse>}
*/ */
doTSDBConnectionTest() { doTSDBConnectionTest() {
/** /**
@@ -422,9 +416,13 @@ export class ZabbixDatasource extends DataSourceApi {
/** /**
* Test connection to Zabbix API and external history DB. * Test connection to Zabbix API and external history DB.
*/ */
testDatasource() { async testDatasource() {
return this.doTSDBConnectionTest().then(result => { try {
const { zabbixVersion, dbConnectorStatus } = result; const result = await this.doTSDBConnectionTest();
/**
* @type {ZabbixConnectionInfo}
*/
const { zabbixVersion, dbConnectorStatus } = result.results["zabbixAPI"].meta;
let message = `Zabbix API version: ${zabbixVersion}`; let message = `Zabbix API version: ${zabbixVersion}`;
if (dbConnectorStatus) { if (dbConnectorStatus) {
message += `, DB connector type: ${dbConnectorStatus.dsType}`; message += `, DB connector type: ${dbConnectorStatus.dsType}`;
@@ -434,26 +432,30 @@ export class ZabbixDatasource extends DataSourceApi {
title: "Success", title: "Success",
message: message message: message
}; };
}).catch(error => { }
catch (error) {
if (error instanceof ZabbixAPIError) { if (error instanceof ZabbixAPIError) {
return { return {
status: "error", status: "error",
title: error.message, title: error.message,
message: error.message message: error.message
}; };
} else if (error.data && error.data.message) { }
else if (error.data && error.data.message) {
return { return {
status: "error", status: "error",
title: "Connection failed", title: "Zabbix Client Error",
message: "Connection failed: " + error.data.message message: error.data.message
}; };
} else if (typeof(error) === 'string') { }
else if (typeof (error) === 'string') {
return { return {
status: "error", status: "error",
title: "Connection failed", title: "Unknown Error",
message: "Connection failed: " + error message: error
}; };
} else { }
else {
console.log(error); console.log(error);
return { return {
status: "error", status: "error",
@@ -461,7 +463,7 @@ export class ZabbixDatasource extends DataSourceApi {
message: "Could not connect to given url" message: "Could not connect to given url"
}; };
} }
}); }
} }
/** /**

View File

@@ -31,5 +31,55 @@ export interface ZabbixMetricsQuery extends DataQuery {
itemFilter: string; itemFilter: string;
} }
export { TemplateSrv } from 'grafana/app/features/templating/template_srv'; // export { TemplateSrv } from 'grafana/app/features/templating/template_srv';
export { DashboardSrv } from 'grafana/app/features/dashboard/dashboard_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;
}

View File

@@ -110,37 +110,37 @@ export class Zabbix {
} }
``` ```
*/ */
testDataSource() { // testDataSource() {
let zabbixVersion; // let zabbixVersion;
let dbConnectorStatus; // let dbConnectorStatus;
return this.getVersion() // return this.getVersion()
.then(version => { // .then(version => {
zabbixVersion = version; // zabbixVersion = version;
return this.login(); // return this.login();
}) // })
.then(() => { // .then(() => {
if (this.enableDirectDBConnection) { // if (this.enableDirectDBConnection) {
return this.dbConnector.testDataSource(); // return this.dbConnector.testDataSource();
} else { // } else {
return Promise.resolve(); // return Promise.resolve();
} // }
}) // })
.catch(error => { // .catch(error => {
if (error instanceof ZabbixNotImplemented) { // if (error instanceof ZabbixNotImplemented) {
return Promise.resolve(); // return Promise.resolve();
} // }
return Promise.reject(error); // return Promise.reject(error);
}) // })
.then(testResult => { // .then(testResult => {
if (testResult) { // if (testResult) {
dbConnectorStatus = { // dbConnectorStatus = {
dsType: this.dbConnector.datasourceTypeName, // dsType: this.dbConnector.datasourceTypeName,
dsName: this.dbConnector.datasourceName // dsName: this.dbConnector.datasourceName
}; // };
} // }
return { zabbixVersion, dbConnectorStatus }; // return { zabbixVersion, dbConnectorStatus };
}); // });
} // }
getItemsFromTarget(target, options) { getItemsFromTarget(target, options) {
let parts = ['group', 'host', 'application', 'item']; let parts = ['group', 'host', 'application', 'item'];

View File

@@ -2,9 +2,11 @@ import _ from 'lodash';
import $ from 'jquery'; import $ from 'jquery';
import angular from 'angular'; import angular from 'angular';
class ZabbixAlertingService { export class ZabbixAlertingService {
/** @ngInject */ /**
* @ngInject
*/
constructor(dashboardSrv) { constructor(dashboardSrv) {
this.dashboardSrv = dashboardSrv; this.dashboardSrv = dashboardSrv;
} }

View File

@@ -28,7 +28,7 @@ module.exports = {
externals: [ externals: [
// remove the line below if you don't want to use builtin versions // remove the line below if you don't want to use builtin versions
'jquery', 'lodash', 'moment', 'angular', 'jquery', 'lodash', 'moment', 'angular',
'react', 'react-dom', '@grafana/ui', 'react', 'react-dom', '@grafana/ui', '@grafana/runtime',
function (context, request, callback) { function (context, request, callback) {
var prefix = 'grafana/'; var prefix = 'grafana/';
if (request.indexOf(prefix) === 0) { if (request.indexOf(prefix) === 0) {

7071
yarn.lock

File diff suppressed because it is too large Load Diff