Mikrotik widget : first minimal working widget
This commit is contained in:
parent
ccba3d87b0
commit
9ae58250f9
4
.gitignore
vendored
4
.gitignore
vendored
@ -41,3 +41,7 @@ next-env.d.ts
|
|||||||
|
|
||||||
# homepage
|
# homepage
|
||||||
/config
|
/config
|
||||||
|
|
||||||
|
/.idea/
|
||||||
|
|
||||||
|
/config/
|
||||||
|
|||||||
@ -388,5 +388,10 @@
|
|||||||
"nextdns": {
|
"nextdns": {
|
||||||
"wait": "Please Wait",
|
"wait": "Please Wait",
|
||||||
"no_devices": "No Device Data Received"
|
"no_devices": "No Device Data Received"
|
||||||
|
},
|
||||||
|
"mikrotik": {
|
||||||
|
"cpuload": "CPU Load",
|
||||||
|
"memoryused": "Memory Used",
|
||||||
|
"uptime": "Uptime"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ const components = {
|
|||||||
lidarr: dynamic(() => import("./lidarr/component")),
|
lidarr: dynamic(() => import("./lidarr/component")),
|
||||||
mastodon: dynamic(() => import("./mastodon/component")),
|
mastodon: dynamic(() => import("./mastodon/component")),
|
||||||
miniflux: dynamic(() => import("./miniflux/component")),
|
miniflux: dynamic(() => import("./miniflux/component")),
|
||||||
|
mikrotik: dynamic(() => import("./mikrotik/component")),
|
||||||
navidrome: dynamic(() => import("./navidrome/component")),
|
navidrome: dynamic(() => import("./navidrome/component")),
|
||||||
nextdns: dynamic(() => import("./nextdns/component")),
|
nextdns: dynamic(() => import("./nextdns/component")),
|
||||||
npm: dynamic(() => import("./npm/component")),
|
npm: dynamic(() => import("./npm/component")),
|
||||||
|
|||||||
38
src/widgets/mikrotik/component.jsx
Normal file
38
src/widgets/mikrotik/component.jsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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, "system");
|
||||||
|
|
||||||
|
if (statsError) {
|
||||||
|
return <Container error={statsError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!statsData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="mikrotik.uptime" />
|
||||||
|
<Block label="mikrotik.cpuload" />
|
||||||
|
<Block label="mikrotik.memoryused" />
|
||||||
|
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const memoryused = 100 - (statsData['free-memory'] / statsData['total-memory'])*100
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="mikrotik.uptime" value={ statsData.uptime } />
|
||||||
|
<Block label="mikrotik.cpuload" value={t("common.number", { value: statsData['cpu-load'] })} />
|
||||||
|
<Block label="mikrotik.memoryused" value={t("common.percent", { value: memoryused })} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
15
src/widgets/mikrotik/widget.js
Normal file
15
src/widgets/mikrotik/widget.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/rest/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
system: {
|
||||||
|
endpoint: "system/resource",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
||||||
@ -17,6 +17,7 @@ import jellyseerr from "./jellyseerr/widget";
|
|||||||
import lidarr from "./lidarr/widget";
|
import lidarr from "./lidarr/widget";
|
||||||
import mastodon from "./mastodon/widget";
|
import mastodon from "./mastodon/widget";
|
||||||
import miniflux from "./miniflux/widget";
|
import miniflux from "./miniflux/widget";
|
||||||
|
import mikrotik from "./mikrotik/widget";
|
||||||
import navidrome from "./navidrome/widget";
|
import navidrome from "./navidrome/widget";
|
||||||
import nextdns from "./nextdns/widget";
|
import nextdns from "./nextdns/widget";
|
||||||
import npm from "./npm/widget";
|
import npm from "./npm/widget";
|
||||||
@ -69,6 +70,7 @@ const widgets = {
|
|||||||
lidarr,
|
lidarr,
|
||||||
mastodon,
|
mastodon,
|
||||||
miniflux,
|
miniflux,
|
||||||
|
mikrotik,
|
||||||
navidrome,
|
navidrome,
|
||||||
nextdns,
|
nextdns,
|
||||||
npm,
|
npm,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user