Problems: more work on options migration

This commit is contained in:
Alexander Zobnin
2020-05-13 18:13:25 +03:00
parent bfbd2907ce
commit 2588fd5c50
9 changed files with 131 additions and 55 deletions

View File

@@ -11,7 +11,7 @@ import responseHandler from './responseHandler';
import problemsHandler from './problemsHandler'; import problemsHandler from './problemsHandler';
import { Zabbix } from './zabbix/zabbix'; import { Zabbix } from './zabbix/zabbix';
import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore'; import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore';
import { VariableQueryTypes } from './types'; import { VariableQueryTypes, ShowProblemTypes } from './types';
const DEFAULT_ZABBIX_VERSION = 3; const DEFAULT_ZABBIX_VERSION = 3;
@@ -396,9 +396,7 @@ export class ZabbixDatasource {
let proxies; let proxies;
let showAckButton = true; let showAckButton = true;
// const showEvents = this.panel.showEvents.value; const showProblems = target.showProblems || ShowProblemTypes.Problems;
const showEvents = target.options.showEvents?.value || 1;
// const showProxy = this.panel.hostProxy;
const showProxy = target.options.hostProxy; const showProxy = target.options.hostProxy;
const getProxiesPromise = showProxy ? this.zabbix.getProxies() : () => []; const getProxiesPromise = showProxy ? this.zabbix.getProxies() : () => [];
@@ -420,10 +418,10 @@ export class ZabbixDatasource {
}; };
const triggersOptions: any = { const triggersOptions: any = {
showTriggers: showEvents showTriggers: showProblems
}; };
if (showEvents !== 1) { if (showProblems !== ShowProblemTypes.Problems) {
triggersOptions.timeFrom = timeFrom; triggersOptions.timeFrom = timeFrom;
triggersOptions.timeTo = timeTo; triggersOptions.timeTo = timeTo;
} }

View File

@@ -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-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"> <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"> <div class="gf-form-select-wrapper max-width-20">
<select class="gf-form-input" <select class="gf-form-input"
ng-model="ctrl.target.options.showEvents" ng-model="ctrl.target.showProblems"
ng-options="f.text for f in ctrl.showEventsFields track by f.value" ng-options="v.value as v.text for v in ctrl.showProblemsOptions"
ng-change="ctrl.onQueryOptionChange()"> ng-change="ctrl.onTargetBlur()">
</select> </select>
</div> </div>
</div> </div>
@@ -279,23 +279,21 @@
</div> </div>
<div class="gf-form-group" ng-show="ctrl.target.queryType == editorMode.PROBLEMS || ctrl.target.queryType == editorMode.TRIGGERS"> <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"> <gf-form-switch class="gf-form" ng-show="ctrl.target.queryType == editorMode.TRIGGERS"
<div class="gf-form max-width-20"> label-class="width-9"
<label class="gf-form-label width-7">Acknowledged</label> label="Count"
<div class="gf-form-select-wrapper width-14"> checked="ctrl.target.triggers.count"
<select class="gf-form-input" on-change="ctrl.onTargetBlur()">
ng-change="ctrl.onTargetBlur()" </gf-form-switch>
ng-model="ctrl.target.triggers.acknowledged" <div class="gf-form" ng-show="ctrl.target.queryType == editorMode.PROBLEMS || ctrl.target.queryType == editorMode.TRIGGERS">
ng-options="a.value as a.text for a in ctrl.ackFilters"> <label class="gf-form-label width-9">Acknowledged</label>
</select> <div class="gf-form-select-wrapper width-12">
</div> <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> </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>
<div ng-show="ctrl.target.queryType == editorMode.PROBLEMS"> <div ng-show="ctrl.target.queryType == editorMode.PROBLEMS">

View File

@@ -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; return triggerList;
} }

View File

