Fix API initialization, closes #861

This commit is contained in:
Alexander Zobnin
2020-05-20 14:54:21 +03:00
parent 4c462e72dc
commit d18e6cc675
3 changed files with 18 additions and 8 deletions

View File

@@ -62,12 +62,16 @@ export class ZabbixAPIConnector {
return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth)
.catch(error => {
if (isNotAuthorized(error.data)) {
if (isNotInitialized(error.data)) {
// If API not initialized yet (auth is empty), login first
return this.loginOnce()
.then(() => this.request(method, params));
} else if (isNotAuthorized(error.data)) {
// Handle auth errors
this.loginErrorCount++;
if (this.loginErrorCount > this.maxLoginAttempts) {
this.loginErrorCount = 0;
return null;
return Promise.resolve();
} else {
return this.loginOnce()
.then(() => this.request(method, params));
@@ -237,7 +241,7 @@ export class ZabbixAPIConnector {
};
return this.request('item.get', params)
.then(utils.expandItems);
.then(items => utils.expandItems(items));
}
getMacros(hostids) {
@@ -662,6 +666,10 @@ function filterTriggersByAcknowledge(triggers, acknowledged) {
}
}
function isNotInitialized(message) {
return message === "Not initialized";
}
function isNotAuthorized(message) {
return (
message === "Session terminated, re-login, please." ||