From 1a9445384962c3ff3f398cb81b3954f27c34a068 Mon Sep 17 00:00:00 2001 From: Niklas Date: Sun, 4 Dec 2022 19:33:15 +0100 Subject: [PATCH 1/5] Respect scrutiny device status threshold setting --- src/widgets/scrutiny/component.jsx | 43 ++++++++++++++++++++++++------ src/widgets/scrutiny/widget.js | 6 +++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/widgets/scrutiny/component.jsx b/src/widgets/scrutiny/component.jsx index 2e44d778..8bba3030 100644 --- a/src/widgets/scrutiny/component.jsx +++ b/src/widgets/scrutiny/component.jsx @@ -3,15 +3,39 @@ import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Component({ service }) { - const { widget } = service; - const { data: scrutinyData, error: scrutinyError } = useWidgetAPI(widget, "summary"); - - if (scrutinyError) { - return ; + // @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/shared/device-status.pipe.ts + const DeviceStatus = { + passed: 0, + failed_smart: 1, + failed_scrutiny: 2, + failed_both: 3 + } + + // @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts + const DeviceStatusThreshold = { + smart : 1, + scrutiny: 2, + both: 3 } - if (!scrutinyData) { + const thresholdStatusMapping = new Map([ + [DeviceStatusThreshold.smart, DeviceStatus.failed_smart], + [DeviceStatusThreshold.scrutiny, DeviceStatus.scrutiny], + [DeviceStatusThreshold.both, DeviceStatusThreshold.both] + ]) + + const { widget } = service; + + const { data: scrutinySettings, error: scrutinySettingsError } = useWidgetAPI(widget, "settings"); + const { data: scrutinyData, error: scrutinyError } = useWidgetAPI(widget, "summary"); + + if (scrutinyError || scrutinySettingsError) { + const finalError = scrutinyError ?? scrutinySettingsError; + return ; + } + + if (!scrutinyData || !scrutinySettings) { return ( @@ -22,10 +46,11 @@ export default function Component({ service }) { } const deviceIds = Object.values(scrutinyData.data.summary); + const statusThreshold = scrutinySettings.settings.metrics.status_threshold; + const failed = deviceIds.filter(deviceId => [thresholdStatusMapping.get(statusThreshold), DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0; + const unknown = deviceIds.filter(deviceId => deviceId.device.device_status < DeviceStatus.passed || deviceId.device.device_status > DeviceStatus.failed_both)?.length || 0; const passed = deviceIds.filter(deviceId => deviceId.device.device_status === 0)?.length || 0; - const failed = deviceIds.filter(deviceId => deviceId.device.device_status > 0 && deviceId.device.device_status <= 3)?.length || 0; - const unknown = deviceIds.length - (passed + failed) || 0; return ( @@ -35,3 +60,5 @@ export default function Component({ service }) { ); } + + diff --git a/src/widgets/scrutiny/widget.js b/src/widgets/scrutiny/widget.js index 8af7e04e..0d2e6b5c 100644 --- a/src/widgets/scrutiny/widget.js +++ b/src/widgets/scrutiny/widget.js @@ -11,6 +11,12 @@ const widget = { "data", ] }, + settings: { + endpoint: "settings", + validate: [ + "settings", + ] + } }, }; From 3f79a2fdda7a7d60d51a05e698924d5bfe66b119 Mon Sep 17 00:00:00 2001 From: Niklas Date: Sun, 4 Dec 2022 20:01:00 +0100 Subject: [PATCH 2/5] thresholdStatusMapping bugfix --- src/widgets/scrutiny/component.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/scrutiny/component.jsx b/src/widgets/scrutiny/component.jsx index 8bba3030..a9919c9d 100644 --- a/src/widgets/scrutiny/component.jsx +++ b/src/widgets/scrutiny/component.jsx @@ -21,8 +21,8 @@ export default function Component({ service }) { const thresholdStatusMapping = new Map([ [DeviceStatusThreshold.smart, DeviceStatus.failed_smart], - [DeviceStatusThreshold.scrutiny, DeviceStatus.scrutiny], - [DeviceStatusThreshold.both, DeviceStatusThreshold.both] + [DeviceStatusThreshold.scrutiny, DeviceStatus.failed_scrutiny], + [DeviceStatusThreshold.both, DeviceStatus.both] ]) const { widget } = service; From cbf72eedab97f82ed5c4aac7d0dceccb1d383818 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 4 Dec 2022 15:33:51 -0800 Subject: [PATCH 3/5] fix missing passing condition --- src/widgets/scrutiny/component.jsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/widgets/scrutiny/component.jsx b/src/widgets/scrutiny/component.jsx index a9919c9d..00ebe5ed 100644 --- a/src/widgets/scrutiny/component.jsx +++ b/src/widgets/scrutiny/component.jsx @@ -14,16 +14,10 @@ export default function Component({ service }) { // @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts const DeviceStatusThreshold = { - smart : 1, + smart: 1, scrutiny: 2, both: 3 } - - const thresholdStatusMapping = new Map([ - [DeviceStatusThreshold.smart, DeviceStatus.failed_smart], - [DeviceStatusThreshold.scrutiny, DeviceStatus.failed_scrutiny], - [DeviceStatusThreshold.both, DeviceStatus.both] - ]) const { widget } = service; @@ -48,9 +42,9 @@ export default function Component({ service }) { const deviceIds = Object.values(scrutinyData.data.summary); const statusThreshold = scrutinySettings.settings.metrics.status_threshold; - const failed = deviceIds.filter(deviceId => [thresholdStatusMapping.get(statusThreshold), DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0; + const failed = deviceIds.filter(deviceId => (deviceId.device.device_status > 0 && statusThreshold === DeviceStatusThreshold.both) || [statusThreshold, DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0; const unknown = deviceIds.filter(deviceId => deviceId.device.device_status < DeviceStatus.passed || deviceId.device.device_status > DeviceStatus.failed_both)?.length || 0; - const passed = deviceIds.filter(deviceId => deviceId.device.device_status === 0)?.length || 0; + const passed = deviceIds.filter(deviceId => deviceId.device.device_status === 0 || (deviceId.device.device_status > statusThreshold && deviceId.device.device_status < DeviceStatus.failed_both))?.length || 0; return ( From 90cb395dc6f9be7606efd0265f4a77b295694c8b Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 5 Dec 2022 08:01:24 +0100 Subject: [PATCH 4/5] change calculation of passed devices --- src/widgets/scrutiny/component.jsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/widgets/scrutiny/component.jsx b/src/widgets/scrutiny/component.jsx index 00ebe5ed..707a991f 100644 --- a/src/widgets/scrutiny/component.jsx +++ b/src/widgets/scrutiny/component.jsx @@ -9,7 +9,10 @@ export default function Component({ service }) { passed: 0, failed_smart: 1, failed_scrutiny: 2, - failed_both: 3 + failed_both: 3, + + isFailed: function ( s ) { return s > this.passed && s <= this.failed_both}, + isUnknown: function ( s ) { return s < this.passed || s > this.failed_both} } // @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts @@ -37,14 +40,14 @@ export default function Component({ service }) { ); - } + } const deviceIds = Object.values(scrutinyData.data.summary); const statusThreshold = scrutinySettings.settings.metrics.status_threshold; - - const failed = deviceIds.filter(deviceId => (deviceId.device.device_status > 0 && statusThreshold === DeviceStatusThreshold.both) || [statusThreshold, DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0; - const unknown = deviceIds.filter(deviceId => deviceId.device.device_status < DeviceStatus.passed || deviceId.device.device_status > DeviceStatus.failed_both)?.length || 0; - const passed = deviceIds.filter(deviceId => deviceId.device.device_status === 0 || (deviceId.device.device_status > statusThreshold && deviceId.device.device_status < DeviceStatus.failed_both))?.length || 0; + + const failed = deviceIds.filter(deviceId => (DeviceStatus.isFailed(deviceId.device.device_status) && statusThreshold === DeviceStatusThreshold.both) || [statusThreshold, DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0; + const unknown = deviceIds.filter(deviceId => DeviceStatus.isUnknown(deviceId.device.device_status))?.length || 0; + const passed = deviceIds.length - (failed + unknown); return ( @@ -52,7 +55,7 @@ export default function Component({ service }) { + ); -} - - + +} \ No newline at end of file From 0ce5311b5fb7f64d69d55894da345163175f8d6b Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 5 Dec 2022 08:13:41 +0100 Subject: [PATCH 5/5] fix lint errors --- src/widgets/scrutiny/component.jsx | 41 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/widgets/scrutiny/component.jsx b/src/widgets/scrutiny/component.jsx index 707a991f..0f769d9f 100644 --- a/src/widgets/scrutiny/component.jsx +++ b/src/widgets/scrutiny/component.jsx @@ -2,26 +2,26 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; + +// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/shared/device-status.pipe.ts +const DeviceStatus = { + passed: 0, + failed_smart: 1, + failed_scrutiny: 2, + failed_both: 3, + + isFailed(s){ return s > this.passed && s <= this.failed_both}, + isUnknown(s){ return s < this.passed || s > this.failed_both} +} + +// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts +const DeviceStatusThreshold = { + smart: 1, + scrutiny: 2, + both: 3 +} + export default function Component({ service }) { - - // @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/shared/device-status.pipe.ts - const DeviceStatus = { - passed: 0, - failed_smart: 1, - failed_scrutiny: 2, - failed_both: 3, - - isFailed: function ( s ) { return s > this.passed && s <= this.failed_both}, - isUnknown: function ( s ) { return s < this.passed || s > this.failed_both} - } - - // @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts - const DeviceStatusThreshold = { - smart: 1, - scrutiny: 2, - both: 3 - } - const { widget } = service; const { data: scrutinySettings, error: scrutinySettingsError } = useWidgetAPI(widget, "settings"); @@ -58,4 +58,5 @@ export default function Component({ service }) { ); -} \ No newline at end of file +} +