Problems panel: add target migrations
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
// Plugin IDs
|
||||||
|
export const ZABBIX_PROBLEMS_PANEL_ID = 'alexanderzobnin-zabbix-triggers-panel';
|
||||||
|
export const ZABBIX_DS_ID = 'alexanderzobnin-zabbix-datasource';
|
||||||
|
|
||||||
// Data point
|
// Data point
|
||||||
export const DATAPOINT_VALUE = 0;
|
export const DATAPOINT_VALUE = 0;
|
||||||
export const DATAPOINT_TS = 1;
|
export const DATAPOINT_TS = 1;
|
||||||
|
|||||||
@@ -5,6 +5,37 @@ 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';
|
||||||
|
|
||||||
|
function getTargetDefaults() {
|
||||||
|
return {
|
||||||
|
queryType: c.MODE_METRICS,
|
||||||
|
group: { 'filter': "" },
|
||||||
|
host: { 'filter': "" },
|
||||||
|
application: { 'filter': "" },
|
||||||
|
item: { 'filter': "" },
|
||||||
|
functions: [],
|
||||||
|
triggers: {
|
||||||
|
'count': true,
|
||||||
|
'minSeverity': 3,
|
||||||
|
'acknowledged': 2
|
||||||
|
},
|
||||||
|
trigger: {filter: ""},
|
||||||
|
tags: {filter: ""},
|
||||||
|
proxy: {filter: ""},
|
||||||
|
options: {
|
||||||
|
showDisabledItems: false,
|
||||||
|
skipEmptyValues: false,
|
||||||
|
// Problems
|
||||||
|
hostsInMaintenance: false,
|
||||||
|
showTriggers: null,
|
||||||
|
sortTriggersBy: null,
|
||||||
|
showEvents: null,
|
||||||
|
},
|
||||||
|
table: {
|
||||||
|
'skipEmptyValues': false
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export class ZabbixQueryController extends QueryCtrl {
|
export class ZabbixQueryController extends QueryCtrl {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
@@ -86,6 +117,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
|
console.log(this);
|
||||||
var target = this.target;
|
var target = this.target;
|
||||||
|
|
||||||
// Migrate old targets
|
// Migrate old targets
|
||||||
@@ -99,27 +131,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
_.defaults(this, scopeDefaults);
|
_.defaults(this, scopeDefaults);
|
||||||
|
|
||||||
// Load default values
|
// Load default values
|
||||||
var targetDefaults = {
|
const targetDefaults = getTargetDefaults();
|
||||||
'queryType': c.MODE_METRICS,
|
_.defaultsDeep(target, targetDefaults);
|
||||||
'group': { 'filter': "" },
|
|
||||||
'host': { 'filter': "" },
|
if (this.panel.type === c.ZABBIX_PROBLEMS_PANEL_ID) {
|
||||||
'application': { 'filter': "" },
|
target.queryType = c.MODE_PROBLEMS;
|
||||||
'item': { 'filter': "" },
|
}
|
||||||
'functions': [],
|
|
||||||
'triggers': {
|
|
||||||
'count': true,
|
|
||||||
'minSeverity': 3,
|
|
||||||
'acknowledged': 2
|
|
||||||
},
|
|
||||||
'options': {
|
|
||||||
'showDisabledItems': false,
|
|
||||||
'skipEmptyValues': false
|
|
||||||
},
|
|
||||||
'table': {
|
|
||||||
'skipEmptyValues': false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_.defaults(target, targetDefaults);
|
|
||||||
|
|
||||||
// Create function instances from saved JSON
|
// Create function instances from saved JSON
|
||||||
target.functions = _.map(target.functions, function(func) {
|
target.functions = _.map(target.functions, function(func) {
|
||||||
|
|||||||
@@ -3,7 +3,16 @@ import { getNextRefIdChar } from './utils';
|
|||||||
import { getDefaultTarget } from './triggers_panel_ctrl';
|
import { getDefaultTarget } from './triggers_panel_ctrl';
|
||||||
|
|
||||||
// Actual schema version
|
// 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) {
|
export function migratePanelSchema(panel) {
|
||||||
if (isEmptyPanel(panel)) {
|
if (isEmptyPanel(panel)) {
|
||||||
@@ -12,7 +21,7 @@ export function migratePanelSchema(panel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const schemaVersion = getSchemaVersion(panel);
|
const schemaVersion = getSchemaVersion(panel);
|
||||||
panel.schemaVersion = CURRENT_SCHEMA_VERSION;
|
// panel.schemaVersion = CURRENT_SCHEMA_VERSION;
|
||||||
|
|
||||||
if (schemaVersion < 2) {
|
if (schemaVersion < 2) {
|
||||||
panel.datasources = [panel.datasource];
|
panel.datasources = [panel.datasource];
|
||||||
@@ -66,6 +75,23 @@ export function migratePanelSchema(panel) {
|
|||||||
delete panel.datasources;
|
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;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import { triggerPanelOptionsTab } from './options_tab';
|
|||||||
import { migratePanelSchema, CURRENT_SCHEMA_VERSION } from './migrations';
|
import { migratePanelSchema, CURRENT_SCHEMA_VERSION } from './migrations';
|
||||||
import ProblemList from './components/Problems/Problems';
|
import ProblemList from './components/Problems/Problems';
|
||||||
import AlertList from './components/AlertList/AlertList';
|
import AlertList from './components/AlertList/AlertList';
|
||||||
import { getNextRefIdChar } from './utils';
|
|
||||||
|
|
||||||
const ZABBIX_DS_ID = 'alexanderzobnin-zabbix-datasource';
|
|
||||||
const PROBLEM_EVENTS_LIMIT = 100;
|
const PROBLEM_EVENTS_LIMIT = 100;
|
||||||
|
|
||||||
export const DEFAULT_TARGET = {
|
export const DEFAULT_TARGET = {
|
||||||
@@ -24,18 +22,6 @@ export const DEFAULT_TARGET = {
|
|||||||
proxy: {filter: ""},
|
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 = [
|
export const DEFAULT_SEVERITY = [
|
||||||
{ priority: 0, severity: 'Not classified', color: 'rgb(108, 108, 108)', show: true},
|
{ priority: 0, severity: 'Not classified', color: 'rgb(108, 108, 108)', show: true},
|
||||||
{ priority: 1, severity: 'Information', color: 'rgb(120, 158, 183)', 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 = {
|
export const PANEL_DEFAULTS = {
|
||||||
schemaVersion: CURRENT_SCHEMA_VERSION,
|
schemaVersion: CURRENT_SCHEMA_VERSION,
|
||||||
// targets: [getDefaultTarget([])],
|
|
||||||
// Fields
|
// Fields
|
||||||
hostField: true,
|
hostField: true,
|
||||||
hostTechNameField: false,
|
hostTechNameField: false,
|
||||||
@@ -115,7 +100,7 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
|||||||
this.range = {};
|
this.range = {};
|
||||||
this.renderData = [];
|
this.renderData = [];
|
||||||
|
|
||||||
// this.panel = migratePanelSchema(this.panel);
|
this.panel = migratePanelSchema(this.panel);
|
||||||
_.defaultsDeep(this.panel, _.cloneDeep(PANEL_DEFAULTS));
|
_.defaultsDeep(this.panel, _.cloneDeep(PANEL_DEFAULTS));
|
||||||
|
|
||||||
this.events.on(PanelEvents.render, this.onRender.bind(this));
|
this.events.on(PanelEvents.render, this.onRender.bind(this));
|
||||||
@@ -125,6 +110,8 @@ export class TriggerPanelCtrl extends MetricsPanelCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onInitEditMode() {
|
onInitEditMode() {
|
||||||
|
// Update schema version to prevent migration on up-to-date targets
|
||||||
|
this.panel.schemaVersion = CURRENT_SCHEMA_VERSION;
|
||||||
this.addEditorTab('Options', triggerPanelOptionsTab);
|
this.addEditorTab('Options', triggerPanelOptionsTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user