Problems: more work on options migration
This commit is contained in:
@@ -11,7 +11,7 @@ import responseHandler from './responseHandler';
|
||||
import problemsHandler from './problemsHandler';
|
||||
import { Zabbix } from './zabbix/zabbix';
|
||||
import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore';
|
||||
import { VariableQueryTypes } from './types';
|
||||
import { VariableQueryTypes, ShowProblemTypes } from './types';
|
||||
|
||||
const DEFAULT_ZABBIX_VERSION = 3;
|
||||
|
||||
@@ -396,9 +396,7 @@ export class ZabbixDatasource {
|
||||
let proxies;
|
||||
let showAckButton = true;
|
||||
|
||||
// const showEvents = this.panel.showEvents.value;
|
||||
const showEvents = target.options.showEvents?.value || 1;
|
||||
// const showProxy = this.panel.hostProxy;
|
||||
const showProblems = target.showProblems || ShowProblemTypes.Problems;
|
||||
const showProxy = target.options.hostProxy;
|
||||
|
||||
const getProxiesPromise = showProxy ? this.zabbix.getProxies() : () => [];
|
||||
@@ -420,10 +418,10 @@ export class ZabbixDatasource {
|
||||
};
|
||||
|
||||
const triggersOptions: any = {
|
||||
showTriggers: showEvents
|
||||
showTriggers: showProblems
|
||||
};
|
||||
|
||||
if (showEvents !== 1) {
|
||||
if (showProblems !== ShowProblemTypes.Problems) {
|
||||
triggersOptions.timeFrom = timeFrom;
|
||||
triggersOptions.timeTo = timeTo;
|
||||
}
|
||||
|
||||
@@ -169,12 +169,12 @@
|
||||
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.queryType == editorMode.TRIGGERS || ctrl.target.queryType == editorMode.PROBLEMS">
|
||||
<div class="gf-form max-width-20" ng-show="ctrl.target.queryType == editorMode.PROBLEMS">
|
||||
<label class="gf-form-label query-keyword width-7">Show events</label>
|
||||
<label class="gf-form-label query-keyword width-7">Show</label>
|
||||
<div class="gf-form-select-wrapper max-width-20">
|
||||
<select class="gf-form-input"
|
||||
ng-model="ctrl.target.options.showEvents"
|
||||
ng-options="f.text for f in ctrl.showEventsFields track by f.value"
|
||||
ng-change="ctrl.onQueryOptionChange()">
|
||||
ng-model="ctrl.target.showProblems"
|
||||
ng-options="v.value as v.text for v in ctrl.showProblemsOptions"
|
||||
ng-change="ctrl.onTargetBlur()">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -279,23 +279,21 @@
|
||||
</div>
|
||||
|
||||
<div class="gf-form-group" ng-show="ctrl.target.queryType == editorMode.PROBLEMS || ctrl.target.queryType == editorMode.TRIGGERS">
|
||||
<div ng-show="ctrl.target.queryType == editorMode.TRIGGERS">
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label width-7">Acknowledged</label>
|
||||
<div class="gf-form-select-wrapper width-14">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.triggers.acknowledged"
|
||||
ng-options="a.value as a.text for a in ctrl.ackFilters">
|
||||
</select>
|
||||
</div>
|
||||
<gf-form-switch class="gf-form" ng-show="ctrl.target.queryType == editorMode.TRIGGERS"
|
||||
label-class="width-9"
|
||||
label="Count"
|
||||
checked="ctrl.target.triggers.count"
|
||||
on-change="ctrl.onTargetBlur()">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form" ng-show="ctrl.target.queryType == editorMode.PROBLEMS || ctrl.target.queryType == editorMode.TRIGGERS">
|
||||
<label class="gf-form-label width-9">Acknowledged</label>
|
||||
<div class="gf-form-select-wrapper width-12">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.options.acknowledged"
|
||||
ng-options="a.value as a.text for a in ctrl.ackFilters">
|
||||
</select>
|
||||
</div>
|
||||
<gf-form-switch class="gf-form"
|
||||
label-class="width-9"
|
||||
label="Count"
|
||||
checked="ctrl.target.triggers.count"
|
||||
on-change="ctrl.onTargetBlur()">
|
||||
</gf-form-switch>
|
||||
</div>
|
||||
|
||||
<div ng-show="ctrl.target.queryType == editorMode.PROBLEMS">
|
||||
|
||||
@@ -91,6 +91,11 @@ export function filterTriggersPre(triggerList, replacedTarget) {
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by maintenance status
|
||||
if (!replacedTarget.options.hostsInMaintenance) {
|
||||
triggerList = _.filter(triggerList, (trigger) => !trigger.maintenance);
|
||||
}
|
||||
|
||||
return triggerList;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +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';
|
||||
|
||||
function getTargetDefaults() {
|
||||
return {
|
||||
@@ -28,7 +29,6 @@ function getTargetDefaults() {
|
||||
hostsInMaintenance: false,
|
||||
hostProxy: false,
|
||||
sortTriggersBy: { text: 'last change', value: 'lastchange' },
|
||||
showEvents: { text: 'Problems', value: 1 },
|
||||
},
|
||||
table: {
|
||||
'skipEmptyValues': false
|
||||
@@ -36,6 +36,21 @@ function getTargetDefaults() {
|
||||
};
|
||||
}
|
||||
|
||||
function getSLATargetDefaults() {
|
||||
return {
|
||||
slaProperty: { name: "SLA", property: "sla" },
|
||||
};
|
||||
}
|
||||
|
||||
function getProblemsTargetDefaults() {
|
||||
return {
|
||||
showProblems: ShowProblemTypes.Problems,
|
||||
options: {
|
||||
acknowledged: 2,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export class ZabbixQueryController extends QueryCtrl {
|
||||
|
||||
/** @ngInject */
|
||||
@@ -96,6 +111,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
{ text: 'Problems', value: 1 }
|
||||
];
|
||||
|
||||
this.showProblemsOptions = [
|
||||
{ text: 'Problems', value: 'problems' },
|
||||
{ text: 'Recent problems', value: 'recent' },
|
||||
{ text: 'History', value: 'history' },
|
||||
];
|
||||
|
||||
this.resultFormats = [{ text: 'Time series', value: 'time_series' }, { text: 'Table', value: 'table' }];
|
||||
|
||||
this.triggerSeverity = c.TRIGGER_SEVERITY;
|
||||
@@ -143,14 +164,20 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
return metricFunctions.createFuncInstance(func.def, func.params);
|
||||
});
|
||||
|
||||
if (target.queryType === c.MODE_ITSERVICE) {
|
||||
_.defaultsDeep(target, getSLATargetDefaults());
|
||||
}
|
||||
|
||||
if (target.queryType === c.MODE_PROBLEMS) {
|
||||
_.defaultsDeep(target, getProblemsTargetDefaults());
|
||||
}
|
||||
|
||||
if (target.queryType === c.MODE_METRICS ||
|
||||
target.queryType === c.MODE_TEXT ||
|
||||
target.queryType === c.MODE_TRIGGERS ||
|
||||
target.queryType === c.MODE_PROBLEMS) {
|
||||
this.initFilters();
|
||||
}
|
||||
else if (target.queryType === c.MODE_ITSERVICE) {
|
||||
_.defaults(target, {slaProperty: {name: "SLA", property: "sla"}});
|
||||
} else if (target.queryType === c.MODE_ITSERVICE) {
|
||||
this.suggestITServices();
|
||||
}
|
||||
};
|
||||
@@ -354,15 +381,28 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
}
|
||||
|
||||
renderQueryOptionsText() {
|
||||
var optionsMap = {
|
||||
const metricOptionsMap = {
|
||||
showDisabledItems: "Show disabled items",
|
||||
};
|
||||
|
||||
const problemsOptionsMap = {
|
||||
sortTriggersBy: "Sort problems",
|
||||
acknowledged: "Acknowledged",
|
||||
skipEmptyValues: "Skip empty values",
|
||||
hostsInMaintenance: "Show hosts in maintenance",
|
||||
sortTriggersBy: "Sort problems",
|
||||
limit: "Limit problems",
|
||||
hostProxy: "Show proxy",
|
||||
};
|
||||
var options = [];
|
||||
|
||||
let optionsMap = {};
|
||||
|
||||
if (this.target.queryType === c.MODE_METRICS) {
|
||||
optionsMap = metricOptionsMap;
|
||||
} else if (this.target.queryType === c.MODE_PROBLEMS || this.target.queryType === c.MODE_TRIGGERS) {
|
||||
optionsMap = problemsOptionsMap;
|
||||
}
|
||||
|
||||
const options = [];
|
||||
_.forOwn(this.target.options, (value, key) => {
|
||||
if (value && optionsMap[key]) {
|
||||
if (value === true) {
|
||||
@@ -392,6 +432,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
*/
|
||||
switchEditorMode(mode) {
|
||||
this.target.queryType = mode;
|
||||
this.queryOptionsText = this.renderQueryOptionsText();
|
||||
this.init();
|
||||
this.targetChanged();
|
||||
}
|
||||
|
||||
@@ -28,3 +28,9 @@ export enum VariableQueryTypes {
|
||||
Application = 'application',
|
||||
Item = 'item',
|
||||
}
|
||||
|
||||
export enum ShowProblemTypes {
|
||||
Problems = 'problems',
|
||||
Recent = 'recent',
|
||||
History = 'history',
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import kbn from 'grafana/app/core/utils/kbn';
|
||||
import * as utils from '../../../utils';
|
||||
import { ZabbixAPICore } from './zabbixAPICore';
|
||||
import { ZBX_ACK_ACTION_NONE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_ADD_MESSAGE, MIN_SLA_INTERVAL } from '../../../constants';
|
||||
import { ShowProblemTypes } from '../../../types';
|
||||
|
||||
/**
|
||||
* Zabbix API Wrapper.
|
||||
@@ -350,8 +351,10 @@ export class ZabbixAPIConnector {
|
||||
selectTags: 'extend'
|
||||
};
|
||||
|
||||
if (showTriggers) {
|
||||
params.filter.value = showTriggers;
|
||||
if (showTriggers === ShowProblemTypes.Problems) {
|
||||
params.filter.value = 1;
|
||||
} else if (showTriggers === ShowProblemTypes.Recent || showTriggers === ShowProblemTypes.History) {
|
||||
params.filter.value = [0, 1];
|
||||
}
|
||||
|
||||
if (maintenance) {
|
||||
|
||||
Reference in New Issue
Block a user