diff --git a/src/datasource-zabbix/zabbixCache.service.js b/src/datasource-zabbix/zabbixCache.service.js index af0f623..2ba8ef9 100644 --- a/src/datasource-zabbix/zabbixCache.service.js +++ b/src/datasource-zabbix/zabbixCache.service.js @@ -110,61 +110,6 @@ angular.module('grafana.services').factory('ZabbixCachingProxy', function($q, $i }); } - _getHosts() { - var self = this; - if (this._hosts) { - return this.$q.when(self._hosts); - } else { - return this.refresh().then(function() { - return self._hosts; - }); - } - } - - getIndexedHosts() { - var self = this; - if (this._idx_hosts) { - return this.$q.when(self._idx_hosts); - } else { - return this.refresh().then(function() { - return self._idx_hosts; - }); - } - } - - getIndexedApplications() { - var self = this; - if (this._idx_apps) { - return this.$q.when(self._idx_apps); - } else { - return this.refresh().then(function() { - return self._idx_apps; - }); - } - } - - getApplications() { - var self = this; - if (this._applications) { - return this.$q.when(self._applications); - } else { - return this.refresh().then(function() { - return self._applications; - }); - } - } - - _getItems(type) { - var self = this; - if (this._items) { - return this.$q.when(filterItems(self._items, type)); - } else { - return this.refresh().then(function() { - return filterItems(self._items, type); - }); - } - } - getHistoryFromCache(items, time_from, time_till) { var deferred = this.$q.defer(); var historyStorage = this.storage.history; @@ -268,114 +213,6 @@ angular.module('grafana.services').factory('ZabbixCachingProxy', function($q, $i return ZabbixCachingProxy; }); -/** - * Convert host.get response to cache format - * host.groups - array of group ids - */ -function convertHosts(hosts) { - return _.forEach(hosts, function(host) { - host.groups = _.map(host.groups, 'groupid'); - return host; - }); -} - -function convertGroups(groups) { - return _.forEach(groups, function(group) { - group.hosts = _.map(group.hosts, 'hostid'); - return group; - }); -} - -/** - * Group Zabbix applications by name - * host.hosts - array of host ids - */ -function convertApplications(applications) { - return _.map(_.groupBy(applications, 'name'), function(value, key) { - //console.log(value); - // Hack for supporting different apis (2.2 vs 2.4 vs 3.0) - var hostField = 'host'; - if (value[0] && value[0]['hosts']) { - // For Zabbix 2.2 - hostField = 'hosts'; - } - - return { - name: key, - applicationids: _.map(value, 'applicationid'), - itemids: _.uniq(_.map(_.flatten(value, 'items'), 'itemid')), - hosts: _.uniq(_.map(_.flatten(value, hostField), 'hostid')) - }; - }); -} - -function indexHosts(hosts) { - return _.indexBy(_.map(hosts, function(host) { - - // Expand item names - host.items = _.forEach(host.items, function(item) { - item.item = item.name; - item.name = utils.expandItemName(item.item, item.key_); - return item; - }); - - host.applications = _.map(host.applications, 'applicationid'); - host.idx_items = indexItems(host.items); - host.items = _.map(host.items, 'itemid'); - return host; - }), 'hostid'); -} - -function indexApps(applications) { - return _.indexBy(_.map(applications, function(app) { - return { - name: app.name, - applicationid: app.applicationid, - host: _.first(_.map(app.hosts, 'hostid')), - itemids: _.map(app.items, 'itemid') - }; - }), 'applicationid'); -} - -function indexItems(items) { - return _.indexBy(_.map(items, function(item) { - return item; - }), 'itemid'); -} - -/** - * Convert item.get response to cache format - * item.applications - array of application ids - * item.item - original item name returned by api (ie "CPU $2 time") - * item.name - expanded name (ie "CPU system time") - */ -function convertItems(items) { - return _.forEach(items, function(item) { - item.applications = _.map(item.applications, 'applicationid'); - item.item = item.name; - item.name = utils.expandItemName(item.item, item.key_); - return item; - }); -} - -function filterItems(items, type) { - switch (type) { - case 'num': - return _.filter(items, function(item) { - return (item.value_type === '0' || - item.value_type === '3'); - }); - case 'text': - return _.filter(items, function(item) { - return (item.value_type === '1' || - item.value_type === '2' || - item.value_type === '4'); - }); - default: - return items; - } -} - String.prototype.getHash = function() { var hash = 0, i, chr, len; if (this.length === 0) {