iobroker.device-watcher 2.8.3 → 2.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/admin/i18n/de/translations.json +164 -161
- package/admin/i18n/en/translations.json +5 -1
- package/admin/i18n/es/translations.json +5 -1
- package/admin/i18n/fr/translations.json +5 -1
- package/admin/i18n/it/translations.json +5 -1
- package/admin/i18n/nl/translations.json +5 -1
- package/admin/i18n/pl/translations.json +5 -1
- package/admin/i18n/pt/translations.json +5 -1
- package/admin/i18n/ru/translations.json +5 -1
- package/admin/i18n/uk/translations.json +5 -1
- package/admin/i18n/zh-cn/translations.json +5 -1
- package/admin/jsonConfig.json +26 -2
- package/io-package.json +827 -847
- package/main.js +245 -226
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -342,7 +342,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
342
342
|
} else {
|
|
343
343
|
try {
|
|
344
344
|
// The object was deleted
|
|
345
|
-
this.log.
|
|
345
|
+
this.log.debug(`object ${id} deleted`);
|
|
346
346
|
|
|
347
347
|
// delete instance data in map
|
|
348
348
|
if (this.listInstanceRaw.has(id)) {
|
|
@@ -379,9 +379,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
379
379
|
let oldStatus;
|
|
380
380
|
let isLowBatValue;
|
|
381
381
|
let instanceStatusRaw;
|
|
382
|
-
let oldInstanceHostState;
|
|
383
|
-
let oldInstanceDeviceState;
|
|
384
382
|
let oldAdapterUpdatesCounts;
|
|
383
|
+
let oldIsHealthyValue;
|
|
385
384
|
|
|
386
385
|
try {
|
|
387
386
|
// adapter updates
|
|
@@ -404,74 +403,32 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
// instances
|
|
407
|
-
for (const [
|
|
406
|
+
for (const [instanceID, instanceData] of this.listInstanceRaw) {
|
|
408
407
|
switch (id) {
|
|
409
|
-
|
|
410
|
-
case
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
instanceData.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
await this.sendStateNotifications('deactivatedInstance', instance);
|
|
408
|
+
case `system.adapter.${instanceID}.alive`:
|
|
409
|
+
case `system.adapter.${instanceID}.connected`:
|
|
410
|
+
case `${instanceID}.info.connection`:
|
|
411
|
+
if (!instanceData.checkIsRunning) {
|
|
412
|
+
instanceData.checkIsRunning = true;
|
|
413
|
+
oldIsHealthyValue = instanceData.isHealthy;
|
|
414
|
+
instanceStatusRaw = await this.setInstanceStatus(instanceData.instanceMode, instanceData.schedule, instanceID);
|
|
415
|
+
instanceData.isAlive = instanceStatusRaw[0];
|
|
416
|
+
instanceData.isHealthy = instanceStatusRaw[1];
|
|
417
|
+
instanceData.status = instanceStatusRaw[2];
|
|
418
|
+
|
|
419
|
+
if (oldIsHealthyValue === instanceData.isHealthy) continue;
|
|
420
|
+
// send message when instance was deactivated
|
|
421
|
+
if (this.config.checkSendInstanceDeactivatedMsg && !instanceData.isAlive) {
|
|
422
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
423
|
+
await this.sendStateNotifications('deactivatedInstance', instanceID);
|
|
426
424
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
oldInstanceHostState = instanceData.isConnectedHost;
|
|
432
|
-
instanceData.isConnectedHost = state.val;
|
|
433
|
-
if (oldInstanceHostState !== instanceData.isConnectedHost) {
|
|
434
|
-
instanceStatusRaw = await this.setInstanceStatus(
|
|
435
|
-
instanceData.instanceMode,
|
|
436
|
-
instanceData.schedule,
|
|
437
|
-
instanceData.instanceAlivePath,
|
|
438
|
-
instanceData.connectedHostPath,
|
|
439
|
-
instanceData.connectedDevicePath,
|
|
440
|
-
);
|
|
441
|
-
instanceData.isAlive = instanceStatusRaw[1];
|
|
442
|
-
instanceData.status = instanceStatusRaw[0];
|
|
443
|
-
instanceData.isHealthy = instanceStatusRaw[2];
|
|
444
|
-
|
|
445
|
-
if (!instanceData.isAlive) continue;
|
|
446
|
-
if (this.config.checkSendInstanceFailedMsg && !this.blacklistInstancesNotify.includes(instanceData.instanceAlivePath)) {
|
|
447
|
-
if (!instanceData.isHealthy) {
|
|
448
|
-
await this.sendStateNotifications('errorInstance', instance);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
break;
|
|
453
|
-
// instance connected device
|
|
454
|
-
case instanceData.connectedDevicePath:
|
|
455
|
-
oldInstanceDeviceState = instanceData.isConnectedDevice;
|
|
456
|
-
instanceData.isConnectedDevice = state.val;
|
|
457
|
-
if (oldInstanceDeviceState !== instanceData.isConnectedDevice) {
|
|
458
|
-
instanceStatusRaw = await this.setInstanceStatus(
|
|
459
|
-
instanceData.instanceMode,
|
|
460
|
-
instanceData.schedule,
|
|
461
|
-
instanceData.instanceAlivePath,
|
|
462
|
-
instanceData.connectedHostPath,
|
|
463
|
-
instanceData.connectedDevicePath,
|
|
464
|
-
);
|
|
465
|
-
instanceData.isAlive = instanceStatusRaw[1];
|
|
466
|
-
instanceData.status = instanceStatusRaw[0];
|
|
467
|
-
instanceData.isHealthy = instanceStatusRaw[2];
|
|
468
|
-
|
|
469
|
-
if (!instanceData.isAlive) continue;
|
|
470
|
-
if (this.config.checkSendInstanceFailedMsg && !this.blacklistInstancesNotify.includes(instanceData.instanceAlivePath)) {
|
|
471
|
-
if (!instanceData.isHealthy) {
|
|
472
|
-
await this.sendStateNotifications('errorInstance', instance);
|
|
473
|
-
}
|
|
425
|
+
// send message when instance has an error
|
|
426
|
+
if (this.config.checkSendInstanceFailedMsg && instanceData.isAlive && !instanceData.isHealthy) {
|
|
427
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
428
|
+
await this.sendStateNotifications('errorInstance', instanceID);
|
|
474
429
|
}
|
|
430
|
+
|
|
431
|
+
instanceData.checkIsRunning = false;
|
|
475
432
|
}
|
|
476
433
|
break;
|
|
477
434
|
}
|
|
@@ -648,12 +605,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
648
605
|
case 'instancesList':
|
|
649
606
|
if (obj.message) {
|
|
650
607
|
try {
|
|
651
|
-
for (const instanceData of this.listInstanceRaw
|
|
652
|
-
const label = `${instanceData.Adapter}: ${
|
|
608
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
609
|
+
const label = `${instanceData.Adapter}: ${instance}`;
|
|
653
610
|
const valueObjectInstances = {
|
|
654
611
|
adapter: instanceData.Adapter,
|
|
655
|
-
|
|
656
|
-
path: instanceData.instanceAlivePath,
|
|
612
|
+
instanceID: instance,
|
|
657
613
|
};
|
|
658
614
|
instances[countInstances] = { label: label, value: JSON.stringify(valueObjectInstances) };
|
|
659
615
|
countInstances++;
|
|
@@ -673,12 +629,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
673
629
|
case 'instancesListTime':
|
|
674
630
|
if (obj.message) {
|
|
675
631
|
try {
|
|
676
|
-
for (const instanceData of this.listInstanceRaw
|
|
677
|
-
const label = `${instanceData.Adapter}: ${
|
|
632
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
633
|
+
const label = `${instanceData.Adapter}: ${instance}`;
|
|
678
634
|
const valueObjectInstances = {
|
|
679
635
|
adapter: instanceData.Adapter,
|
|
680
|
-
instanceName:
|
|
681
|
-
path: instanceData.instanceAlivePath,
|
|
636
|
+
instanceName: instance,
|
|
682
637
|
};
|
|
683
638
|
instancesTime[countInstances] = { label: label, value: JSON.stringify(valueObjectInstances) };
|
|
684
639
|
countInstances++;
|
|
@@ -820,11 +775,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
820
775
|
const blacklistParse = this.parseData(myBlacklistInstances[i].instances);
|
|
821
776
|
// push devices in list to ignor device in lists
|
|
822
777
|
if (myBlacklistInstances[i].checkIgnorLists) {
|
|
823
|
-
this.blacklistInstancesLists.push(blacklistParse.
|
|
778
|
+
this.blacklistInstancesLists.push(blacklistParse.instanceID);
|
|
824
779
|
}
|
|
825
780
|
// push devices in list to ignor device in notifications
|
|
826
781
|
if (myBlacklistInstances[i].checkIgnorNotify) {
|
|
827
|
-
this.blacklistInstancesNotify.push(blacklistParse.
|
|
782
|
+
this.blacklistInstancesNotify.push(blacklistParse.instanceID);
|
|
828
783
|
}
|
|
829
784
|
} catch (error) {
|
|
830
785
|
this.errorReporting('[createBlacklist]', error);
|
|
@@ -847,18 +802,15 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
847
802
|
try {
|
|
848
803
|
const userTimeListparse = this.parseData(userTimeListInstances[i].instancesTime);
|
|
849
804
|
// push devices in list to ignor device in lists
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
errorTime: userTimeListInstances[i].errorTime,
|
|
855
|
-
});
|
|
856
|
-
}
|
|
805
|
+
this.userTimeInstancesList.set(userTimeListparse.instanceName, {
|
|
806
|
+
deactivationTime: userTimeListInstances[i].deactivationTime,
|
|
807
|
+
errorTime: userTimeListInstances[i].errorTime,
|
|
808
|
+
});
|
|
857
809
|
} catch (error) {
|
|
858
810
|
this.errorReporting('[createTimeListInstances]', error);
|
|
859
811
|
}
|
|
860
812
|
}
|
|
861
|
-
if (this.userTimeInstancesList.size >= 1) this.log.info(`Found instances items on lists for timesettings: ${this.
|
|
813
|
+
if (this.userTimeInstancesList.size >= 1) this.log.info(`Found instances items on lists for timesettings: ${Array.from(this.userTimeInstancesList.keys())}`);
|
|
862
814
|
}
|
|
863
815
|
}
|
|
864
816
|
|
|
@@ -2038,14 +1990,14 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2038
1990
|
if (!(typeof id === 'string' && id.startsWith(`system.adapter.`))) continue;
|
|
2039
1991
|
|
|
2040
1992
|
// get instance name
|
|
2041
|
-
const
|
|
1993
|
+
const instanceID = await this.getInstanceName(id);
|
|
2042
1994
|
|
|
2043
1995
|
// get instance connected to host data
|
|
2044
|
-
const instanceConnectedHostDP = `system.adapter.${
|
|
1996
|
+
const instanceConnectedHostDP = `system.adapter.${instanceID}.connected`;
|
|
2045
1997
|
const instanceConnectedHostVal = await this.getInitValue(instanceConnectedHostDP);
|
|
2046
1998
|
|
|
2047
1999
|
// get instance connected to device data
|
|
2048
|
-
const instanceConnectedDeviceDP = `${
|
|
2000
|
+
const instanceConnectedDeviceDP = `${instanceID}.info.connection`;
|
|
2049
2001
|
let instanceConnectedDeviceVal;
|
|
2050
2002
|
if (instanceConnectedDeviceDP !== undefined && typeof instanceConnectedDeviceDP === 'boolean') {
|
|
2051
2003
|
instanceConnectedDeviceVal = await this.getInitValue(instanceConnectedDeviceDP);
|
|
@@ -2054,7 +2006,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2054
2006
|
}
|
|
2055
2007
|
|
|
2056
2008
|
// get adapter version
|
|
2057
|
-
const instanceObjectPath = `system.adapter.${
|
|
2009
|
+
const instanceObjectPath = `system.adapter.${instanceID}`;
|
|
2058
2010
|
let adapterName;
|
|
2059
2011
|
let adapterVersion;
|
|
2060
2012
|
let adapterAvailableUpdate = '';
|
|
@@ -2082,11 +2034,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2082
2034
|
adapterAvailableUpdate = ' - ';
|
|
2083
2035
|
}
|
|
2084
2036
|
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2037
|
+
let isAlive;
|
|
2038
|
+
let isHealthy;
|
|
2039
|
+
let instanceStatus;
|
|
2040
|
+
if (instanceMode === 'schedule') {
|
|
2041
|
+
const instanceStatusRaw = await this.checkScheduleisHealty(instanceID, scheduleTime);
|
|
2042
|
+
isAlive = instanceStatusRaw[0];
|
|
2043
|
+
isHealthy = instanceStatusRaw[1];
|
|
2044
|
+
instanceStatus = instanceStatusRaw[2];
|
|
2045
|
+
} else if (instanceMode === 'daemon') {
|
|
2046
|
+
const instanceStatusRaw = await this.checkDaemonIsHealthy(instanceID);
|
|
2047
|
+
isAlive = instanceStatusRaw[0];
|
|
2048
|
+
isHealthy = instanceStatusRaw[1];
|
|
2049
|
+
instanceStatus = instanceStatusRaw[2];
|
|
2050
|
+
}
|
|
2090
2051
|
|
|
2091
2052
|
//subscribe to statechanges
|
|
2092
2053
|
this.subscribeForeignStates(id);
|
|
@@ -2095,22 +2056,19 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2095
2056
|
this.subscribeForeignObjects(`system.adapter.*`);
|
|
2096
2057
|
|
|
2097
2058
|
// create raw list
|
|
2098
|
-
this.listInstanceRaw.set(
|
|
2059
|
+
this.listInstanceRaw.set(instanceID, {
|
|
2099
2060
|
Adapter: adapterName,
|
|
2100
|
-
InstanceName: instanceName,
|
|
2101
2061
|
instanceObjectPath: instanceObjectPath,
|
|
2102
|
-
instanceAlivePath: id,
|
|
2103
2062
|
instanceMode: instanceMode,
|
|
2104
2063
|
schedule: scheduleTime,
|
|
2105
2064
|
adapterVersion: adapterVersion,
|
|
2106
2065
|
updateAvailable: adapterAvailableUpdate,
|
|
2107
2066
|
isAlive: isAlive,
|
|
2108
2067
|
isHealthy: isHealthy,
|
|
2109
|
-
connectedHostPath: instanceConnectedHostDP,
|
|
2110
2068
|
isConnectedHost: instanceConnectedHostVal,
|
|
2111
|
-
connectedDevicePath: instanceConnectedDeviceDP,
|
|
2112
2069
|
isConnectedDevice: instanceConnectedDeviceVal,
|
|
2113
2070
|
status: instanceStatus,
|
|
2071
|
+
checkIsRunning: false,
|
|
2114
2072
|
});
|
|
2115
2073
|
}
|
|
2116
2074
|
await this.createInstanceList();
|
|
@@ -2132,136 +2090,197 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2132
2090
|
}
|
|
2133
2091
|
|
|
2134
2092
|
/**
|
|
2135
|
-
* Check if instance is alive
|
|
2136
|
-
* @param {
|
|
2137
|
-
* @param {number} instanceDeactivationTime
|
|
2093
|
+
* Check if instance is alive and ok
|
|
2094
|
+
* @param {string} instanceID
|
|
2138
2095
|
*/
|
|
2139
|
-
async
|
|
2140
|
-
|
|
2141
|
-
|
|
2096
|
+
async checkDaemonIsHealthy(instanceID) {
|
|
2097
|
+
const aliveState = await this.getInitValue(`system.adapter.${instanceID}.alive`);
|
|
2098
|
+
const connectedHostState = await this.getInitValue(`system.adapter.${instanceID}.connected`);
|
|
2099
|
+
let connectedDeviceState = await this.getInitValue(`${instanceID}.info.connection`);
|
|
2100
|
+
if (connectedDeviceState === undefined) connectedDeviceState = true;
|
|
2101
|
+
|
|
2102
|
+
let isAlive = false;
|
|
2103
|
+
let isHealthy = false;
|
|
2104
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2142
2105
|
|
|
2143
|
-
await this.delay(instanceDeactivationTime);
|
|
2144
|
-
aliveState = await this.getInitValue(instanceAlivePath);
|
|
2145
2106
|
if (!aliveState) {
|
|
2107
|
+
isAlive = false;
|
|
2108
|
+
isHealthy = false;
|
|
2109
|
+
instanceStatusString = 'Instanz deaktiviert';
|
|
2110
|
+
} else {
|
|
2111
|
+
if (connectedHostState && connectedDeviceState) {
|
|
2112
|
+
isAlive = true;
|
|
2113
|
+
isHealthy = true;
|
|
2114
|
+
instanceStatusString = 'Instanz okay';
|
|
2115
|
+
} else if (!connectedHostState) {
|
|
2116
|
+
isAlive = true;
|
|
2117
|
+
isHealthy = false;
|
|
2118
|
+
instanceStatusString = 'Nicht verbunden mit Host';
|
|
2119
|
+
} else if (!connectedDeviceState) {
|
|
2120
|
+
isAlive = true;
|
|
2121
|
+
isHealthy = false;
|
|
2122
|
+
instanceStatusString = 'Nicht verbunden mit Gerät oder Dienst';
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
/**
|
|
2130
|
+
* Check if instance is alive and ok
|
|
2131
|
+
* @param {string} instanceID
|
|
2132
|
+
* @param {number} instanceDeactivationTime
|
|
2133
|
+
*/
|
|
2134
|
+
async checkDaemonIsAlive(instanceID, instanceDeactivationTime) {
|
|
2135
|
+
const aliveState = await this.getInitValue(`system.adapter.${instanceID}.alive`);
|
|
2136
|
+
let daemonIsAlive;
|
|
2137
|
+
|
|
2138
|
+
let isAlive = false;
|
|
2139
|
+
let isHealthy = false;
|
|
2140
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2141
|
+
|
|
2142
|
+
if (aliveState) {
|
|
2143
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2144
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2145
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2146
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2147
|
+
} else if (!aliveState) {
|
|
2146
2148
|
await this.delay(instanceDeactivationTime);
|
|
2147
|
-
|
|
2148
|
-
if (!
|
|
2149
|
-
|
|
2149
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2150
|
+
if (!daemonIsAlive[0]) {
|
|
2151
|
+
await this.delay(instanceDeactivationTime);
|
|
2152
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2153
|
+
if (!daemonIsAlive[0]) {
|
|
2154
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2155
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2156
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2157
|
+
} else {
|
|
2158
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2159
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2160
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2161
|
+
}
|
|
2150
2162
|
} else {
|
|
2151
|
-
|
|
2163
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2164
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2165
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
async checkScheduleisHealty(instanceID, scheduleTime) {
|
|
2173
|
+
let lastUpdate;
|
|
2174
|
+
let previousCronRun = null;
|
|
2175
|
+
let lastCronRun;
|
|
2176
|
+
let diff;
|
|
2177
|
+
let isAlive = false;
|
|
2178
|
+
let isHealthy = false;
|
|
2179
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2180
|
+
|
|
2181
|
+
const isAliveSchedule = await this.getForeignStateAsync(`system.adapter.${instanceID}.alive`);
|
|
2182
|
+
|
|
2183
|
+
if (isAliveSchedule) {
|
|
2184
|
+
lastUpdate = Math.round((Date.now() - isAliveSchedule.lc) / 1000); // Last state change in seconds
|
|
2185
|
+
previousCronRun = this.getPreviousCronRun(scheduleTime); // When was the last cron run
|
|
2186
|
+
if (previousCronRun) {
|
|
2187
|
+
lastCronRun = Math.round(previousCronRun / 1000); // change distance to last run in seconds
|
|
2188
|
+
diff = lastCronRun - lastUpdate;
|
|
2189
|
+
if (diff > -300) {
|
|
2190
|
+
// if 5 minutes difference exceeded, instance is not alive
|
|
2191
|
+
isAlive = true;
|
|
2192
|
+
isHealthy = true;
|
|
2193
|
+
instanceStatusString = 'Instanz okay';
|
|
2194
|
+
}
|
|
2152
2195
|
}
|
|
2153
|
-
} else {
|
|
2154
|
-
return true;
|
|
2155
2196
|
}
|
|
2197
|
+
|
|
2198
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2156
2199
|
}
|
|
2157
2200
|
|
|
2158
2201
|
/**
|
|
2159
2202
|
* set status for instance
|
|
2160
2203
|
* @param {string} instanceMode
|
|
2161
2204
|
* @param {string} scheduleTime
|
|
2162
|
-
* @param {
|
|
2163
|
-
* @param {string} hostConnectedPath
|
|
2164
|
-
* @param {string} isDeviceConnctedPath
|
|
2205
|
+
* @param {any} instanceID
|
|
2165
2206
|
*/
|
|
2166
|
-
async setInstanceStatus(instanceMode, scheduleTime,
|
|
2167
|
-
|
|
2168
|
-
let
|
|
2169
|
-
let isDeviceConnected = await this.getInitValue(isDeviceConnctedPath);
|
|
2170
|
-
let instanceStatusString = 'Instance deactivated';
|
|
2171
|
-
let lastUpdate;
|
|
2172
|
-
let lastCronRun;
|
|
2173
|
-
let diff;
|
|
2174
|
-
let isAlive;
|
|
2175
|
-
let previousCronRun = null;
|
|
2207
|
+
async setInstanceStatus(instanceMode, scheduleTime, instanceID) {
|
|
2208
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2209
|
+
let isAlive = false;
|
|
2176
2210
|
let isHealthy = false;
|
|
2211
|
+
let scheduleIsAlive;
|
|
2212
|
+
let daemonIsAlive;
|
|
2213
|
+
let daemonIsNotAlive;
|
|
2177
2214
|
let instanceDeactivationTime = (this.config.offlineTimeInstances * 1000) / 2;
|
|
2178
2215
|
let instanceErrorTime = (this.config.errorTimeInstances * 1000) / 2;
|
|
2179
2216
|
|
|
2180
2217
|
switch (instanceMode) {
|
|
2181
2218
|
case 'schedule':
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
lastCronRun = Math.round(previousCronRun / 1000); // change distance to last run in seconds
|
|
2187
|
-
diff = lastCronRun - lastUpdate;
|
|
2188
|
-
if (diff > -300) {
|
|
2189
|
-
// if 5 minutes difference exceeded, instance is not alive
|
|
2190
|
-
isAlive = true;
|
|
2191
|
-
isHealthy = true;
|
|
2192
|
-
instanceStatusString = 'Instanz okay';
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2219
|
+
scheduleIsAlive = await this.checkScheduleisHealty(instanceID, scheduleTime);
|
|
2220
|
+
isAlive = Boolean(scheduleIsAlive[0]);
|
|
2221
|
+
isHealthy = Boolean(scheduleIsAlive[1]);
|
|
2222
|
+
instanceStatusString = String(scheduleIsAlive[2]);
|
|
2196
2223
|
break;
|
|
2197
2224
|
case 'daemon':
|
|
2198
|
-
|
|
2225
|
+
// check with time the user did define for error and deactivation
|
|
2226
|
+
if (this.userTimeInstancesList.has(instanceID)) {
|
|
2199
2227
|
// User set own setting for deactivation time
|
|
2200
|
-
instanceDeactivationTime = this.userTimeInstancesList.get(
|
|
2228
|
+
instanceDeactivationTime = this.userTimeInstancesList.get(instanceID).deactivationTime;
|
|
2201
2229
|
instanceDeactivationTime = (instanceDeactivationTime * 1000) / 2; // calculate sec to ms and divide into two
|
|
2202
2230
|
|
|
2203
2231
|
// User set own setting for error time
|
|
2204
|
-
instanceErrorTime = this.userTimeInstancesList.get(
|
|
2232
|
+
instanceErrorTime = this.userTimeInstancesList.get(instanceID).errorTime;
|
|
2205
2233
|
instanceErrorTime = (instanceErrorTime * 1000) / 2; // calculate sec to ms and divide into two
|
|
2206
2234
|
}
|
|
2207
2235
|
|
|
2208
|
-
|
|
2209
|
-
isAlive = await this.checkIsAlive(instanceAlivePath, instanceDeactivationTime);
|
|
2210
|
-
if (!isAlive) return ['Instanz deaktiviert', false, null]; // if instance is turned off
|
|
2211
|
-
|
|
2212
|
-
if (isDeviceConnected === undefined) isDeviceConnected = true;
|
|
2213
|
-
|
|
2214
|
-
// if instance has an error
|
|
2215
|
-
if (isHostConnected && isDeviceConnected) {
|
|
2216
|
-
// In case of (re)start, connection may take some time. We take 3 attempts.
|
|
2217
|
-
// Attempt 1/3 - immediately
|
|
2218
|
-
isHealthy = true;
|
|
2219
|
-
instanceStatusString = 'Instanz okay';
|
|
2220
|
-
} else {
|
|
2221
|
-
// 2/3 - after x seconds
|
|
2222
|
-
await this.delay(instanceErrorTime);
|
|
2223
|
-
|
|
2224
|
-
isAlive = await this.checkIsAlive(instanceAlivePath, instanceDeactivationTime);
|
|
2225
|
-
if (!isAlive) return ['Instanz deaktiviert', false, null]; // if instance is turned off
|
|
2236
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2226
2237
|
|
|
2227
|
-
|
|
2228
|
-
if (
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
if (
|
|
2233
|
-
|
|
2234
|
-
instanceStatusString = 'Instanz okay';
|
|
2235
|
-
} else {
|
|
2236
|
-
// 3/3 - after x seconds in total or user time setting
|
|
2238
|
+
if (daemonIsAlive[0]) {
|
|
2239
|
+
if (daemonIsAlive[1]) {
|
|
2240
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2241
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2242
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2243
|
+
} else if (daemonIsAlive[0] && !daemonIsAlive[1]) {
|
|
2244
|
+
// wait first time
|
|
2237
2245
|
await this.delay(instanceErrorTime);
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
instanceStatusString =
|
|
2253
|
-
isHealthy = false;
|
|
2254
|
-
} else if (!isHostConnected) {
|
|
2255
|
-
instanceStatusString = 'Nicht verbunden mit Host';
|
|
2256
|
-
isHealthy = false;
|
|
2246
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2247
|
+
if (daemonIsAlive[0] && !daemonIsAlive[1]) {
|
|
2248
|
+
// wait second time
|
|
2249
|
+
await this.delay(instanceErrorTime);
|
|
2250
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2251
|
+
if (daemonIsAlive[0] && !daemonIsAlive[1]) {
|
|
2252
|
+
// finally
|
|
2253
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2254
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2255
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2256
|
+
} else if (!daemonIsAlive[0]) {
|
|
2257
|
+
daemonIsNotAlive = await this.checkDaemonIsAlive(instanceID, instanceDeactivationTime);
|
|
2258
|
+
isAlive = Boolean(daemonIsNotAlive[0]);
|
|
2259
|
+
isHealthy = Boolean(daemonIsNotAlive[1]);
|
|
2260
|
+
instanceStatusString = String(daemonIsNotAlive[2]);
|
|
2257
2261
|
}
|
|
2262
|
+
} else if (!daemonIsAlive[0]) {
|
|
2263
|
+
daemonIsNotAlive = await this.checkDaemonIsAlive(instanceID, instanceDeactivationTime);
|
|
2264
|
+
isAlive = Boolean(daemonIsNotAlive[0]);
|
|
2265
|
+
isHealthy = Boolean(daemonIsNotAlive[1]);
|
|
2266
|
+
instanceStatusString = String(daemonIsNotAlive[2]);
|
|
2258
2267
|
}
|
|
2268
|
+
} else if (!daemonIsAlive[0]) {
|
|
2269
|
+
daemonIsNotAlive = await this.checkDaemonIsAlive(instanceID, instanceDeactivationTime);
|
|
2270
|
+
isAlive = Boolean(daemonIsNotAlive[0]);
|
|
2271
|
+
isHealthy = Boolean(daemonIsNotAlive[1]);
|
|
2272
|
+
instanceStatusString = String(daemonIsNotAlive[2]);
|
|
2259
2273
|
}
|
|
2274
|
+
} else if (!daemonIsAlive[0]) {
|
|
2275
|
+
daemonIsNotAlive = await this.checkDaemonIsAlive(instanceID, instanceDeactivationTime);
|
|
2276
|
+
isAlive = Boolean(daemonIsNotAlive[0]);
|
|
2277
|
+
isHealthy = Boolean(daemonIsNotAlive[1]);
|
|
2278
|
+
instanceStatusString = String(daemonIsNotAlive[2]);
|
|
2260
2279
|
}
|
|
2261
2280
|
break;
|
|
2262
2281
|
}
|
|
2263
2282
|
|
|
2264
|
-
return [
|
|
2283
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2265
2284
|
}
|
|
2266
2285
|
|
|
2267
2286
|
/**
|
|
@@ -2346,54 +2365,54 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2346
2365
|
this.listErrorInstanceRaw = [];
|
|
2347
2366
|
this.listErrorInstance = [];
|
|
2348
2367
|
|
|
2349
|
-
for (const instance of this.listInstanceRaw
|
|
2368
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
2350
2369
|
// fill raw list
|
|
2351
|
-
if (
|
|
2370
|
+
if (instanceData.isAlive && !instanceData.isHealthy) {
|
|
2352
2371
|
this.listErrorInstanceRaw.push({
|
|
2353
|
-
Adapter:
|
|
2354
|
-
Instance: instance
|
|
2355
|
-
Mode:
|
|
2356
|
-
Status:
|
|
2372
|
+
Adapter: instanceData.Adapter,
|
|
2373
|
+
Instance: instance,
|
|
2374
|
+
Mode: instanceData.instanceMode,
|
|
2375
|
+
Status: instanceData.status,
|
|
2357
2376
|
});
|
|
2358
2377
|
}
|
|
2359
2378
|
|
|
2360
|
-
if (this.blacklistInstancesLists.includes(instance
|
|
2379
|
+
if (this.blacklistInstancesLists.includes(instance)) continue;
|
|
2361
2380
|
// all instances
|
|
2362
2381
|
this.listAllInstances.push({
|
|
2363
|
-
Adapter:
|
|
2364
|
-
Instance: instance
|
|
2365
|
-
Mode:
|
|
2366
|
-
Schedule:
|
|
2367
|
-
Version:
|
|
2368
|
-
Updateable:
|
|
2369
|
-
Status:
|
|
2382
|
+
Adapter: instanceData.Adapter,
|
|
2383
|
+
Instance: instance,
|
|
2384
|
+
Mode: instanceData.instanceMode,
|
|
2385
|
+
Schedule: instanceData.schedule,
|
|
2386
|
+
Version: instanceData.adapterVersion,
|
|
2387
|
+
Updateable: instanceData.updateAvailable,
|
|
2388
|
+
Status: instanceData.status,
|
|
2370
2389
|
});
|
|
2371
2390
|
|
|
2372
|
-
if (!
|
|
2391
|
+
if (!instanceData.isAlive) {
|
|
2373
2392
|
// list with deactivated instances
|
|
2374
2393
|
this.listDeactivatedInstances.push({
|
|
2375
|
-
Adapter:
|
|
2376
|
-
Instance: instance
|
|
2377
|
-
Status:
|
|
2394
|
+
Adapter: instanceData.Adapter,
|
|
2395
|
+
Instance: instance,
|
|
2396
|
+
Status: instanceData.status,
|
|
2378
2397
|
});
|
|
2379
2398
|
} else {
|
|
2380
2399
|
// list with active instances
|
|
2381
2400
|
this.listAllActiveInstances.push({
|
|
2382
|
-
Adapter:
|
|
2383
|
-
Instance: instance
|
|
2384
|
-
Mode:
|
|
2385
|
-
Schedule:
|
|
2386
|
-
Status:
|
|
2401
|
+
Adapter: instanceData.Adapter,
|
|
2402
|
+
Instance: instance,
|
|
2403
|
+
Mode: instanceData.instanceMode,
|
|
2404
|
+
Schedule: instanceData.schedule,
|
|
2405
|
+
Status: instanceData.status,
|
|
2387
2406
|
});
|
|
2388
2407
|
}
|
|
2389
2408
|
|
|
2390
2409
|
// list with error instances
|
|
2391
|
-
if (
|
|
2410
|
+
if (instanceData.isAlive && !instanceData.isHealthy) {
|
|
2392
2411
|
this.listErrorInstance.push({
|
|
2393
|
-
Adapter:
|
|
2394
|
-
Instance: instance
|
|
2395
|
-
Mode:
|
|
2396
|
-
Status:
|
|
2412
|
+
Adapter: instanceData.Adapter,
|
|
2413
|
+
Instance: instance,
|
|
2414
|
+
Mode: instanceData.instanceMode,
|
|
2415
|
+
Status: instanceData.status,
|
|
2397
2416
|
});
|
|
2398
2417
|
}
|
|
2399
2418
|
}
|
|
@@ -2976,12 +2995,12 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2976
2995
|
break;
|
|
2977
2996
|
case 'errorInstance':
|
|
2978
2997
|
objectData = this.listInstanceRaw.get(id);
|
|
2979
|
-
message = `Instanz Watchdog:\n${
|
|
2998
|
+
message = `Instanz Watchdog:\n${id}: ${objectData.status}`;
|
|
2980
2999
|
setMessage(message);
|
|
2981
3000
|
break;
|
|
2982
3001
|
case 'deactivatedInstance':
|
|
2983
3002
|
objectData = this.listInstanceRaw.get(id);
|
|
2984
|
-
message = `Instanz Watchdog:\n${
|
|
3003
|
+
message = `Instanz Watchdog:\n${id}: ${objectData.status}`;
|
|
2985
3004
|
setMessage(message);
|
|
2986
3005
|
break;
|
|
2987
3006
|
}
|
|
@@ -3165,8 +3184,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
3165
3184
|
list = '';
|
|
3166
3185
|
|
|
3167
3186
|
for (const id of this.listErrorInstanceRaw) {
|
|
3168
|
-
if (this.blacklistInstancesNotify.includes(id
|
|
3169
|
-
list = `${list}\n${id
|
|
3187
|
+
if (this.blacklistInstancesNotify.includes(id)) continue;
|
|
3188
|
+
list = `${list}\n${id}: ${id.Status}`;
|
|
3170
3189
|
}
|
|
3171
3190
|
if (list.length === 0) return;
|
|
3172
3191
|
message = `Tägliche Meldung über fehlerhafte Instanzen: ${list}`;
|
|
@@ -3195,8 +3214,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
3195
3214
|
list = '';
|
|
3196
3215
|
|
|
3197
3216
|
for (const id of this.listDeactivatedInstances) {
|
|
3198
|
-
if (this.blacklistInstancesNotify.includes(id
|
|
3199
|
-
list = `${list}\n${id
|
|
3217
|
+
if (this.blacklistInstancesNotify.includes(id)) continue;
|
|
3218
|
+
list = `${list}\n${id}`;
|
|
3200
3219
|
}
|
|
3201
3220
|
if (list.length === 0) return;
|
|
3202
3221
|
message = `Tägliche Meldung über deaktivierte Instanzen: ${list}`;
|