Fixed "Session terminated, re-login, please." error when auth token expired.
This commit is contained in:
@@ -30,6 +30,7 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
// For testing
|
// For testing
|
||||||
this.ds = datasource;
|
this.ds = datasource;
|
||||||
|
this.auth = 'testauth'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -216,10 +217,10 @@ function (angular, _, kbn) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var performedQuery;
|
var performedQuery;
|
||||||
|
var self = this;
|
||||||
|
|
||||||
// Check authorization first
|
// Check authorization first
|
||||||
if (!this.auth) {
|
if (!this.auth) {
|
||||||
var self = this;
|
|
||||||
performedQuery = this.performZabbixAPILogin().then(function (response) {
|
performedQuery = this.performZabbixAPILogin().then(function (response) {
|
||||||
self.auth = response;
|
self.auth = response;
|
||||||
options.data.auth = response;
|
options.data.auth = response;
|
||||||
@@ -232,9 +233,22 @@ function (angular, _, kbn) {
|
|||||||
// Handle response
|
// Handle response
|
||||||
return performedQuery.then(function (response) {
|
return performedQuery.then(function (response) {
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
// TODO: handle "auth token expired" error
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
else if (response.data.error) {
|
||||||
|
// Handle Zabbix API errors
|
||||||
|
|
||||||
|
if (response.data.error.data == "Session terminated, re-login, please.") {
|
||||||
|
// Handle "Session terminated, re-login, please." error
|
||||||
|
return self.performZabbixAPILogin().then(function (response) {
|
||||||
|
self.auth = response;
|
||||||
|
options.data.auth = response;
|
||||||
|
return backendSrv.datasourceRequest(options);
|
||||||
|
}).then(function (response) {
|
||||||
|
return response.data.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
return response.data.result;
|
return response.data.result;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -270,8 +284,11 @@ function (angular, _, kbn) {
|
|||||||
ZabbixAPIDatasource.prototype.performHostGroupSuggestQuery = function() {
|
ZabbixAPIDatasource.prototype.performHostGroupSuggestQuery = function() {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
real_hosts: true, //Return only host groups that contain hosts
|
sortfield: 'name',
|
||||||
sortfield: 'name'
|
// Return only host groups that contain hosts
|
||||||
|
real_hosts: true,
|
||||||
|
// Return only host groups that contain monitored hosts.
|
||||||
|
monitored_hosts: true
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.performZabbixAPIRequest('hostgroup.get', params);
|
return this.performZabbixAPIRequest('hostgroup.get', params);
|
||||||
|
|||||||
Reference in New Issue
Block a user