diff --git a/public/locales/en/common.json b/public/locales/en/common.json index ba88d14c..c53252be 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -469,6 +469,11 @@ "incident": "Incident", "m": "m" }, + "uptimekumamonitor": { + "up": "Up", + "down": "Down", + "maintenance": "Maintenance" + }, "komga": { "libraries": "Libraries", "series": "Series", diff --git a/src/widgets/components.js b/src/widgets/components.js index 0252f945..ef16ef4a 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -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")), }; diff --git a/src/widgets/uptimekumamonitor/component.jsx b/src/widgets/uptimekumamonitor/component.jsx new file mode 100644 index 00000000..23db4017 --- /dev/null +++ b/src/widgets/uptimekumamonitor/component.jsx @@ -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 ( + + + + ); + } + var upIndicator; + if (isUp.data.includes("Up")) {upIndicator = {t("uptimekumamonitor.up")}} + else if (isUp.data.includes("Maintenance")) {upIndicator = {t("uptimekumamonitor.maintenance")}} + else if (isUp.data.includes("N/A")) {upIndicator = {"N/A"}} + else {upIndicator = {t("uptimekumamonitor.down")}} + + return ( + + + + ); +} \ No newline at end of file diff --git a/src/widgets/uptimekumamonitor/proxy.js b/src/widgets/uptimekumamonitor/proxy.js new file mode 100644 index 00000000..39e12a84 --- /dev/null +++ b/src/widgets/uptimekumamonitor/proxy.js @@ -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()}); +} diff --git a/src/widgets/uptimekumamonitor/widget.js b/src/widgets/uptimekumamonitor/widget.js new file mode 100644 index 00000000..0f6c76b1 --- /dev/null +++ b/src/widgets/uptimekumamonitor/widget.js @@ -0,0 +1,7 @@ +import uptimekumamonitorProxyHandler from "./proxy"; + +const widget = { + proxyHandler: uptimekumamonitorProxyHandler, +} + +export default widget; \ No newline at end of file diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index c3f6f586..731b0b06 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -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, };