Add healthcheck widget
This commit is contained in:
parent
0e2b474540
commit
5def5dd508
5 changed files with 87 additions and 0 deletions
|
@ -354,6 +354,16 @@
|
|||
"child_bridges": "Child Bridges",
|
||||
"child_bridges_status": "{{ok}}/{{total}}"
|
||||
},
|
||||
"healthchecks": {
|
||||
"new": "New",
|
||||
"up": "Online",
|
||||
"grace": "In Grace Period",
|
||||
"down": "Offline",
|
||||
"paused": "Paused",
|
||||
"status": "Status",
|
||||
"last_ping": "Last Ping",
|
||||
"never": "No pings yet"
|
||||
},
|
||||
"watchtower": {
|
||||
"containers_scanned": "Scanned",
|
||||
"containers_updated": "Updated",
|
||||
|
|
|
@ -21,6 +21,7 @@ const components = {
|
|||
grafana: dynamic(() => import("./grafana/component")),
|
||||
hdhomerun: dynamic(() => import("./hdhomerun/component")),
|
||||
homebridge: dynamic(() => import("./homebridge/component")),
|
||||
healthchecks: dynamic(() => import("./healthchecks/component")),
|
||||
jackett: dynamic(() => import("./jackett/component")),
|
||||
jellyfin: dynamic(() => import("./emby/component")),
|
||||
jellyseerr: dynamic(() => import("./jellyseerr/component")),
|
||||
|
|
56
src/widgets/healthchecks/component.jsx
Normal file
56
src/widgets/healthchecks/component.jsx
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Block from "components/services/widget/block";
|
||||
import Container from "components/services/widget/container";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
function formatDate(dateString) {
|
||||
const date = new Date(dateString);
|
||||
const now = new Date();
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const diff = (now - date) / 1000;
|
||||
|
||||
if (date > today && diff < 86400) {
|
||||
return date.toLocaleTimeString([], {
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
return date.toLocaleDateString([], {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
|
||||
const { data, error } = useWidgetAPI(widget, "checks");
|
||||
|
||||
if (error) {
|
||||
return <Container error={error} />;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label={t("healthchecks.status")} />
|
||||
<Block label={t("healthchecks.last_ping")} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label={t("healthchecks.status")} value={t(`healthchecks.${data.status}`)} />
|
||||
<Block
|
||||
label={t("healthchecks.last_ping")}
|
||||
value={data.last_ping ? formatDate(data.last_ping) : t("healthchecks.never")}
|
||||
/>
|
||||
</Container>
|
||||
);
|
||||
}
|
18
src/widgets/healthchecks/widget.js
Normal file
18
src/widgets/healthchecks/widget.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "https://healthchecks.io/api/v2/{endpoint}/{uuid}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
checks: {
|
||||
endpoint: "checks",
|
||||
validate: [
|
||||
"status",
|
||||
"last_ping",
|
||||
]
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -16,6 +16,7 @@ import gotify from "./gotify/widget";
|
|||
import grafana from "./grafana/widget";
|
||||
import hdhomerun from "./hdhomerun/widget";
|
||||
import homebridge from "./homebridge/widget";
|
||||
import healthchecks from "./healthchecks/widget";
|
||||
import jackett from "./jackett/widget";
|
||||
import jellyseerr from "./jellyseerr/widget";
|
||||
import komga from "./komga/widget";
|
||||
|
@ -87,6 +88,7 @@ const widgets = {
|
|||
grafana,
|
||||
hdhomerun,
|
||||
homebridge,
|
||||
healthchecks,
|
||||
jackett,
|
||||
jellyfin: emby,
|
||||
jellyseerr,
|
||||
|
|
Loading…
Add table
Reference in a new issue