diff --git a/docs/widgets/services/truenas.md b/docs/widgets/services/truenas.md index 243504905..8933f656e 100644 --- a/docs/widgets/services/truenas.md +++ b/docs/widgets/services/truenas.md @@ -11,6 +11,8 @@ To create an API Key, follow [the official TrueNAS documentation](https://www.tr A detailed pool listing is disabled by default, but can be enabled with the `enablePools` option. +The Scale and Core API's provide information on the pools in different manners. The `nasType` option choses which API response parsing should be used. + ```yaml widget: type: truenas @@ -19,4 +21,5 @@ widget: password: pass # not required if using api key key: yourtruenasapikey # not required if using username / password enablePools: true # optional, defaults to false + nasType: scale # defaults to scale, values are core or scale ``` diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index bee7db4e2..7634f41c8 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -448,6 +448,7 @@ export function cleanServiceGroups(groups) { // truenas enablePools, + nasType, // unifi site, @@ -520,6 +521,11 @@ export function cleanServiceGroups(groups) { } if (type === "truenas") { if (enablePools !== undefined) cleanedService.widget.enablePools = JSON.parse(enablePools); + if (nasType) { + cleanedService.widget.nasType = nasType; + } else { + cleanedService.widget.nasType = "scale"; + } } if (["diskstation", "qnap"].includes(type)) { if (volume) cleanedService.widget.volume = volume; diff --git a/src/widgets/truenas/component.jsx b/src/widgets/truenas/component.jsx index 872d8c647..119bb5081 100644 --- a/src/widgets/truenas/component.jsx +++ b/src/widgets/truenas/component.jsx @@ -3,7 +3,8 @@ import { useTranslation } from "next-i18next"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; -import Pool from "widgets/truenas/pool"; +import ScalePool from "widgets/truenas/scale-pool"; +import CorePool from "widgets/truenas/core-pool"; export default function Component({ service }) { const { t } = useTranslation(); @@ -30,6 +31,8 @@ export default function Component({ service }) { } const enablePools = widget?.enablePools && Array.isArray(poolsData) && poolsData.length > 0; + const scaleDeployment = widget?.nasType === "scale"; + const coreDeployment = widget?.nasType === "core"; return ( <> @@ -39,9 +42,19 @@ export default function Component({ service }) { {enablePools && + scaleDeployment && poolsData.map((pool) => ( - + ))} + {enablePools && + coreDeployment && + poolsData.map((pool) => )} ); } diff --git a/src/widgets/truenas/core-pool.jsx b/src/widgets/truenas/core-pool.jsx new file mode 100644 index 000000000..01bf7788f --- /dev/null +++ b/src/widgets/truenas/core-pool.jsx @@ -0,0 +1,37 @@ +import classNames from "classnames"; +import prettyBytes from "pretty-bytes"; + +export default function CorePool({ name, data, healthy }) { + let total = 0; + let allocated = 0; + for (let i = 0; i < data.length; i += 1) { + total += data[i].stats.size; + allocated += data[i].stats.allocated; + } + // const total = free + allocated; + const usedPercent = Math.round((allocated / total) * 100); + const statusColor = healthy ? "bg-green-500" : "bg-yellow-500"; + + return ( +
+
+ + + +
+
{name}
+
+
+ + {prettyBytes(allocated)} / {prettyBytes(total)} + + ({usedPercent}%) +
+
+ ); +} diff --git a/src/widgets/truenas/pool.jsx b/src/widgets/truenas/scale-pool.jsx similarity index 94% rename from src/widgets/truenas/pool.jsx rename to src/widgets/truenas/scale-pool.jsx index 8e9d04656..7aa59f206 100644 --- a/src/widgets/truenas/pool.jsx +++ b/src/widgets/truenas/scale-pool.jsx @@ -1,7 +1,7 @@ import classNames from "classnames"; import prettyBytes from "pretty-bytes"; -export default function Pool({ name, free, allocated, healthy }) { +export default function ScalePool({ name, free, allocated, healthy }) { const total = free + allocated; const usedPercent = Math.round((allocated / total) * 100); const statusColor = healthy ? "bg-green-500" : "bg-yellow-500"; diff --git a/src/widgets/truenas/widget.js b/src/widgets/truenas/widget.js index 7435b6e19..5f8a38df3 100644 --- a/src/widgets/truenas/widget.js +++ b/src/widgets/truenas/widget.js @@ -25,6 +25,7 @@ const widget = { healthy: entry.healthy, allocated: entry.allocated, free: entry.free, + data: entry.topology.data, })), }, },