First Version - Simple Up Status Widget
This commit is contained in:
parent
af2566c237
commit
b4680e4b8c
@ -469,6 +469,11 @@
|
||||
"incident": "Incident",
|
||||
"m": "m"
|
||||
},
|
||||
"uptimekumamonitor": {
|
||||
"up": "Up",
|
||||
"down": "Down",
|
||||
"maintenance": "Maintenance"
|
||||
},
|
||||
"komga": {
|
||||
"libraries": "Libraries",
|
||||
"series": "Series",
|
||||
|
||||
@ -74,6 +74,7 @@ const components = {
|
||||
unifi: dynamic(() => import("./unifi/component")),
|
||||
unmanic: dynamic(() => import("./unmanic/component")),
|
||||
uptimekuma: dynamic(() => import("./uptimekuma/component")),
|
||||
uptimekumamonitor: dynamic(() => import("./uptimekumamonitor/component")),
|
||||
watchtower: dynamic(() => import("./watchtower/component")),
|
||||
xteve: dynamic(() => import("./xteve/component")),
|
||||
};
|
||||
|
||||
31
src/widgets/uptimekumamonitor/component.jsx
Normal file
31
src/widgets/uptimekumamonitor/component.jsx
Normal file
@ -0,0 +1,31 @@
|
||||
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 { widget } = service;
|
||||
const { data: isUp} = useWidgetAPI(widget);
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
if (!isUp) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="Status"/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
var upIndicator;
|
||||
if (isUp.data.includes("Up")) {upIndicator = <span className="text-green-500">{t("uptimekumamonitor.up")}</span>}
|
||||
else if (isUp.data.includes("Maintenance")) {upIndicator = <span style={{color: '#1747f5'}}>{t("uptimekumamonitor.maintenance")}</span>}
|
||||
else if (isUp.data.includes("N/A")) {upIndicator = <span>{"N/A"}</span>}
|
||||
else {upIndicator = <span className="text-red-500">{t("uptimekumamonitor.down")}</span>}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="Status" value={upIndicator} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
28
src/widgets/uptimekumamonitor/proxy.js
Normal file
28
src/widgets/uptimekumamonitor/proxy.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("uptimekumamonitorProxyHandler");
|
||||
|
||||
export default async function uptimekumamonitorProxyHandler(req, res) {
|
||||
const { group, service } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
const widget = await getServiceWidget(group, service);
|
||||
if (!widget) {
|
||||
logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
const url = new URL(formatApiCall("{url}/api/badge/{monitor}/status", { ...widget }));
|
||||
const params = {
|
||||
method: "GET",
|
||||
body: null
|
||||
};
|
||||
const [status, contentType, data] = await httpProxy(url, params);
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(200).json({data: data.toString()});
|
||||
}
|
||||
7
src/widgets/uptimekumamonitor/widget.js
Normal file
7
src/widgets/uptimekumamonitor/widget.js
Normal file
@ -0,0 +1,7 @@
|
||||
import uptimekumamonitorProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
proxyHandler: uptimekumamonitorProxyHandler,
|
||||
}
|
||||
|
||||
export default widget;
|
||||
@ -68,6 +68,7 @@ import truenas from "./truenas/widget";
|
||||
import unifi from "./unifi/widget";
|
||||
import unmanic from "./unmanic/widget";
|
||||
import uptimekuma from "./uptimekuma/widget";
|
||||
import uptimekumamonitor from "./uptimekumamonitor/widget";
|
||||
import watchtower from "./watchtower/widget";
|
||||
import xteve from "./xteve/widget";
|
||||
|
||||
@ -144,6 +145,7 @@ const widgets = {
|
||||
unifi_console: unifi,
|
||||
unmanic,
|
||||
uptimekuma,
|
||||
uptimekumamonitor,
|
||||
watchtower,
|
||||
xteve,
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user