2014-02-15 06:46:36 -06:00
|
|
|
define([
|
|
|
|
'angular',
|
|
|
|
'underscore',
|
2014-02-27 14:46:06 -06:00
|
|
|
'config',
|
|
|
|
'./graphite/graphiteDatasource',
|
|
|
|
'./influxdb/influxdbDatasource',
|
2014-02-15 06:46:36 -06:00
|
|
|
],
|
2014-02-25 10:48:01 -06:00
|
|
|
function (angular, _, config) {
|
2014-02-15 06:46:36 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var module = angular.module('kibana.services');
|
|
|
|
|
2014-02-27 14:46:06 -06:00
|
|
|
module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource) {
|
2014-02-25 10:48:01 -06:00
|
|
|
|
2014-03-04 15:01:25 -06:00
|
|
|
this.init = function() {
|
2014-02-15 06:46:36 -06:00
|
|
|
|
2014-03-04 15:01:25 -06:00
|
|
|
var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } );
|
|
|
|
this.default = this.datasourceFactory(defaultDatasource);
|
2014-03-04 14:49:06 -06:00
|
|
|
|
2014-03-04 15:01:25 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
this.datasourceFactory = function(ds) {
|
2014-03-04 14:49:06 -06:00
|
|
|
switch(ds.type) {
|
|
|
|
case 'graphite':
|
|
|
|
return new GraphiteDatasource(ds);
|
|
|
|
case 'influxdb':
|
|
|
|
return new InfluxDatasource(ds);
|
|
|
|
}
|
2014-03-04 15:01:25 -06:00
|
|
|
};
|
2014-02-15 06:46:36 -06:00
|
|
|
|
|
|
|
this.get = function(name) {
|
2014-02-27 14:46:06 -06:00
|
|
|
if (!name) { return this.default; }
|
|
|
|
|
|
|
|
var ds = config.datasources[name];
|
2014-03-02 06:26:08 -06:00
|
|
|
if (!ds) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-02-15 06:46:36 -06:00
|
|
|
|
2014-03-04 15:01:25 -06:00
|
|
|
return this.datasourceFactory(ds);
|
2014-02-15 06:46:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
this.listOptions = function() {
|
|
|
|
return _.map(config.datasources, function(value, key) {
|
|
|
|
return {
|
|
|
|
name: value.default ? key + ' (default)' : key,
|
|
|
|
value: value.default ? null : key
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2014-03-04 15:01:25 -06:00
|
|
|
|
|
|
|
this.init();
|
2014-02-15 06:46:36 -06:00
|
|
|
});
|
|
|
|
});
|