Option for using zabbix mapping, closes #1128
This commit is contained in:
@@ -41,6 +41,8 @@ datasources:
|
|||||||
disableReadOnlyUsersAck: true
|
disableReadOnlyUsersAck: true
|
||||||
# Disable time series data alignment
|
# Disable time series data alignment
|
||||||
disableDataAlignment: false
|
disableDataAlignment: false
|
||||||
|
# Use value mapping from Zabbix
|
||||||
|
useZabbixValueMapping: true
|
||||||
version: 1
|
version: 1
|
||||||
editable: false
|
editable: false
|
||||||
|
|
||||||
|
|||||||
@@ -288,6 +288,11 @@
|
|||||||
checked="ctrl.target.options.showDisabledItems"
|
checked="ctrl.target.options.showDisabledItems"
|
||||||
on-change="ctrl.onQueryOptionChange()">
|
on-change="ctrl.onQueryOptionChange()">
|
||||||
</gf-form-switch>
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label-class="width-10"
|
||||||
|
label="Use Zabbix value mapping"
|
||||||
|
checked="ctrl.target.options.useZabbixValueMapping"
|
||||||
|
on-change="ctrl.onQueryOptionChange()">
|
||||||
|
</gf-form-switch>
|
||||||
<gf-form-switch class="gf-form" label-class="width-10"
|
<gf-form-switch class="gf-form" label-class="width-10"
|
||||||
label="Disable data alignment"
|
label="Disable data alignment"
|
||||||
checked="ctrl.target.options.disableDataAlignment"
|
checked="ctrl.target.options.disableDataAlignment"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import * as c from './constants';
|
|||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
import * as metricFunctions from './metricFunctions';
|
import * as metricFunctions from './metricFunctions';
|
||||||
import * as migrations from './migrations';
|
import * as migrations from './migrations';
|
||||||
import { ShowProblemTypes } from './types';
|
import { ShowProblemTypes, ZabbixMetricsQuery } from './types';
|
||||||
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
|
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
|
||||||
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ function getTargetDefaults() {
|
|||||||
showDisabledItems: false,
|
showDisabledItems: false,
|
||||||
skipEmptyValues: false,
|
skipEmptyValues: false,
|
||||||
disableDataAlignment: false,
|
disableDataAlignment: false,
|
||||||
|
useZabbixValueMapping: false,
|
||||||
},
|
},
|
||||||
table: {
|
table: {
|
||||||
'skipEmptyValues': false
|
'skipEmptyValues': false
|
||||||
@@ -456,6 +457,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
const metricOptionsMap = {
|
const metricOptionsMap = {
|
||||||
showDisabledItems: "Show disabled items",
|
showDisabledItems: "Show disabled items",
|
||||||
disableDataAlignment: "Disable data alignment",
|
disableDataAlignment: "Disable data alignment",
|
||||||
|
useZabbixValueMapping: "Use Zabbix value mapping",
|
||||||
};
|
};
|
||||||
|
|
||||||
const problemsOptionsMap = {
|
const problemsOptionsMap = {
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import _ from 'lodash';
|
|||||||
import TableModel from 'grafana/app/core/table_model';
|
import TableModel from 'grafana/app/core/table_model';
|
||||||
import * as c from './constants';
|
import * as c from './constants';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
import { ArrayVector, DataFrame, DataQuery, Field, FieldType, MutableDataFrame, TIME_SERIES_TIME_FIELD_NAME, TIME_SERIES_VALUE_FIELD_NAME } from '@grafana/data';
|
import { ArrayVector, DataFrame, Field, FieldType, MutableDataFrame, TIME_SERIES_TIME_FIELD_NAME, TIME_SERIES_VALUE_FIELD_NAME } from '@grafana/data';
|
||||||
|
import { ZabbixMetricsQuery } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert Zabbix API history.get response to Grafana format
|
* Convert Zabbix API history.get response to Grafana format
|
||||||
@@ -60,7 +61,8 @@ function convertHistory(history, items, addHostName, convertPointCallback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function seriesToDataFrame(timeseries, target: DataQuery, valueMappings?: any[], fieldType?: FieldType): DataFrame {
|
export function seriesToDataFrame(timeseries, target: ZabbixMetricsQuery, valueMappings?: any[], fieldType?: FieldType): DataFrame {
|
||||||
|
console.log(target);
|
||||||
const { datapoints, scopedVars, target: seriesName, item } = timeseries;
|
const { datapoints, scopedVars, target: seriesName, item } = timeseries;
|
||||||
|
|
||||||
const timeFiled: Field = {
|
const timeFiled: Field = {
|
||||||
@@ -122,8 +124,8 @@ export function seriesToDataFrame(timeseries, target: DataQuery, valueMappings?:
|
|||||||
|
|
||||||
// Try to use value mapping from Zabbix
|
// Try to use value mapping from Zabbix
|
||||||
const mappings = utils.getValueMapping(item, valueMappings);
|
const mappings = utils.getValueMapping(item, valueMappings);
|
||||||
if (mappings) {
|
if (mappings && target.options?.useZabbixValueMapping) {
|
||||||
console.log(`Datasource: value mapping detected`);
|
console.log(`Datasource: using Zabbix value mapping`);
|
||||||
valueFiled.config.mappings = mappings;
|
valueFiled.config.mappings = mappings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ export interface ZabbixMetricsQuery extends DataQuery {
|
|||||||
triggers: { minSeverity: string; acknowledged: boolean; count: number; };
|
triggers: { minSeverity: string; acknowledged: boolean; count: number; };
|
||||||
queryType: string;
|
queryType: string;
|
||||||
datasourceId: number;
|
datasourceId: number;
|
||||||
group: { filter: string; name: string; };
|
group: { filter: string; name?: string; };
|
||||||
host: { filter: string; name: string; };
|
host: { filter: string; name?: string; };
|
||||||
application: { filter: string; name: string; };
|
application: { filter: string; name?: string; };
|
||||||
item: { filter: string; name: string; };
|
item: { filter: string; name?: string; };
|
||||||
textFilter: string;
|
textFilter: string;
|
||||||
mode: number;
|
mode: number;
|
||||||
itemids: number[];
|
itemids: number[];
|
||||||
@@ -62,6 +62,7 @@ export interface ZabbixQueryOptions {
|
|||||||
showDisabledItems?: boolean;
|
showDisabledItems?: boolean;
|
||||||
skipEmptyValues?: boolean;
|
skipEmptyValues?: boolean;
|
||||||
disableDataAlignment?: boolean;
|
disableDataAlignment?: boolean;
|
||||||
|
useZabbixValueMapping?: boolean;
|
||||||
// Problems options
|
// Problems options
|
||||||
minSeverity?: number;
|
minSeverity?: number;
|
||||||
sortProblems?: string;
|
sortProblems?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user