Add UniFI console service widget
This commit is contained in:
parent
ad1d1e751d
commit
e03822df6e
3 changed files with 61 additions and 0 deletions
|
@ -36,6 +36,10 @@
|
|||
"uptime": "System Uptime",
|
||||
"days": "Days",
|
||||
"wan": "WAN",
|
||||
"lan": "LAN",
|
||||
"wlan": "WLAN",
|
||||
"up": "UP",
|
||||
"down": "DOWN",
|
||||
"wait": "Please wait"
|
||||
},
|
||||
"docker": {
|
||||
|
|
|
@ -32,6 +32,7 @@ const components = {
|
|||
tautulli: dynamic(() => import("./tautulli/component")),
|
||||
traefik: dynamic(() => import("./traefik/component")),
|
||||
transmission: dynamic(() => import("./transmission/component")),
|
||||
unifi_console: dynamic(() => import("./unifi/component")),
|
||||
};
|
||||
|
||||
export default components;
|
||||
|
|
56
src/widgets/unifi/component.jsx
Normal file
56
src/widgets/unifi/component.jsx
Normal file
|
@ -0,0 +1,56 @@
|
|||
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: statsData, error: statsError } = useWidgetAPI(widget, "stat/sites");
|
||||
|
||||
if (statsError || statsData?.error) {
|
||||
return <Container error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
const defaultSite = statsData?.data?.find(s => s.name === "default");
|
||||
|
||||
if (!defaultSite) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="unifi.uptime" />
|
||||
<Block label="unifi.wan" />
|
||||
<Block label="unifi.lan" />
|
||||
<Block label="unifi.wlan" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const wan = defaultSite.health.find(h => h.subsystem === "wan");
|
||||
const lan = defaultSite.health.find(h => h.subsystem === "lan");
|
||||
const wlan = defaultSite.health.find(h => h.subsystem === "wlan");
|
||||
const data = {
|
||||
name: wan.gw_name,
|
||||
uptime: wan["gw_system-stats"].uptime,
|
||||
up: wan.status === 'ok',
|
||||
wlan: {
|
||||
users: wlan.num_user,
|
||||
status: wlan.status
|
||||
},
|
||||
lan: {
|
||||
users: lan.num_user,
|
||||
status: lan.status
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="unifi.uptime" value={t("common.number", { value: data.uptime / 86400, maximumFractionDigits: 1 }) + " " + t("unifi.days")} />
|
||||
<Block label="unifi.wan" value={ data.up ? t("unifi.up") : t("unifi.down") } />
|
||||
<Block label="unifi.lan" value={t("common.number", { value: data.lan.users }) + " " + t("unifi.users")} />
|
||||
<Block label="unifi.wlan" value={t("common.number", { value: data.wlan.users }) + " " + t("unifi.users")} />
|
||||
</Container>
|
||||
);
|
||||
}
|
Loading…
Add table
Reference in a new issue