import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api, type CurrentUser, type IntegrationSummary, type UptimeKumaMonitor, type UptimeKumaMonitorsResponse } from "../api/client"; import { useSortable } from "../hooks/useSortable"; import SortableTh from "../components/SortableTh"; import { usePagination } from "../hooks/usePagination"; import Pagination from "../components/Pagination"; import { downloadCsv } from "../utils/csv"; import { readableError } from "../utils/errors"; import IntegrationPageTitle from "../components/IntegrationPageTitle"; import { ErrorNotice } from "../components/Notice"; import { SearchBox } from "../components/TableToolbar"; import { useTableSearch } from "../hooks/useTableSearch"; import DetailDrawer, { ObjectDetails } from "../components/DetailDrawer"; import { useRowDetail } from "../hooks/useRowDetail"; import { EmptyRow } from "../components/EmptyState"; import { t } from "../i18n"; function statusBadge(monitor: UptimeKumaMonitor) { switch (monitor.status) { case "up": return {t("Up")}; case "down": return {t("Down")}; case "pending": return {t("Pending")}; case "maintenance": return {t("Maintenance")}; default: return {t("Unknown")}; } } function formatPercent(v: number | null): string { return v === null ? "—" : `${v}%`; } function formatMs(v: number | null): string { if (v === null || v < 0) return "—"; return `${Math.round(v)} ms`; } export default function UptimeKuma({ user: _user }: { user: CurrentUser }) { const [integrations, setIntegrations] = useState(null); const [selectedId, setSelectedId] = useState(null); const [error, setError] = useState(null); const [data, setData] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { api.integrations .list() .then((res) => { const kumaIntegrations = res.integrations.filter((i) => i.type === "uptimekuma"); setIntegrations(kumaIntegrations); if (!selectedId && kumaIntegrations.length > 0) setSelectedId(kumaIntegrations[0].id); }) .catch((err) => setError(readableError(err))); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const selected = integrations?.find((i) => i.id === selectedId) ?? null; function loadMonitors(id: number) { setLoading(true); setError(null); api.integrations.uptimekuma .monitors(id) .then(setData) .catch((err) => setError(readableError(err))) .finally(() => setLoading(false)); } useEffect(() => { if (selected?.enabled) { loadMonitors(selected.id); } else { setData(null); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedId]); const tableSearch = useTableSearch(data?.monitors); const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "name", "asc", { url: true }); const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted); const detail = useRowDetail[number]>(); function exportCsv() { if (!sorted) return; downloadCsv( "uptime-kuma-monitors.csv", ["Monitor", "Type", "Target", "Status", "Response (ms)", "Uptime 24h", "Uptime 30d", "Cert days left", "Server"], sorted.map((m) => [ m.name, m.type, m.target ? `${m.target}${m.port ? `:${m.port}` : ""}` : "", m.status, m.responseTimeMs !== null && m.responseTimeMs >= 0 ? Math.round(m.responseTimeMs) : "", m.uptime24h ?? "", m.uptime30d ?? "", m.certDaysRemaining ?? "", m.matchedServer?.name ?? "", ]), ); } return ( <> {integrations?.length === 0 ? (
No Uptime Kuma integration configured yet. {t("Add one under Integrations")}.
) : ( <> {integrations && integrations.length > 1 && (
)} {selected && !selected.enabled ? (
"{selected.name}" is disabled. Enable it under Integrations → Manage integrations to see its monitors.
) : (

Monitors {data && data.summary.down > 0 && {data.summary.down} down} {data && data.summary.down === 0 && data.summary.pending > 0 && ( {data.summary.pending} pending )}

label={t("Monitor")} sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label={t("Target")} sortKeyName="target" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label={t("Status")} sortKeyName="status" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label={t("Response")} sortKeyName="responseTimeMs" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label={t("Uptime 24h")} sortKeyName="uptime24h" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label={t("Uptime 30d")} sortKeyName="uptime30d" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> {pageItems?.map((m) => ( ))} {sorted?.length === 0 && ( tableSearch.setQuery("") : undefined} /> )}
{t("Server")}
{m.name}
{m.type}
{m.target ? `${m.target}${m.port ? `:${m.port}` : ""}` : "—"} {m.certDaysRemaining !== null && (
cert: {m.certDaysRemaining}d left
)}
{m.matchedServer ? ( {m.matchedServer.name} ) : ( — )} {statusBadge(m)} {formatMs(m.responseTimeMs)} {formatPercent(m.uptime24h)} {formatPercent(m.uptime30d)}
"Server" links a monitor to one of your servers when its target (an IP, or a TCP/HTTP hostname) matches a server's own address or hostname — monitors of other kinds (groups, pushes, keyword/DNS checks without a plain host) are left unmatched rather than guessed at.
)} )} {detail.selected && ( m.name)(detail.selected)} subtitle={((m) => m.type)(detail.selected)} onClose={detail.close}> )} ); }