Added initial cache service for groups, hosts, applications and
items caching on client side.
This commit is contained in:
59
plugins/datasource-zabbix/zabbixCacheSrv.js
Normal file
59
plugins/datasource-zabbix/zabbixCacheSrv.js
Normal file
@@ -0,0 +1,59 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash'
|
||||
],
|
||||
function (angular, _) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
|
||||
module.factory('ZabbixCache', function($q, backendSrv) {
|
||||
|
||||
function ZabbixCache(zabbixAPI, lifetime) {
|
||||
var self = this;
|
||||
this.zabbixAPI = zabbixAPI;
|
||||
this.lifetime = lifetime;
|
||||
|
||||
var promises = [
|
||||
this.zabbixAPI.getGroups(),
|
||||
this.zabbixAPI.getHosts(),
|
||||
this.zabbixAPI.getApplications(),
|
||||
this.zabbixAPI.getItems()
|
||||
];
|
||||
|
||||
$q.all(promises).then(function (results) {
|
||||
console.log(results);
|
||||
if (results.length) {
|
||||
self._groups = results[0];
|
||||
self._hosts = results[1];
|
||||
self._applications = groupApplications(results[2]);
|
||||
self._items = results[3];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var p = ZabbixCache.prototype;
|
||||
|
||||
p.getHosts = function() {
|
||||
return this._hosts;
|
||||
};
|
||||
|
||||
/**
|
||||
* Group Zabbix applications by name
|
||||
* @param {[type]} applications [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
function groupApplications(applications) {
|
||||
return _.map(_.groupBy(applications, 'name'), function (value, key) {
|
||||
return {
|
||||
name: key,
|
||||
ids: _.map(value, 'applicationid')
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return ZabbixCache;
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user