From 84d93ecd5bad44c845896c2529a10f1704772c8c Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 20 May 2020 16:52:40 +0300 Subject: [PATCH] Variables: able to query item values, closes #417 --- .../components/VariableQueryEditor.tsx | 7 +++++-- src/datasource-zabbix/datasource.ts | 8 +++++++- src/datasource-zabbix/types.ts | 1 + .../zabbix_api/zabbixAPIConnector.ts | 1 + src/datasource-zabbix/zabbix/zabbix.ts | 20 +++++++++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/datasource-zabbix/components/VariableQueryEditor.tsx b/src/datasource-zabbix/components/VariableQueryEditor.tsx index e129443..51830ee 100644 --- a/src/datasource-zabbix/components/VariableQueryEditor.tsx +++ b/src/datasource-zabbix/components/VariableQueryEditor.tsx @@ -15,6 +15,7 @@ export class ZabbixVariableQueryEditor extends PureComponent {(selectedQueryType.value === VariableQueryTypes.Application || - selectedQueryType.value === VariableQueryTypes.Item) && + selectedQueryType.value === VariableQueryTypes.Item || + selectedQueryType.value === VariableQueryTypes.ItemValues) &&
Application @@ -133,7 +135,8 @@ export class ZabbixVariableQueryEditor extends PureComponent
- {selectedQueryType.value === VariableQueryTypes.Item && + {(selectedQueryType.value === VariableQueryTypes.Item || + selectedQueryType.value === VariableQueryTypes.ItemValues) &&
Item 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));