@@ -4,6 +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';
function getTargetDefaults() { function getTargetDefaults() {
return { return {
@@ -28,7 +29,6 @@ function getTargetDefaults() {
hostsInMaintenance: false, hostsInMaintenance: false,
hostProxy: false, hostProxy: false,
sortTriggersBy: { text: 'last change', value: 'lastchange' }, sortTriggersBy: { text: 'last change', value: 'lastchange' },
showEvents: { text: 'Problems', value: 1 },
}, },
table: { table: {
'skipEmptyValues': false '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 { export class ZabbixQueryController extends QueryCtrl {
/** @ngInject */ /** @ngInject */
@@ -96,6 +111,12 @@ export class ZabbixQueryController extends QueryCtrl {
{ text: 'Problems', value: 1 } { 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.resultFormats = [{ text: 'Time series', value: 'time_series' }, { text: 'Table', value: 'table' }];
this.triggerSeverity = c.TRIGGER_SEVERITY; this.triggerSeverity = c.TRIGGER_SEVERITY;
@@ -143,14 +164,20 @@ export class ZabbixQueryController extends QueryCtrl {
return metricFunctions.createFuncInstance(func.def, func.params); 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 || if (target.queryType === c.MODE_METRICS ||
target.queryType === c.MODE_TEXT || target.queryType === c.MODE_TEXT ||
target.queryType === c.MODE_TRIGGERS || target.queryType === c.MODE_TRIGGERS ||
target.queryType === c.MODE_PROBLEMS) { target.queryType === c.MODE_PROBLEMS) {
this.initFilters(); this.initFilters();
} } else if (target.queryType === c.MODE_ITSERVICE) {
else if (target.queryType === c.MODE_ITSERVICE) {
_.defaults(target, {slaProperty: {name: "SLA", property: "sla"}});
this.suggestITServices(); this.suggestITServices();
} }
}; };
@@ -354,15 +381,28 @@ export class ZabbixQueryController extends QueryCtrl {
} }
renderQueryOptionsText() { renderQueryOptionsText() {
var optionsMap = { const metricOptionsMap = {
showDisabledItems: "Show disabled items", showDisabledItems: "Show disabled items",
};
const problemsOptionsMap = {
sortTriggersBy: "Sort problems",
acknowledged: "Acknowledged",
skipEmptyValues: "Skip empty values", skipEmptyValues: "Skip empty values",
hostsInMaintenance: "Show hosts in maintenance", hostsInMaintenance: "Show hosts in maintenance",
sortTriggersBy: "Sort problems",
limit: "Limit problems", limit: "Limit problems",
hostProxy: "Show proxy", 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) => { _.forOwn(this.target.options, (value, key) => {
if (value && optionsMap[key]) { if (value && optionsMap[key]) {
if (value === true) { if (value === true) {
@@ -392,6 +432,7 @@ export class ZabbixQueryController extends QueryCtrl {
*/ */
switchEditorMode(mode) { switchEditorMode(mode) {
this.target.queryType = mode; this.target.queryType = mode;
this.queryOptionsText = this.renderQueryOptionsText();
this.init(); this.init();
this.targetChanged(); this.targetChanged();
} }

View File

@@ -28,3 +28,9 @@ export enum VariableQueryTypes {
Application = 'application', Application = 'application',
Item = 'item', Item = 'item',
} }
export enum ShowProblemTypes {
Problems = 'problems',
Recent = 'recent',
History = 'history',
}

View File

@@ -3,6 +3,7 @@ import kbn from 'grafana/app/core/utils/kbn';
import * as utils from '../../../utils'; import * as utils from '../../../utils';
import { ZabbixAPICore } from './zabbixAPICore'; import { ZabbixAPICore } from './zabbixAPICore';
import { ZBX_ACK_ACTION_NONE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_ADD_MESSAGE, MIN_SLA_INTERVAL } from '../../../constants'; 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. * Zabbix API Wrapper.
@@ -350,8 +351,10 @@ export class ZabbixAPIConnector {
selectTags: 'extend' selectTags: 'extend'
}; };
if (showTriggers) { if (showTriggers === ShowProblemTypes.Problems) {
params.filter.value = showTriggers; params.filter.value = 1;
} else if (showTriggers === ShowProblemTypes.Recent || showTriggers === ShowProblemTypes.History) {
params.filter.value = [0, 1];
} }
if (maintenance) { if (maintenance) {

View File

@@ -1,5 +1,6 @@
import _ from 'lodash'; import _ from 'lodash';
import { getNextRefIdChar } from './utils'; import { getNextRefIdChar } from './utils';
import { ShowProblemTypes } from '../datasource-zabbix/types';
// Actual schema version // Actual schema version
export const CURRENT_SCHEMA_VERSION = 8; export const CURRENT_SCHEMA_VERSION = 8;
@@ -19,9 +20,7 @@ export const getDefaultTarget = (targets?) => {
export function getDefaultTargetOptions() { export function getDefaultTargetOptions() {
return { return {
hostsInMaintenance: true, hostsInMaintenance: true,
showTriggers: 'all triggers',
sortTriggersBy: { text: 'last change', value: 'lastchange' }, 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) { for (const target of panel.targets) {
// set queryType to PROBLEMS // set queryType to PROBLEMS
target.queryType = 5; target.queryType = 5;
target.options = getDefaultTargetOptions(); target.showProblems = migrateShowEvents(panel);
_.defaults(target, {tags: {filter: ""}}); target.options = migrateOptions(panel);
_.defaults(target.options, getDefaultTargetOptions());
_.defaults(target, { tags: { filter: "" } });
} }
delete panel.showEvents;
delete panel.showTriggers;
delete panel.hostsInMaintenance;
} }
return panel; 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) { function getSchemaVersion(panel) {
return panel.schemaVersion || 1; return panel.schemaVersion || 1;
} }

View File

@@ -34,8 +34,9 @@ describe('Triggers Panel schema migration', () => {
ageField: true, ageField: true,
infoField: true, infoField: true,
limit: 10, limit: 10,
showTriggers: 'all triggers', showTriggers: 'unacknowledged',
hideHostsInMaintenance: false, hideHostsInMaintenance: false,
hostsInMaintenance: false,
sortTriggersBy: { text: 'last change', value: 'lastchange' }, sortTriggersBy: { text: 'last change', value: 'lastchange' },
showEvents: { text: 'Problems', value: '1' }, showEvents: { text: 'Problems', value: '1' },
triggerSeverity: DEFAULT_SEVERITY, triggerSeverity: DEFAULT_SEVERITY,
@@ -61,12 +62,12 @@ describe('Triggers Panel schema migration', () => {
{ {
...DEFAULT_TARGET, ...DEFAULT_TARGET,
queryType: 5, queryType: 5,
showProblems: 'problems',
options: { options: {
hostsInMaintenance: true, hostsInMaintenance: false,
showTriggers: 'all triggers', acknowledged: 0,
sortTriggersBy: { text: 'last change', value: 'lastchange' }, sortTriggersBy: { text: 'last change', value: 'lastchange' },
showEvents: { text: 'Problems', value: 1 }, },
}
} }
], ],
ageField: true, ageField: true,

View File

@@ -20,6 +20,7 @@ export const DEFAULT_TARGET = {
trigger: {filter: ""}, trigger: {filter: ""},
tags: {filter: ""}, tags: {filter: ""},
proxy: {filter: ""}, proxy: {filter: ""},
showProblems: 'problems',
}; };
export const DEFAULT_SEVERITY = [ export const DEFAULT_SEVERITY = [
@@ -41,7 +42,6 @@ export const PANEL_DEFAULTS = {
hostField: true, hostField: true,
hostTechNameField: false, hostTechNameField: false,
hostGroups: false, hostGroups: false,
hostProxy: false,
showTags: true, showTags: true,
statusField: true, statusField: true,
statusIcon: false, statusIcon: false,
@@ -50,11 +50,8 @@ export const PANEL_DEFAULTS = {
descriptionField: true, descriptionField: true,
descriptionAtNewLine: false, descriptionAtNewLine: false,
// Options // Options
hostsInMaintenance: true,
showTriggers: 'all triggers',
sortTriggersBy: { text: 'last change', value: 'lastchange' }, sortTriggersBy: { text: 'last change', value: 'lastchange' },
showEvents: { text: 'Problems', value: 1 }, limit: null,
limit: 100,
// View options // View options
layout: 'table', layout: 'table',
fontSize: '100%', fontSize: '100%',
@@ -175,7 +172,9 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
triggers = this.sortTriggers(triggers); triggers = this.sortTriggers(triggers);
// Limit triggers number // 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; 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 // Filter triggers by severity
triggerList = _.filter(triggerList, trigger => { triggerList = _.filter(triggerList, trigger => {
if (trigger.lastEvent && trigger.lastEvent.severity) { if (trigger.lastEvent && trigger.lastEvent.severity) {