Problems panel: add target migrations
This commit is contained in:
@@ -3,7 +3,16 @@ import { getNextRefIdChar } from './utils';
|
||||
import { getDefaultTarget } from './triggers_panel_ctrl';
|
||||
|
||||
// Actual schema version
|
||||
export const CURRENT_SCHEMA_VERSION = 7;
|
||||
export const CURRENT_SCHEMA_VERSION = 8;
|
||||
|
||||
export function getDefaultTargetOptions() {
|
||||
return {
|
||||
hostsInMaintenance: true,
|
||||
showTriggers: 'all triggers',
|
||||
sortTriggersBy: { text: 'last change', value: 'lastchange' },
|
||||
showEvents: { text: 'Problems', value: 1 },
|
||||
};
|
||||
}
|
||||
|
||||
export function migratePanelSchema(panel) {
|
||||
if (isEmptyPanel(panel)) {
|
||||
@@ -12,7 +21,7 @@ export function migratePanelSchema(panel) {
|
||||
}
|
||||
|
||||
const schemaVersion = getSchemaVersion(panel);
|
||||
panel.schemaVersion = CURRENT_SCHEMA_VERSION;
|
||||
// panel.schemaVersion = CURRENT_SCHEMA_VERSION;
|
||||
|
||||
if (schemaVersion < 2) {
|
||||
panel.datasources = [panel.datasource];
|
||||
@@ -66,6 +75,23 @@ export function migratePanelSchema(panel) {
|
||||
delete panel.datasources;
|
||||
}
|
||||
|
||||
if (schemaVersion < 8) {
|
||||
if (panel.targets.length === 1) {
|
||||
if (panel.targets[0].datasource) {
|
||||
panel.datasource = panel.targets[0].datasource;
|
||||
delete panel.targets[0].datasource;
|
||||
}
|
||||
} else if (panel.targets.length > 1) {
|
||||
// Mixed data sources
|
||||
panel.datasource = '-- Mixed --';
|
||||
}
|
||||
for (const target of panel.targets) {
|
||||
// set queryType to PROBLEMS
|
||||
target.queryType = 5;
|
||||
target.options = getDefaultTargetOptions();
|
||||
}
|
||||
}
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@ import { triggerPanelOptionsTab } from './options_tab';
|
||||
import { migratePanelSchema, CURRENT_SCHEMA_VERSION } from './migrations';
|
||||
import ProblemList from './components/Problems/Problems';
|
||||
import AlertList from './components/AlertList/AlertList';
|
||||
import { getNextRefIdChar } from './utils';
|
||||
|
||||
const ZABBIX_DS_ID = 'alexanderzobnin-zabbix-datasource';
|
||||
const PROBLEM_EVENTS_LIMIT = 100;
|
||||
|
||||
export const DEFAULT_TARGET = {
|
||||
@@ -24,18 +22,6 @@ export const DEFAULT_TARGET = {
|
||||
proxy: {filter: ""},
|
||||
};
|
||||
|
||||
export const getDefaultTarget = (targets) => {
|
||||
return {
|
||||
group: {filter: ""},
|
||||
host: {filter: ""},
|
||||
application: {filter: ""},
|
||||
trigger: {filter: ""},
|
||||
tags: {filter: ""},
|
||||
proxy: {filter: ""},
|
||||
refId: getNextRefIdChar(targets),
|
||||
};
|
||||
};
|
||||
|
||||
export const DEFAULT_SEVERITY = [
|
||||
{ priority: 0, severity: 'Not classified', color: 'rgb(108, 108, 108)', show: true},
|
||||
{ priority: 1, severity: 'Information', color: 'rgb(120, 158, 183)', show: true},
|
||||
@@ -51,7 +37,6 @@ const DEFAULT_TIME_FORMAT = "DD MMM YYYY HH:mm:ss";
|
||||
|
||||
export const PANEL_DEFAULTS = {
|
||||
schemaVersion: CURRENT_SCHEMA_VERSION,
|
||||
// targets: [getDefaultTarget([])],
|
||||
// Fields
|
||||
hostField: true,
|
||||
hostTechNameField: false,
|
||||
@@ -115,7 +100,7 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
||||
this.range = {};
|
||||
this.renderData = [];
|
||||
|
||||
// this.panel = migratePanelSchema(this.panel);
|
||||
this.panel = migratePanelSchema(this.panel);
|
||||
_.defaultsDeep(this.panel, _.cloneDeep(PANEL_DEFAULTS));
|
||||
|
||||
this.events.on(PanelEvents.render, this.onRender.bind(this));
|
||||
@@ -125,6 +110,8 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
||||
}
|
||||
|
||||
onInitEditMode() {
|
||||
// Update schema version to prevent migration on up-to-date targets
|
||||
this.panel.schemaVersion = CURRENT_SCHEMA_VERSION;
|
||||
this.addEditorTab('Options', triggerPanelOptionsTab);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user