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) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { getNextRefIdChar } from './utils';
|
||||
import { ShowProblemTypes } from '../datasource-zabbix/types';
|
||||
|
||||
// Actual schema version
|
||||
export const CURRENT_SCHEMA_VERSION = 8;
|
||||
@@ -19,9 +20,7 @@ export const getDefaultTarget = (targets?) => {
|
||||
export function getDefaultTargetOptions() {
|
||||
return {
|
||||
hostsInMaintenance: true,
|
||||
showTriggers: 'all triggers',
|
||||
sortTriggersBy: { text: 'last change', value: 'lastchange' },
|
||||
showEvents: { text: 'Problems', value: 1 },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -99,14 +98,45 @@ export function migratePanelSchema(panel) {
|
||||
for (const target of panel.targets) {
|
||||
// set queryType to PROBLEMS
|
||||
target.queryType = 5;
|
||||
target.options = getDefaultTargetOptions();
|
||||
_.defaults(target, {tags: {filter: ""}});
|
||||
target.showProblems = migrateShowEvents(panel);
|
||||
target.options = migrateOptions(panel);
|
||||
_.defaults(target.options, getDefaultTargetOptions());
|
||||
_.defaults(target, { tags: { filter: "" } });
|
||||
}
|
||||
|
||||
delete panel.showEvents;
|
||||
delete panel.showTriggers;
|
||||
delete panel.hostsInMaintenance;
|
||||
}
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
function migrateOptions(panel) {
|
||||
let acknowledged = 2;
|
||||
if (panel.showTriggers === 'acknowledged') {
|
||||
acknowledged = 1;
|
||||
} else if (panel.showTriggers === 'unacknowledged') {
|
||||
acknowledged = 0;
|
||||
}
|
||||
|
||||
return {
|
||||
hostsInMaintenance: panel.hostsInMaintenance,
|
||||
sortTriggersBy: panel.sortTriggersBy,
|
||||
acknowledged: acknowledged,
|
||||
};
|
||||
}
|
||||
|
||||
function migrateShowEvents(panel) {
|
||||
if (panel.showEvents?.value === 1) {
|
||||
return ShowProblemTypes.Problems;
|
||||
} else if (panel.showEvents?.value === 0 || panel.showEvents?.value?.length > 1) {
|
||||
return ShowProblemTypes.History;
|
||||
} else {
|
||||
return ShowProblemTypes.Problems;
|
||||
}
|
||||
}
|
||||
|
||||
function getSchemaVersion(panel) {
|
||||
return panel.schemaVersion || 1;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@ describe('Triggers Panel schema migration', () => {
|
||||
ageField: true,
|
||||
infoField: true,
|
||||
limit: 10,
|
||||
showTriggers: 'all triggers',
|
||||
showTriggers: 'unacknowledged',
|
||||
hideHostsInMaintenance: false,
|
||||
hostsInMaintenance: false,
|
||||
sortTriggersBy: { text: 'last change', value: 'lastchange' },
|
||||
showEvents: { text: 'Problems', value: '1' },
|
||||
triggerSeverity: DEFAULT_SEVERITY,
|
||||
@@ -61,12 +62,12 @@ describe('Triggers Panel schema migration', () => {
|
||||
{
|
||||
...DEFAULT_TARGET,
|
||||
queryType: 5,
|
||||
showProblems: 'problems',
|
||||
options: {
|
||||
hostsInMaintenance: true,
|
||||
showTriggers: 'all triggers',
|
||||
hostsInMaintenance: false,
|
||||
acknowledged: 0,
|
||||
sortTriggersBy: { text: 'last change', value: 'lastchange' },
|
||||
showEvents: { text: 'Problems', value: 1 },
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
ageField: true,
|
||||
|
||||
@@ -20,6 +20,7 @@ export const DEFAULT_TARGET = {
|
||||
trigger: {filter: ""},
|
||||
tags: {filter: ""},
|
||||
proxy: {filter: ""},
|
||||
showProblems: 'problems',
|
||||
};
|
||||
|
||||
export const DEFAULT_SEVERITY = [
|
||||
@@ -41,7 +42,6 @@ export const PANEL_DEFAULTS = {
|
||||
hostField: true,
|
||||
hostTechNameField: false,
|
||||
hostGroups: false,
|
||||
hostProxy: false,
|
||||
showTags: true,
|
||||
statusField: true,
|
||||
statusIcon: false,
|
||||
@@ -50,11 +50,8 @@ export const PANEL_DEFAULTS = {
|
||||
descriptionField: true,
|
||||
descriptionAtNewLine: false,
|
||||
// Options
|
||||
hostsInMaintenance: true,
|
||||
showTriggers: 'all triggers',
|
||||
sortTriggersBy: { text: 'last change', value: 'lastchange' },
|
||||
showEvents: { text: 'Problems', value: 1 },
|
||||
limit: 100,
|
||||
limit: null,
|
||||
// View options
|
||||
layout: 'table',
|
||||
fontSize: '100%',
|
||||
@@ -175,7 +172,9 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
||||
triggers = this.sortTriggers(triggers);
|
||||
|
||||
// Limit triggers number
|
||||
triggers = triggers.slice(0, this.panel.limit || PANEL_DEFAULTS.limit);
|
||||
if (this.panel.limit) {
|
||||
triggers = triggers.slice(0, this.panel.limit);
|
||||
}
|
||||
|
||||
this.renderData = triggers;
|
||||
|
||||
@@ -198,11 +197,6 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by maintenance status
|
||||
if (!this.panel.hostsInMaintenance) {
|
||||
triggerList = _.filter(triggerList, (trigger) => trigger.maintenance === false);
|
||||
}
|
||||
|
||||
// Filter triggers by severity
|
||||
triggerList = _.filter(triggerList, trigger => {
|
||||
if (trigger.lastEvent && trigger.lastEvent.severity) {
|
||||
|
||||
Reference in New Issue
Block a user