Add widget for Truenas

pull/451/head
Dimitar Ilkov 2 years ago
parent 6d46647fc9
commit 3483fe1188

@ -292,5 +292,10 @@
"up_to_date": "Up to Date", "up_to_date": "Up to Date",
"child_bridges": "Child Bridges", "child_bridges": "Child Bridges",
"child_bridges_status": "{{ok}}/{{total}}" "child_bridges_status": "{{ok}}/{{total}}"
},
"truenas": {
"load": "System Load",
"uptime": "Uptime",
"alerts": "Alerts"
} }
} }

@ -35,6 +35,7 @@ const components = {
tautulli: dynamic(() => import("./tautulli/component")), tautulli: dynamic(() => import("./tautulli/component")),
traefik: dynamic(() => import("./traefik/component")), traefik: dynamic(() => import("./traefik/component")),
transmission: dynamic(() => import("./transmission/component")), transmission: dynamic(() => import("./transmission/component")),
truenas: dynamic(() => import("./truenas/component")),
unifi: dynamic(() => import("./unifi/component")), unifi: dynamic(() => import("./unifi/component")),
}; };

@ -0,0 +1,37 @@
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";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: alertData, error: alertError } = useWidgetAPI(widget, "alerts");
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
if (alertError || statusError) {
return <Container error={t("widget.api_error")} />;
}
if (!alertData || !statusData) {
return (
<Container service={service}>
<Block label="truenas.load" />
<Block label="truenas.uptime" />
<Block label="truenas.alerts" />
</Container>
);
}
return (
<Container service={service}>
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
<Block label="truenas.uptime" value={statusData.uptime.substring(0,statusData.uptime.length-7)} />
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
</Container>
);
}

@ -0,0 +1,21 @@
import { jsonArrayFilter } from "utils/proxy/api-helpers";
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}/api/v2.0/{endpoint}",
proxyHandler: genericProxyHandler,
mappings: {
alerts: {
endpoint: "alert/list",
map: (data) => ({
pending: jsonArrayFilter(data, (item) => item?.dismissed === false).length,
}),
},
status: {
endpoint: "system/info",
},
},
};
export default widget;

@ -30,6 +30,7 @@ import strelaysrv from "./strelaysrv/widget";
import tautulli from "./tautulli/widget"; import tautulli from "./tautulli/widget";
import traefik from "./traefik/widget"; import traefik from "./traefik/widget";
import transmission from "./transmission/widget"; import transmission from "./transmission/widget";
import truenas from "./truenas/widget";
import unifi from "./unifi/widget"; import unifi from "./unifi/widget";
const widgets = { const widgets = {
@ -66,6 +67,7 @@ const widgets = {
tautulli, tautulli,
traefik, traefik,
transmission, transmission,
truenas,
unifi, unifi,
unifi_console: unifi, unifi_console: unifi,
}; };

Loading…
Cancel
Save