Mikrotik widget (#720)

pull/731/head
Benoit SERRA 2 years ago committed by GitHub
parent 17e7d449b0
commit 38d81b654e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

5
.gitignore vendored

@ -41,3 +41,8 @@ next-env.d.ts
# homepage
/config
# IDEs
/.idea/

@ -206,7 +206,7 @@
"processed": "Processed",
"errored": "Errored",
"saved": "Saved"
},
},
"traefik": {
"routers": "Routers",
"services": "Services",
@ -395,5 +395,11 @@
"nextdns": {
"wait": "Please Wait",
"no_devices": "No Device Data Received"
},
"mikrotik": {
"cpuLoad": "CPU Load",
"memoryUsed": "Memory Used",
"uptime": "Uptime",
"numberOfLeases": "Leases"
}
}

@ -22,6 +22,7 @@ const components = {
lidarr: dynamic(() => import("./lidarr/component")),
mastodon: dynamic(() => import("./mastodon/component")),
miniflux: dynamic(() => import("./miniflux/component")),
mikrotik: dynamic(() => import("./mikrotik/component")),
navidrome: dynamic(() => import("./navidrome/component")),
nextdns: dynamic(() => import("./nextdns/component")),
npm: dynamic(() => import("./npm/component")),

@ -0,0 +1,43 @@
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");
const { data: leasesData, error: leasesError } = useWidgetAPI(widget, "leases");
if (statsError || leasesError) {
const finalError = statsError ?? leasesError;
return <Container error={ finalError } />;
}
if (!statsData || !leasesData) {
return (
<Container service={service}>
<Block label="mikrotik.uptime" />
<Block label="mikrotik.cpuLoad" />
<Block label="mikrotik.memoryUsed" />
<Block label="mikrotik.numberOfLeases" />
</Container>
);
}
const memoryUsed = 100 - (statsData['free-memory'] / statsData['total-memory'])*100
const numberOfLeases = leasesData.length
return (
<Container service={service}>
<Block label="mikrotik.uptime" value={ statsData.uptime } />
<Block label="mikrotik.cpuLoad" value={t("common.percent", { value: statsData['cpu-load'] })} />
<Block label="mikrotik.memoryUsed" value={t("common.percent", { value: memoryUsed })} />
<Block label="mikrotik.numberOfLeases" value={t("common.number", { value: numberOfLeases })} />
</Container>
);
}

@ -0,0 +1,24 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}/rest/{endpoint}",
proxyHandler: genericProxyHandler,
mappings: {
system: {
endpoint: "system/resource",
validate: [
"cpu-load",
"free-memory",
"total-memory",
"uptime"
]
},
leases: {
endpoint: "ip/dhcp-server/lease",
}
},
};
export default widget;

@ -17,6 +17,7 @@ import jellyseerr from "./jellyseerr/widget";
import lidarr from "./lidarr/widget";
import mastodon from "./mastodon/widget";
import miniflux from "./miniflux/widget";
import mikrotik from "./mikrotik/widget";
import navidrome from "./navidrome/widget";
import nextdns from "./nextdns/widget";
import npm from "./npm/widget";
@ -71,6 +72,7 @@ const widgets = {
lidarr,
mastodon,
miniflux,
mikrotik,
navidrome,
nextdns,
npm,

Loading…
Cancel
Save