diff --git a/src/datasource-zabbix/datasource.ts b/src/datasource-zabbix/datasource.ts index a0a3a80..c163fb0 100644 --- a/src/datasource-zabbix/datasource.ts +++ b/src/datasource-zabbix/datasource.ts @@ -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; } diff --git a/src/datasource-zabbix/partials/query.editor.html b/src/datasource-zabbix/partials/query.editor.html index a8b0e64..bc39f10 100644 --- a/src/datasource-zabbix/partials/query.editor.html +++ b/src/datasource-zabbix/partials/query.editor.html @@ -169,12 +169,12 @@
- +
@@ -279,23 +279,21 @@
-
-
- -
- -
+ + +
+ +
+
- -
diff --git a/src/datasource-zabbix/problemsHandler.ts b/src/datasource-zabbix/problemsHandler.ts index 2793793..6ed4c72 100644 --- a/src/datasource-zabbix/problemsHandler.ts +++ b/src/datasource-zabbix/problemsHandler.ts @@ -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; } diff --git a/src/datasource-zabbix/query.controller.js b/src/datasource-zabbix/query.controller.js index e085109..0891feb 100644 --- a/src/datasource-zabbix/query.controller.js +++ b/src/datasource-zabbix/query.controller.js @@ -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(); } diff --git a/src/datasource-zabbix/types.ts b/src/datasource-zabbix/types.ts index 739e25f..ba2d45f 100644 --- a/src/datasource-zabbix/types.ts +++ b/src/datasource-zabbix/types.ts @@ -28,3 +28,9 @@ export enum VariableQueryTypes { Application = 'application', Item = 'item', } + +export enum ShowProblemTypes { + Problems = 'problems', + Recent = 'recent', + History = 'history', +} diff --git a/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js b/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js index 792a477..3264a95 100644 --- a/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js +++ b/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js @@ -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) { diff --git a/src/panel-triggers/migrations.ts b/src/panel-triggers/migrations.ts index 834b2a6..e737180 100644 --- a/src/panel-triggers/migrations.ts +++ b/src/panel-triggers/migrations.ts @@ -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; } diff --git a/src/panel-triggers/specs/migrations.spec.ts b/src/panel-triggers/specs/migrations.spec.ts index 5026028..e0d52ae 100644 --- a/src/panel-triggers/specs/migrations.spec.ts +++ b/src/panel-triggers/specs/migrations.spec.ts @@ -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, diff --git a/src/panel-triggers/triggers_panel_ctrl.ts b/src/panel-triggers/triggers_panel_ctrl.ts index 43ef754..6c8b65f 100644 --- a/src/panel-triggers/triggers_panel_ctrl.ts +++ b/src/panel-triggers/triggers_panel_ctrl.ts @@ -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) {