Variables: able to query item values, closes #417
This commit is contained in:
@@ -15,6 +15,7 @@ export class ZabbixVariableQueryEditor extends PureComponent<VariableQueryProps,
|
|||||||
{ value: VariableQueryTypes.Host, label: 'Host' },
|
{ value: VariableQueryTypes.Host, label: 'Host' },
|
||||||
{ value: VariableQueryTypes.Application, label: 'Application' },
|
{ value: VariableQueryTypes.Application, label: 'Application' },
|
||||||
{ value: VariableQueryTypes.Item, label: 'Item' },
|
{ value: VariableQueryTypes.Item, label: 'Item' },
|
||||||
|
{ value: VariableQueryTypes.ItemValues, label: 'Item values' },
|
||||||
];
|
];
|
||||||
|
|
||||||
defaults: VariableQueryData = {
|
defaults: VariableQueryData = {
|
||||||
@@ -123,7 +124,8 @@ export class ZabbixVariableQueryEditor extends PureComponent<VariableQueryProps,
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{(selectedQueryType.value === VariableQueryTypes.Application ||
|
{(selectedQueryType.value === VariableQueryTypes.Application ||
|
||||||
selectedQueryType.value === VariableQueryTypes.Item) &&
|
selectedQueryType.value === VariableQueryTypes.Item ||
|
||||||
|
selectedQueryType.value === VariableQueryTypes.ItemValues) &&
|
||||||
<div className="gf-form-inline">
|
<div className="gf-form-inline">
|
||||||
<div className="gf-form max-width-30">
|
<div className="gf-form max-width-30">
|
||||||
<FormLabel width={10}>Application</FormLabel>
|
<FormLabel width={10}>Application</FormLabel>
|
||||||
@@ -133,7 +135,8 @@ export class ZabbixVariableQueryEditor extends PureComponent<VariableQueryProps,
|
|||||||
onBlur={this.handleQueryChange}
|
onBlur={this.handleQueryChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{selectedQueryType.value === VariableQueryTypes.Item &&
|
{(selectedQueryType.value === VariableQueryTypes.Item ||
|
||||||
|
selectedQueryType.value === VariableQueryTypes.ItemValues) &&
|
||||||
<div className="gf-form max-width-30">
|
<div className="gf-form max-width-30">
|
||||||
<FormLabel width={10}>Item</FormLabel>
|
<FormLabel width={10}>Item</FormLabel>
|
||||||
<ZabbixInput
|
<ZabbixInput
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ export class ZabbixDatasource {
|
|||||||
* @return {string} Metric name - group, host, app or item or list
|
* @return {string} Metric name - group, host, app or item or list
|
||||||
* of metrics in "{metric1,metcic2,...,metricN}" format.
|
* of metrics in "{metric1,metcic2,...,metricN}" format.
|
||||||
*/
|
*/
|
||||||
metricFindQuery(query) {
|
metricFindQuery(query, options) {
|
||||||
let resultPromise;
|
let resultPromise;
|
||||||
let queryModel = _.cloneDeep(query);
|
let queryModel = _.cloneDeep(query);
|
||||||
|
|
||||||
@@ -534,6 +534,8 @@ export class ZabbixDatasource {
|
|||||||
queryModel[prop] = this.replaceTemplateVars(queryModel[prop], {});
|
queryModel[prop] = this.replaceTemplateVars(queryModel[prop], {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { group, host, application, item } = queryModel;
|
||||||
|
|
||||||
switch (queryModel.queryType) {
|
switch (queryModel.queryType) {
|
||||||
case VariableQueryTypes.Group:
|
case VariableQueryTypes.Group:
|
||||||
resultPromise = this.zabbix.getGroups(queryModel.group);
|
resultPromise = this.zabbix.getGroups(queryModel.group);
|
||||||
@@ -547,6 +549,10 @@ export class ZabbixDatasource {
|
|||||||
case VariableQueryTypes.Item:
|
case VariableQueryTypes.Item:
|
||||||
resultPromise = this.zabbix.getItems(queryModel.group, queryModel.host, queryModel.application, queryModel.item);
|
resultPromise = this.zabbix.getItems(queryModel.group, queryModel.host, queryModel.application, queryModel.item);
|
||||||
break;
|
break;
|
||||||
|
case VariableQueryTypes.ItemValues:
|
||||||
|
const range = options?.range;
|
||||||
|
resultPromise = this.zabbix.getItemValues(group, host, application, item, { range });
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
resultPromise = Promise.resolve([]);
|
resultPromise = Promise.resolve([]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export enum VariableQueryTypes {
|
|||||||
Host = 'host',
|
Host = 'host',
|
||||||
Application = 'application',
|
Application = 'application',
|
||||||
Item = 'item',
|
Item = 'item',
|
||||||
|
ItemValues = 'itemValues',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ShowProblemTypes {
|
export enum ShowProblemTypes {
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ export class ZabbixAPIConnector {
|
|||||||
* @return {[type]} array of items
|
* @return {[type]} array of items
|
||||||
*/
|
*/
|
||||||
getItems(hostids, appids, itemtype) {
|
getItems(hostids, appids, itemtype) {
|
||||||
|
console.log(itemtype);
|
||||||
const params: any = {
|
const params: any = {
|
||||||
output: [
|
output: [
|
||||||
'name', 'key_',
|
'name', 'key_',
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import moment from 'moment';
|
||||||
import * as utils from '../utils';
|
import * as utils from '../utils';
|
||||||
import responseHandler from '../responseHandler';
|
import responseHandler from '../responseHandler';
|
||||||
import { CachingProxy } from './proxy/cachingProxy';
|
import { CachingProxy } from './proxy/cachingProxy';
|
||||||
@@ -287,6 +288,25 @@ export class Zabbix implements ZabbixConnector {
|
|||||||
.then(items => filterByQuery(items, itemFilter));
|
.then(items => filterByQuery(items, itemFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getItemValues(groupFilter?, hostFilter?, appFilter?, itemFilter?, options: any = {}) {
|
||||||
|
return this.getItems(groupFilter, hostFilter, appFilter, itemFilter, options).then(items => {
|
||||||
|
let timeRange = [moment().subtract(2, 'h').unix(), moment().unix()];
|
||||||
|
if (options.range) {
|
||||||
|
timeRange = [options.range.from.unix(), options.range.to.unix()];
|
||||||
|
}
|
||||||
|
const [timeFrom, timeTo] = timeRange;
|
||||||
|
|
||||||
|
return this.zabbixAPI.getHistory(items, timeFrom, timeTo).then(history => {
|
||||||
|
if (history) {
|
||||||
|
const values = _.uniq(history.map(v => v.value));
|
||||||
|
return values.map(value => ({ name: value }));
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getITServices(itServiceFilter) {
|
getITServices(itServiceFilter) {
|
||||||
return this.zabbixAPI.getITService()
|
return this.zabbixAPI.getITService()
|
||||||
.then(itServices => findByFilter(itServices, itServiceFilter));
|
.then(itServices => findByFilter(itServices, itServiceFilter));
|
||||||
|
|||||||
Reference in New Issue
Block a user