Skip to content

Commit

Permalink
Merge pull request #423 from iobroker-community-adapters/abort_check
Browse files Browse the repository at this point in the history
abort check
  • Loading branch information
arteck authored Nov 12, 2024
2 parents c5e0f77 + 86e764a commit c38c226
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 42 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Control and use data from your Proxmox VE
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->

### **WORK IN PROGRESS**
* (arteck) fix node message


### 2.3.0 (2024-04-26)
* (mcm1957) Adapter requires node.js >= 18 and js-controller >= 5 now
* (jens-maus) fix ha and ceph object type
Expand Down
71 changes: 34 additions & 37 deletions lib/proxmox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProxmoxUtils {

this.setNextUrlMain(0);

this.adapter.log.info(`Using Proxmox API: ${this.URL}`);
this.adapter.log.info(`Using Node: ${this.URL}`);

this.responseCache = {};
this.sharedMap = {};
Expand All @@ -37,14 +37,11 @@ class ProxmoxUtils {
}

this.currentIpId++;
if (this.currentIpId === this.ipList.length) {

if (this.currentIpId == this.ipList.length) {
this.currentIpId = 0;
}

// if (this.ipList[this.currentIpId]) {
// this.currentIpId = 0;
// }

this.URL = `https://${this.ipList[this.currentIpId]}:${this.port}/api2/json`;
return this.URL;
}
Expand All @@ -59,7 +56,7 @@ class ProxmoxUtils {
if (this.responseCache['/nodes']) {
resolve(JSON.parse(JSON.stringify(this.responseCache['/nodes'])));
} else {
this._getData('/nodes', 'get')
this._getData('/nodes', 'get', '', '', 'getNodes')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache['/nodes'] = data.data;
Expand All @@ -78,7 +75,7 @@ class ProxmoxUtils {
if (useCache && this.responseCache[`/nodes/${node}/status`]) {
resolve(JSON.parse(JSON.stringify(this.responseCache[`/nodes/${node}/status`])));
} else {
this._getData(`/nodes/${node}/status`, 'get')
this._getData(`/nodes/${node}/status`, 'get', '', '', 'getNodeStatus')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache[`/nodes/${node}/status`] = data.data;
Expand All @@ -97,7 +94,7 @@ class ProxmoxUtils {
if (useCache && this.responseCache[`/nodes/${node}/disks/list`]) {
resolve(JSON.parse(JSON.stringify(this.responseCache[`/nodes/${node}/disks/list`])));
} else {
this._getData(`/nodes/${node}/disks/list`, 'get')
this._getData(`/nodes/${node}/disks/list`, 'get', '', '', 'getNodeDisks')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache[`/nodes/${node}/disks/list`] = data.data;
Expand All @@ -112,23 +109,23 @@ class ProxmoxUtils {
}

async getNodeDisksSmart(node, disk) {
return this._getData(`/nodes/${node}/disks/smart?disk=${disk}`, 'get');
return this._getData(`/nodes/${node}/disks/smart?disk=${disk}`, 'get', '', '', 'getNodeDisksSmart');
}

async getCephInformation() {
return this._getData(`/cluster/ceph/status`, 'get', '', '', 'ceph');
return this._getData(`/cluster/ceph/status`, 'get', '', '', 'getCephInformation');
}

async getHAStatusInformation() {
return this._getData(`/cluster/ha/status/current`, 'get', '', '', 'ha');
return this._getData(`/cluster/ha/status/current`, 'get', '', '', 'getHAStatusInformation');
}

async getClusterResources(useCache) {
return new Promise((resolve, reject) => {
if (useCache && this.responseCache['/cluster/resources']) {
resolve(JSON.parse(JSON.stringify(this.responseCache['/cluster/resources'])));
} else {
return this._getData('/cluster/resources', 'get')
return this._getData('/cluster/resources', 'get', '', '', 'getClusterResources')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache['/cluster/resources'] = data.data;
Expand All @@ -147,7 +144,7 @@ class ProxmoxUtils {
if (useCache && this.responseCache[`/nodes/${node}/${type}/${ID}/status/current`]) {
resolve(JSON.parse(JSON.stringify(this.responseCache[`/nodes/${node}/${type}/${ID}/status/current`])));
} else {
this._getData(`/nodes/${node}/${type}/${ID}/status/current`, 'get')
this._getData(`/nodes/${node}/${type}/${ID}/status/current`, 'get', '', '', 'ResourceStatus')
.then((data) => {
if (data !== '' && data !== null && typeof data === 'object') {
this.responseCache[`/nodes/${node}/${type}/${ID}/status/current`] = data.data;
Expand Down Expand Up @@ -258,10 +255,10 @@ class ProxmoxUtils {
reject('STOPPED');
}

if (typeof data === 'undefined') {
if (typeof data == 'undefined') {
data = null;
}
if (typeof retry === 'undefined') {
if (typeof retry == 'undefined') {
retry = null;
}

Expand All @@ -284,7 +281,7 @@ class ProxmoxUtils {
httpsAgent: new https.Agent({
rejectUnauthorized: false,
}),
})
})
.then((response) => {
this.adapter.log.debug(`received ${response.status} response from ${pathU} with content: ${JSON.stringify(response.data)}`);
this.communicationErrorCounter = 0;
Expand All @@ -294,7 +291,7 @@ class ProxmoxUtils {
}

if (response.status === 401 && !retry) {
if (additional == null) {
if (additional == undefined) {
this.ticket(async () => {
// Retry with new ticket
this._getData(url, method, data, true).then(resolve).catch(reject);
Expand All @@ -306,26 +303,26 @@ class ProxmoxUtils {
}
})
.catch((_error) => {
if (additional != 'storage') {

this.adapter.log.warn(`${additional} -- Use Next Proxmox Host because of communication failure ${this.URL}${url}`);

this.communicationErrorCounter++;
// We experienced error the same as we have servers available, so no chance to retry another server
this.setNextUrlMain();
if (this.communicationErrorCounter >= this.ipList.length) {
// this.adapter.log.error(`Error received response from ${error.config.url}`);
this.setNextUrlMain(0);
}

this.ticket(async () => {
// Retry with new ticket
this._getData(url, method, data, true).then(resolve).catch(reject);
});
}
if (additional == 'storage') {
this.adapter.log.error(`Check ${additional} -- Problem found.. maybe offline `);
}
this.adapter.log.error(`Check ${additional} -- Problem found.. storage is offline ??`);
} else {

this.adapter.log.warn(`${additional} -- Use Next Proxmox Node because of communication failure ${this.URL}${url}`);

this.communicationErrorCounter++;
// We experienced error the same as we have servers available, so no chance to retry another server
this.setNextUrlMain();

if (this.communicationErrorCounter >= this.ipList.length) {
this.setNextUrlMain(0);
this.communicationErrorCounter = 0;
}

this.ticket(async () => {
// Retry with new ticket
this._getData(url, method, data, true).then(resolve).catch(reject);
});
}
});
});
}
Expand Down
12 changes: 7 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ class Proxmox extends utils.Adapter {

sendRequest(nextRunTimeout) {
this.setState('info.lastUpdate', { val: Date.now(), ack: true });
this.requestInterval && this.clearTimeout(this.requestInterval);

if (this.clearTimeout) {
this.clearTimeout(this.requestInterval);
this.requestInterval = null;
}

this.requestInterval = this.setTimeout(
async () => {
this.requestInterval = null;

if (this.proxmox) {
this.log.debug('sendRequest interval started');
this.proxmox.resetResponseCache(); // Clear cache to start fresh
Expand All @@ -238,8 +241,7 @@ class Proxmox extends utils.Adapter {
}

this.sendRequest();
},
nextRunTimeout || this.config.requestInterval * 1000,
}, nextRunTimeout || this.config.requestInterval * 1000,
);
}

Expand Down

0 comments on commit c38c226

Please sign in to comment.