Finish
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user