Skip to content

Commit

Permalink
Filter problems by time range, fix #1094
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Dec 23, 2020
1 parent 3f10be6 commit 9802502
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/datasource-zabbix/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
});
}

queryProblems(target, timeRange, options) {
queryProblems(target: ZabbixMetricsQuery, timeRange, options) {
const [timeFrom, timeTo] = timeRange;
const userIsEditor = contextSrv.isEditor || contextSrv.isGrafanaAdmin;

Expand Down Expand Up @@ -512,7 +512,7 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
}

let getProblemsPromise: Promise<ProblemDTO[]>;
if (showProblems === ShowProblemTypes.History) {
if (showProblems === ShowProblemTypes.History || target.options?.useTimeRange) {
problemsOptions.timeFrom = timeFrom;
problemsOptions.timeTo = timeTo;
getProblemsPromise = this.zabbix.getProblemsHistory(groupFilter, hostFilter, appFilter, proxyFilter, problemsOptions);
Expand Down
6 changes: 6 additions & 0 deletions src/datasource-zabbix/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@
</select>
</div>
</div>
<gf-form-switch class="gf-form"
label-class="width-9"
label="Use time range"
checked="ctrl.target.options.useTimeRange"
on-change="ctrl.onQueryOptionChange()">
</gf-form-switch>
<gf-form-switch class="gf-form"
label-class="width-9"
label="Hosts in maintenance"
Expand Down
7 changes: 3 additions & 4 deletions src/datasource-zabbix/query.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class ZabbixQueryController extends QueryCtrl {
queryOptionsText: string;
metric: any;
showQueryOptions: boolean;
oldTarget: any;

/** @ngInject */
constructor($scope, $injector, $rootScope, $sce, templateSrv) {
Expand Down Expand Up @@ -370,9 +371,6 @@ export class ZabbixQueryController extends QueryCtrl {
this.targetChanged();
}
}
oldTarget(oldTarget: any, target: any) {
throw new Error("Method not implemented.");
}

onVariableChange() {
if (this.isContainsVariables()) {
Expand Down Expand Up @@ -405,7 +403,7 @@ export class ZabbixQueryController extends QueryCtrl {
targetChanged() {
this.initFilters();
this.parseTarget();
this.panelCtrl.refresh();
this.refresh();
}

addFunction(funcDef) {
Expand Down Expand Up @@ -466,6 +464,7 @@ export class ZabbixQueryController extends QueryCtrl {
hostsInMaintenance: "Show hosts in maintenance",
limit: "Limit problems",
hostProxy: "Show proxy",
useTimeRange: "Use time range",
};

let optionsMap = {};
Expand Down
4 changes: 4 additions & 0 deletions src/datasource-zabbix/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface ZabbixMetricsQuery extends DataQuery {
tags?: { filter: string; };
functions: ZabbixMetricFunction[];
options: ZabbixQueryOptions;
// Problems
showProblems?: ShowProblemTypes;
// Deprecated
hostFilter?: string;
itemFilter?: string;
Expand All @@ -67,6 +69,8 @@ export interface ZabbixQueryOptions {
hostsInMaintenance?: boolean;
hostProxy?: boolean;
limit?: number;
useTimeRange?: boolean;
severities?: number[];
}

export interface ZabbixMetricFunction {
Expand Down

0 comments on commit 9802502

Please sign in to comment.