Fix default query type for new queries if data source is not default

This commit is contained in:
Alexander Zobnin
2021-08-05 18:17:27 +03:00
parent 62f38df28a
commit c3ce8824af

View File

@@ -4,7 +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, ZabbixMetricsQuery } from './types'; import { ShowProblemTypes } from './types';
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations'; import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime'; import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
@@ -22,9 +22,9 @@ function getTargetDefaults() {
'minSeverity': 3, 'minSeverity': 3,
'acknowledged': 2 'acknowledged': 2
}, },
trigger: {filter: ""}, trigger: { filter: "" },
tags: {filter: ""}, tags: { filter: "" },
proxy: {filter: ""}, proxy: { filter: "" },
options: { options: {
showDisabledItems: false, showDisabledItems: false,
skipEmptyValues: false, skipEmptyValues: false,
@@ -115,12 +115,12 @@ export class ZabbixQueryController extends QueryCtrl {
this.templateSrv = getTemplateSrv(); this.templateSrv = getTemplateSrv();
this.editorModes = [ this.editorModes = [
{value: 'num', text: 'Metrics', queryType: c.MODE_METRICS}, { value: 'num', text: 'Metrics', queryType: c.MODE_METRICS },
{value: 'text', text: 'Text', queryType: c.MODE_TEXT}, { value: 'text', text: 'Text', queryType: c.MODE_TEXT },
{value: 'itservice', text: 'IT Services', queryType: c.MODE_ITSERVICE}, { value: 'itservice', text: 'IT Services', queryType: c.MODE_ITSERVICE },
{value: 'itemid', text: 'Item ID', queryType: c.MODE_ITEMID}, { value: 'itemid', text: 'Item ID', queryType: c.MODE_ITEMID },
{value: 'triggers', text: 'Triggers', queryType: c.MODE_TRIGGERS}, { value: 'triggers', text: 'Triggers', queryType: c.MODE_TRIGGERS },
{value: 'problems', text: 'Problems', queryType: c.MODE_PROBLEMS}, { value: 'problems', text: 'Problems', queryType: c.MODE_PROBLEMS },
]; ];
this.$scope.editorMode = { this.$scope.editorMode = {
@@ -133,11 +133,11 @@ export class ZabbixQueryController extends QueryCtrl {
}; };
this.slaPropertyList = [ this.slaPropertyList = [
{name: "Status", property: "status"}, { name: "Status", property: "status" },
{name: "SLA", property: "sla"}, { name: "SLA", property: "sla" },
{name: "OK time", property: "okTime"}, { name: "OK time", property: "okTime" },
{name: "Problem time", property: "problemTime"}, { name: "Problem time", property: "problemTime" },
{name: "Down time", property: "downtimeTime"} { name: "Down time", property: "downtimeTime" }
]; ];
this.slaIntervals = [ this.slaIntervals = [
@@ -151,9 +151,9 @@ export class ZabbixQueryController extends QueryCtrl {
]; ];
this.ackFilters = [ this.ackFilters = [
{text: 'all triggers', value: 2}, { text: 'all triggers', value: 2 },
{text: 'unacknowledged', value: 0}, { text: 'unacknowledged', value: 0 },
{text: 'acknowledged', value: 1}, { text: 'acknowledged', value: 1 },
]; ];
this.problemAckFilters = [ this.problemAckFilters = [
@@ -169,7 +169,7 @@ export class ZabbixQueryController extends QueryCtrl {
]; ];
this.showEventsFields = [ this.showEventsFields = [
{ text: 'All', value: [0,1] }, { text: 'All', value: [0, 1] },
{ text: 'OK', value: [0] }, { text: 'OK', value: [0] },
{ text: 'Problems', value: 1 } { text: 'Problems', value: 1 }
]; ];
@@ -218,6 +218,7 @@ export class ZabbixQueryController extends QueryCtrl {
// Load default values // Load default values
const targetDefaults = getTargetDefaults(); const targetDefaults = getTargetDefaults();
_.defaultsDeep(target, targetDefaults); _.defaultsDeep(target, targetDefaults);
this.initDefaultQueryMode(target);
if (this.panel.type === c.ZABBIX_PROBLEMS_PANEL_ID) { if (this.panel.type === c.ZABBIX_PROBLEMS_PANEL_ID) {
target.queryType = c.MODE_PROBLEMS; target.queryType = c.MODE_PROBLEMS;
@@ -257,7 +258,7 @@ export class ZabbixQueryController extends QueryCtrl {
} }
initFilters() { initFilters() {
const mode = _.find(this.editorModes, {'queryType': this.target.queryType}); const mode = _.find(this.editorModes, { 'queryType': this.target.queryType });
const itemtype = mode ? mode.value : null; const itemtype = mode ? mode.value : null;
const promises = [ const promises = [
this.suggestGroups(), this.suggestGroups(),
@@ -276,6 +277,17 @@ export class ZabbixQueryController extends QueryCtrl {
return Promise.all(promises); return Promise.all(promises);
} }
initDefaultQueryMode(target) {
if (!(target.queryType === c.MODE_METRICS ||
target.queryType === c.MODE_TEXT ||
target.queryType === c.MODE_ITSERVICE ||
target.queryType === c.MODE_ITEMID ||
target.queryType === c.MODE_TRIGGERS ||
target.queryType === c.MODE_PROBLEMS)) {
target.queryType = c.MODE_METRICS;
}
}
// Get list of metric names for bs-typeahead directive // Get list of metric names for bs-typeahead directive
getMetricNames(metricList, addAllValue) { getMetricNames(metricList, addAllValue) {
const metrics = _.uniq(_.map(this.metric[metricList], 'name')); const metrics = _.uniq(_.map(this.metric[metricList], 'name'));