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