Merge pull request #1023 from rommelkott/main

Add Health checks widget
pull/1031/head
shamoon 2 years ago committed by GitHub
commit 893c443f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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")),

@ -0,0 +1,54 @@
import { useTranslation } from "next-i18next";
import { i18n } from "../../../next-i18next.config";
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();
let dateOptions = {
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
};
if (date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()) {
dateOptions = { timeStyle: "short" };
}
return new Intl.DateTimeFormat(i18n.language, dateOptions).format(date);
}
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>
);
}

@ -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…
Cancel
Save