Skip to content

Commit

Permalink
Option for using zabbix mapping, closes #1128
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Feb 4, 2021
1 parent fdaadaf commit 4c22b6f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/sources/configuration/provisioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ datasources:
disableReadOnlyUsersAck: true
# Disable time series data alignment
disableDataAlignment: false
# Use value mapping from Zabbix
useZabbixValueMapping: true
version: 1
editable: false

Expand Down
5 changes: 5 additions & 0 deletions src/datasource-zabbix/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@
checked="ctrl.target.options.showDisabledItems"
on-change="ctrl.onQueryOptionChange()">
</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"
label="Disable data alignment"
checked="ctrl.target.options.disableDataAlignment"
Expand Down
4 changes: 3 additions & 1 deletion src/datasource-zabbix/query.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as c from './constants';
import * as utils from './utils';
import * as metricFunctions from './metricFunctions';
import * as migrations from './migrations';
import { ShowProblemTypes } from './types';
import { ShowProblemTypes, ZabbixMetricsQuery } from './types';
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';

Expand All @@ -29,6 +29,7 @@ function getTargetDefaults() {
showDisabledItems: false,
skipEmptyValues: false,
disableDataAlignment: false,
useZabbixValueMapping: false,
},
table: {
'skipEmptyValues': false
Expand Down Expand Up @@ -456,6 +457,7 @@ export class ZabbixQueryController extends QueryCtrl {
const metricOptionsMap = {
showDisabledItems: "Show disabled items",
disableDataAlignment: "Disable data alignment",
useZabbixValueMapping: "Use Zabbix value mapping",
};

const problemsOptionsMap = {
Expand Down
10 changes: 6 additions & 4 deletions src/datasource-zabbix/responseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import _ from 'lodash';
import TableModel from 'grafana/app/core/table_model';
import * as c from './constants';
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
Expand Down Expand Up @@ -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 timeFiled: Field = {
Expand Down Expand Up @@ -122,8 +124,8 @@ export function seriesToDataFrame(timeseries, target: DataQuery, valueMappings?:

// Try to use value mapping from Zabbix
const mappings = utils.getValueMapping(item, valueMappings);
if (mappings) {
console.log(`Datasource: value mapping detected`);
if (mappings && target.options?.useZabbixValueMapping) {
console.log(`Datasource: using Zabbix value mapping`);
valueFiled.config.mappings = mappings;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/datasource-zabbix/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export interface ZabbixMetricsQuery extends DataQuery {
triggers: { minSeverity: string; acknowledged: boolean; count: number; };
queryType: string;
datasourceId: number;
group: { filter: string; name: string; };
host: { filter: string; name: string; };
application: { filter: string; name: string; };
item: { filter: string; name: string; };
group: { filter: string; name?: string; };
host: { filter: string; name?: string; };
application: { filter: string; name?: string; };
item: { filter: string; name?: string; };
textFilter: string;
mode: number;
itemids: number[];
Expand All @@ -62,6 +62,7 @@ export interface ZabbixQueryOptions {
showDisabledItems?: boolean;
skipEmptyValues?: boolean;
disableDataAlignment?: boolean;
useZabbixValueMapping?: boolean;
// Problems options
minSeverity?: number;
sortProblems?: string;
Expand Down

0 comments on commit 4c22b6f

Please sign in to comment.