Add option to specify surveil api url
Change-Id: Ia3abf43f1dfc0b076520437741b00837b8249d1e
This commit is contained in:
parent
c7c793b699
commit
6d40b87c7d
@ -31,12 +31,9 @@ angular.module('bansho.authentication', [])
|
||||
login($scope.credentials);
|
||||
};
|
||||
|
||||
if (authService.isAuthenticated()) {
|
||||
login($scope.credentials);
|
||||
}
|
||||
|
||||
configManager.loadDevelopmentConfig().then(function () {
|
||||
var devConfig = configManager.getDevelopmentConfig();
|
||||
|
||||
if (devConfig.env === 'development') {
|
||||
login({
|
||||
'auth': {
|
||||
@ -47,6 +44,8 @@ angular.module('bansho.authentication', [])
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (authService.isAuthenticated()) {
|
||||
login($scope.credentials);
|
||||
}
|
||||
|
||||
}, function () {
|
||||
@ -55,13 +54,13 @@ angular.module('bansho.authentication', [])
|
||||
|
||||
}])
|
||||
|
||||
.factory('authService', [ '$http', '$location', '$rootScope', 'session', 'configManager', 'themeManager',
|
||||
function ($http, $location, $rootScope, session, configManager, themeManager) {
|
||||
.factory('authService', [ '$http', '$location', '$rootScope', 'session', 'configManager', 'themeManager', 'surveilConfig',
|
||||
function ($http, $location, $rootScope, session, configManager, themeManager, surveilConfig) {
|
||||
var authService = {};
|
||||
|
||||
authService.login = function (credentials) {
|
||||
return $http
|
||||
.post('surveil/v2/auth/tokens/', credentials)
|
||||
.post(surveilConfig.getAuthUrl() + '/tokens/', credentials)
|
||||
.success(function (data) {
|
||||
$rootScope.isAuthenticated = true;
|
||||
|
||||
|
@ -87,103 +87,106 @@ angular.module('bansho.config', [])
|
||||
};
|
||||
}])
|
||||
|
||||
.service('configManager', ['$http', '$q', 'componentsConfig', function ($http, $q, componentsConfig) {
|
||||
var config = {},
|
||||
developmentConfig = {};
|
||||
.service('configManager', ['$http', '$q', 'componentsConfig', 'surveilConfig',
|
||||
function ($http, $q, componentsConfig, surveilConfig) {
|
||||
var config = {},
|
||||
developmentConfig = {};
|
||||
|
||||
this.loadDevelopmentConfig = function() {
|
||||
var promise = $q.defer();
|
||||
this.loadDevelopmentConfig = function() {
|
||||
var promise = $q.defer();
|
||||
|
||||
$http.get('components/config/developmentConfig.json')
|
||||
.success(function (config) {
|
||||
developmentConfig = config;
|
||||
promise.resolve();
|
||||
})
|
||||
.error(function() {
|
||||
promise.reject();
|
||||
});
|
||||
$http.get('components/config/developmentConfig.json')
|
||||
.success(function (config) {
|
||||
developmentConfig = config;
|
||||
surveilConfig.setSurveilApiUrl(config.surveilApiUrl);
|
||||
surveilConfig.setAuthUrl(config.surveilAuthUrl);
|
||||
promise.resolve();
|
||||
})
|
||||
.error(function() {
|
||||
promise.reject();
|
||||
});
|
||||
|
||||
return promise.promise;
|
||||
};
|
||||
return promise.promise;
|
||||
};
|
||||
|
||||
this.getDevelopmentConfig = function () {
|
||||
return developmentConfig;
|
||||
};
|
||||
this.getDevelopmentConfig = function () {
|
||||
return developmentConfig;
|
||||
};
|
||||
|
||||
this.getConfigData = function (templateName) {
|
||||
return config.data[templateName];
|
||||
};
|
||||
this.getConfigData = function (templateName) {
|
||||
return config.data[templateName];
|
||||
};
|
||||
|
||||
this.readConfig = function () {
|
||||
return config.data;
|
||||
};
|
||||
this.readConfig = function () {
|
||||
return config.data;
|
||||
};
|
||||
|
||||
this.saveConfig = function(configuration) {
|
||||
config.data = configuration;
|
||||
saveConfig();
|
||||
};
|
||||
this.saveConfig = function(configuration) {
|
||||
config.data = configuration;
|
||||
saveConfig();
|
||||
};
|
||||
|
||||
this.setThemeAndSave = function (theme) {
|
||||
config.data.banshoConfig.theme = theme;
|
||||
saveConfig();
|
||||
};
|
||||
this.setThemeAndSave = function (theme) {
|
||||
config.data.banshoConfig.theme = theme;
|
||||
saveConfig();
|
||||
};
|
||||
|
||||
this.getTheme = function () {
|
||||
var theme;
|
||||
this.getTheme = function () {
|
||||
var theme;
|
||||
|
||||
if (config.data) {
|
||||
theme = config.data.banshoConfig.theme;
|
||||
}
|
||||
if (config.data) {
|
||||
theme = config.data.banshoConfig.theme;
|
||||
}
|
||||
|
||||
return theme;
|
||||
};
|
||||
return theme;
|
||||
};
|
||||
|
||||
var saveConfig = function () {
|
||||
var responsePromise = $q.defer();
|
||||
var saveConfig = function () {
|
||||
var responsePromise = $q.defer();
|
||||
|
||||
$http.post('surveil/v2/bansho/config', JSON.stringify(config.data))
|
||||
.success(function () {
|
||||
responsePromise.resolve();
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to send config to server');
|
||||
});
|
||||
|
||||
return responsePromise.promise;
|
||||
};
|
||||
|
||||
this.fetchConfig = function (useStoredConfig) {
|
||||
var responsePromise = $q.defer();
|
||||
|
||||
componentsConfig.load();
|
||||
|
||||
$http.get('surveil/v2/bansho/config')
|
||||
.success(function (conf) {
|
||||
if (!useStoredConfig || jQuery.isEmptyObject(conf)) {
|
||||
$http.get('components/config/config.json')
|
||||
.success(function (conf) {
|
||||
config.data = conf;
|
||||
|
||||
$http.post('surveil/v2/bansho/config', JSON.stringify(conf))
|
||||
.success(function () {
|
||||
responsePromise.resolve();
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to send config to server');
|
||||
});
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to fetch default config');
|
||||
});
|
||||
} else {
|
||||
config.data = conf;
|
||||
$http.post(surveilConfig.endpoint('config'), JSON.stringify(config.data))
|
||||
.success(function () {
|
||||
responsePromise.resolve();
|
||||
}
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to fetch config');
|
||||
});
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to send config to server');
|
||||
});
|
||||
|
||||
return responsePromise.promise;
|
||||
};
|
||||
}]);
|
||||
|
||||
this.fetchConfig = function (useStoredConfig) {
|
||||
var responsePromise = $q.defer();
|
||||
|
||||
componentsConfig.load();
|
||||
|
||||
$http.get(surveilConfig.endpoint('config'))
|
||||
.success(function (conf) {
|
||||
if (!useStoredConfig || jQuery.isEmptyObject(conf)) {
|
||||
$http.get('components/config/config.json')
|
||||
.success(function (conf) {
|
||||
config.data = conf;
|
||||
|
||||
$http.post(surveilConfig.endpoint('config'), JSON.stringify(conf))
|
||||
.success(function () {
|
||||
responsePromise.resolve();
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to send config to server');
|
||||
});
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to fetch default config');
|
||||
});
|
||||
} else {
|
||||
config.data = conf;
|
||||
responsePromise.resolve();
|
||||
}
|
||||
})
|
||||
.error(function () {
|
||||
responsePromise.reject('Failed to fetch config');
|
||||
});
|
||||
|
||||
return responsePromise.promise;
|
||||
};
|
||||
}]);
|
||||
|
@ -2,5 +2,7 @@
|
||||
"env": "production",
|
||||
"username":"",
|
||||
"password":"",
|
||||
"useStoredConfig": true
|
||||
"useStoredConfig": true,
|
||||
"surveilApiUrl": "surveil/v2",
|
||||
"surveilAuthUrl": "surveil/v2/auth"
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.surveil')
|
||||
.service('surveilStatus', ['$http', '$q', 'surveilQuery', 'componentsConfig',
|
||||
function ($http, $q, surveilQuery, componentsConfig) {
|
||||
.service('surveilStatus', ['$http', '$q', 'surveilQuery', 'componentsConfig', 'surveilConfig',
|
||||
function ($http, $q, surveilQuery, componentsConfig, surveilConfig) {
|
||||
var getMetric = function (host, service, metric) {
|
||||
var url = 'surveil/v2/status/hosts/' + host,
|
||||
var url = surveilConfig.endpoint('status') + '/hosts/' + host,
|
||||
responsePromise = $q.defer();
|
||||
|
||||
if (service !== undefined) {
|
||||
@ -25,7 +25,7 @@ angular.module('bansho.surveil')
|
||||
};
|
||||
|
||||
var getMetricNames = function (host, service) {
|
||||
var url = '/surveil/v2/status/hosts/' + host,
|
||||
var url = surveilConfig.endpoint('status') + '/hosts/' + host,
|
||||
responsePromise = $q.defer();
|
||||
|
||||
if (service !== undefined) {
|
||||
@ -44,7 +44,7 @@ angular.module('bansho.surveil')
|
||||
|
||||
responsePromise.resolve(result);
|
||||
}).error(function () {
|
||||
throw new Error('getMetricNames: GET Request failed');
|
||||
throw new Error('getMetricNames: GET Request failed');
|
||||
});
|
||||
|
||||
return responsePromise.promise;
|
||||
@ -78,9 +78,9 @@ angular.module('bansho.surveil')
|
||||
var hostQuery = surveilQuery(fields, filters.hosts),
|
||||
serviceQuery = surveilQuery(fields, filters.services);
|
||||
|
||||
executeQuery('surveil/v2/status/hosts/', 'POST', hostQuery)
|
||||
executeQuery(surveilConfig.endpoint('status') + '/hosts/', 'POST', hostQuery)
|
||||
.success(function (hosts) {
|
||||
executeQuery('surveil/v2/status/services/', 'POST', serviceQuery)
|
||||
executeQuery(surveilConfig.endpoint('status') + '/services/', 'POST', serviceQuery)
|
||||
.success(function (services) {
|
||||
callback(hosts, services);
|
||||
});
|
||||
@ -129,7 +129,7 @@ angular.module('bansho.surveil')
|
||||
"hosts": function (fields, filters, callback) {
|
||||
var hostQuery = surveilQuery(fields, filters.hosts),
|
||||
method = 'POST',
|
||||
hostUrl = 'surveil/v2/status/hosts/';
|
||||
hostUrl = surveilConfig.endpoint('status') + '/hosts/';
|
||||
|
||||
if (filters.hosts && filters.hosts.is && filters.hosts.is.host_name) {
|
||||
hostUrl += filters.hosts.is.host_name;
|
||||
@ -151,7 +151,7 @@ angular.module('bansho.surveil')
|
||||
"events": function (fields, filters, callback) {
|
||||
var query = surveilQuery(fields, filters.events);
|
||||
|
||||
executeQuery('surveil/v2/status/events/', 'POST', query)
|
||||
executeQuery(surveilConfig.endpoint('status') + '/events/', 'POST', query)
|
||||
.success(function (events) {
|
||||
angular.forEach(events, function (event) {
|
||||
angular.forEach(event, function (value, attr) {
|
||||
|
@ -1 +1,26 @@
|
||||
angular.module('bansho.surveil', []);
|
||||
angular.module('bansho.surveil', [])
|
||||
.service('surveilConfig', function () {
|
||||
var apiUrl,
|
||||
authUrl,
|
||||
surveilEndpoints = {};
|
||||
|
||||
return {
|
||||
setSurveilApiUrl: function (surveilApiUrl) {
|
||||
apiUrl = surveilApiUrl;
|
||||
surveilEndpoints = {
|
||||
status: apiUrl + '/status',
|
||||
actions: apiUrl + '/actions',
|
||||
config: apiUrl + '/bansho/config'
|
||||
};
|
||||
},
|
||||
setAuthUrl: function (url) {
|
||||
authUrl = url;
|
||||
},
|
||||
endpoint: function (endpoint) {
|
||||
return surveilEndpoints[endpoint];
|
||||
},
|
||||
getAuthUrl: function () {
|
||||
return authUrl;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user