Progress
This commit is contained in:
@@ -9,13 +9,35 @@ import dataProcessor from './dataProcessor';
|
||||
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'
|
||||
|
||||
const DEFAULT_ZABBIX_VERSION = 3;
|
||||
const DEFAULT_ZABBIX_VERSION = 3
|
||||
|
||||
export class ZabbixDatasource {
|
||||
export class ZabbixDatasource extends DataSourceApi {
|
||||
|
||||
/** @ngInject */
|
||||
/**
|
||||
* @ngInject
|
||||
* @param {DataSourceInstanceSettings} instanceSettings
|
||||
* @param {TemplateSrv} templateSrv
|
||||
* @param {BackendSrv} backendSrv
|
||||
* @param {DataSourceSrv} datasourceSrv
|
||||
* @param {ZabbixAlertingService} zabbixAlertingSrv
|
||||
*/
|
||||
constructor(instanceSettings, templateSrv, backendSrv, datasourceSrv, zabbixAlertingSrv) {
|
||||
super(instanceSettings)
|
||||
this.type = 'zabbix'
|
||||
this.templateSrv = templateSrv;
|
||||
this.backendSrv = backendSrv;
|
||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||
@@ -185,11 +207,26 @@ export class ZabbixDatasource {
|
||||
tsdbRequestData.to = options.range.to.valueOf().toString();
|
||||
}
|
||||
|
||||
return this.backendSrv.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: tsdbRequestData
|
||||
});
|
||||
return this.backendSrv.post('/api/tsdb/query', tsdbRequestData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<ZabbixConnectionInfo>}
|
||||
*/
|
||||
doTSDBConnectionTest() {
|
||||
/**
|
||||
* @type {{ queries: ZabbixConnectionTestQuery[] }}
|
||||
*/
|
||||
const tsdbRequestData = {
|
||||
queries: [
|
||||
{
|
||||
datasourceId: this.datasourceId,
|
||||
queryType: 'connectionTest'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
return this.backendSrv.post('/api/tsdb/query', tsdbRequestData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,8 +423,7 @@ export class ZabbixDatasource {
|
||||
* Test connection to Zabbix API and external history DB.
|
||||
*/
|
||||
testDatasource() {
|
||||
return this.zabbix.testDataSource()
|
||||
.then(result => {
|
||||
return this.doTSDBConnectionTest().then(result => {
|
||||
const { zabbixVersion, dbConnectorStatus } = result;
|
||||
let message = `Zabbix API version: ${zabbixVersion}`;
|
||||
if (dbConnectorStatus) {
|
||||
@@ -398,8 +434,7 @@ export class ZabbixDatasource {
|
||||
title: "Success",
|
||||
message: message
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
}).catch(error => {
|
||||
if (error instanceof ZabbixAPIError) {
|
||||
return {
|
||||
status: "error",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import { ZabbixMetricsQuery } from './types';
|
||||
|
||||
/**
|
||||
* Query format migration.
|
||||
@@ -19,7 +20,7 @@ export function isGrafana2target(target) {
|
||||
}
|
||||
}
|
||||
|
||||
export function migrateFrom2To3version(target) {
|
||||
export function migrateFrom2To3version(target: ZabbixMetricsQuery) {
|
||||
target.group.filter = target.group.name === "*" ? "/.*/" : target.group.name;
|
||||
target.host.filter = target.host.name === "*" ? convertToRegex(target.hostFilter) : target.host.name;
|
||||
target.application.filter = target.application.name === "*" ? "" : target.application.name;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { loadPluginCss } from 'grafana/app/plugins/sdk';
|
||||
import { loadPluginCss } from '@grafana/runtime';
|
||||
import { ZabbixDatasource } from './datasource';
|
||||
import { ZabbixQueryController } from './query.controller';
|
||||
import { ZabbixDSConfigController } from './config.controller';
|
||||
|
||||
35
src/datasource-zabbix/types.ts
Normal file
35
src/datasource-zabbix/types.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { DataQuery } from '@grafana/ui';
|
||||
|
||||
export interface ZabbixConnectionInfo {
|
||||
zabbixVersion: string;
|
||||
dbConnectorStatus: {
|
||||
dsType: string;
|
||||
dsName: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ZabbixConnectionTestQuery {
|
||||
datasourceId: number;
|
||||
queryType: string;
|
||||
}
|
||||
|
||||
export interface ZabbixMetricsQuery extends DataQuery {
|
||||
triggers: { minSeverity: string; acknowledged: boolean; count: number; };
|
||||
queryType: string;
|
||||
datasourceId: number;
|
||||
functions: { name: string; params: any; def: { name: string; params: any; } }[];
|
||||
options: any;
|
||||
textFilter: string;
|
||||
mode: number;
|
||||
itemids: number[];
|
||||
useCaptureGroups: boolean;
|
||||
group: { filter: string; name: string; };
|
||||
host: { filter: string; name: string; };
|
||||
hostFilter: string;
|
||||
application: { filter: string; name: string; };
|
||||
item: { filter: string; name: string; };
|
||||
itemFilter: string;
|
||||
}
|
||||
|
||||
export { TemplateSrv } from 'grafana/app/features/templating/template_srv';
|
||||
export { DashboardSrv } from 'grafana/app/features/dashboard/dashboard_srv';
|
||||
Reference in New Issue
Block a user