mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-02 21:43:39 +01:00
Respect scrutiny device status threshold setting
This commit is contained in:
parent
6045e53207
commit
1a94453849
@ -3,15 +3,39 @@ import Block from "components/services/widget/block";
|
|||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
const { widget } = service;
|
|
||||||
|
|
||||||
const { data: scrutinyData, error: scrutinyError } = useWidgetAPI(widget, "summary");
|
// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/shared/device-status.pipe.ts
|
||||||
|
const DeviceStatus = {
|
||||||
if (scrutinyError) {
|
passed: 0,
|
||||||
return <Container error={scrutinyError} />;
|
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 <Container error={finalError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scrutinyData || !scrutinySettings) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="scrutiny.passed" />
|
<Block label="scrutiny.passed" />
|
||||||
@ -22,10 +46,11 @@ export default function Component({ service }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deviceIds = Object.values(scrutinyData.data.summary);
|
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 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 (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
@ -35,3 +60,5 @@ export default function Component({ service }) {
|
|||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,12 @@ const widget = {
|
|||||||
"data",
|
"data",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
settings: {
|
||||||
|
endpoint: "settings",
|
||||||
|
validate: [
|
||||||
|
"settings",
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user