Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: incident screenshot (#747)
Maximilian Kaske5a2f14c3925c
diff --git a/apps/web/next.config.js b/apps/web/next.config.jsindex 7d6de6596..c02db0b34 100644--- a/apps/web/next.config.js+++ b/apps/web/next.config.js@@ -27,6 +27,10 @@ const nextConfig = {protocol: "https",hostname: "**.public.blob.vercel-storage.com",},+ {+ protocol: "https",+ hostname: "screenshot.openstat.us",+ },],},};diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/layout.tsxindex c54ed93b1..b395205eb 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/layout.tsx@@ -1,5 +1,6 @@import { notFound } from "next/navigation";+import { Header } from "@/components/dashboard/header";import AppPageWithSidebarLayout from "@/components/layout/app-page-with-sidebar-layout";import { api } from "@/trpc/server";@@ -12,16 +13,20 @@ export default async function Layout({}) {const id = params.id;- const monitor = await api.incident.getIncidentById.query({+ const incidents = await api.incident.getIncidentsByWorkspace.query();+ const incident = await api.incident.getIncidentById.query({id: Number(id),});- if (!monitor) {+ if (!incident) {return notFound();}+ const incidentIndex = incidents.findIndex((item) => item.id === incident.id);+return (<AppPageWithSidebarLayout id="incidents">+ <Header title={`Incident #${incidentIndex + 1}`} />{children}</AppPageWithSidebarLayout>);diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/overview/_components/event.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/overview/_components/event.tsxnew file mode 100644index 000000000..d73c7bdaf--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/overview/_components/event.tsx@@ -0,0 +1,38 @@+import * as React from "react";+import { format } from "date-fns";++import type { ValidIcon } from "@/components/icons";+import { Icons } from "@/components/icons";++export function Event({+ label,+ date,+ icon,+ children,+}: {+ label: string;+ date: Date;+ icon: ValidIcon;+ children?: React.ReactNode;+}) {+ const Icon = Icons[icon];+ return (+ <div className="group relative -m-2 flex gap-4 border border-transparent p-2">+ <div className="relative">+ <div className="bg-background rounded-full border p-2">+ <Icon className="h-4 w-4" />+ </div>+ <div className="bg-muted absolute inset-x-0 mx-auto h-full w-[2px]" />+ </div>+ <div className="mt-1 flex flex-1 flex-col gap-1">+ <div className="flex items-center justify-between gap-4">+ <p className="text-sm font-semibold">{label}</p>+ <p className="text-muted-foreground mt-px text-right text-[10px]">+ <code>{format(new Date(date), "LLL dd, y HH:mm:ss")}</code>+ </p>+ </div>+ {children}+ </div>+ </div>+ );+}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/overview/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/overview/page.tsxnew file mode 100644index 000000000..4ed9f051a--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/overview/page.tsx@@ -0,0 +1,114 @@+import Image from "next/image";+import Link from "next/link";+import { formatDistanceStrict } from "date-fns";+import { ArrowUpRight } from "lucide-react";++import { api } from "@/trpc/server";+import { Event } from "./_components/event";++/**+ * MetricCards (Like: Duration, Monitor Name, Autoresolved,...)+ *+ * Start Date + (can we include the response details?)+ * Screenshot+ * Acknowledged+ * Resolved+ *+ */++export default async function IncidentPage({+ params,+}: {+ params: { workspaceSlug: string; id: string };+}) {+ const incident = await api.incident.getIncidentById.query({+ id: Number(params.id),+ });++ const duration = formatDistanceStrict(+ new Date(incident.startedAt),+ incident?.resolvedAt ? new Date(incident.resolvedAt) : new Date(),+ );++ return (+ <div className="grid gap-6">+ <div className="grid grid-cols-2 gap-4 sm:grid-cols-4 md:gap-6">+ <div className="flex flex-col gap-2 rounded-lg border px-3 py-2">+ <p className="text-muted-foreground text-sm font-light uppercase">+ Monitor+ </p>+ <div className="flex flex-row items-end gap-2">+ <p className="text-xl font-semibold">{incident.monitorName}</p>+ <Link+ href={`/app/${params.workspaceSlug}/monitors/${incident.monitorId}/overview`}+ className="text-muted-foreground hover:text-foreground"+ >+ <ArrowUpRight />+ </Link>+ </div>+ </div>+ <div className="flex flex-col gap-2 rounded-lg border px-3 py-2">+ <p className="text-muted-foreground text-sm font-light uppercase">+ Duration+ </p>+ <p className="text-xl font-semibold">{duration}</p>+ </div>+ <div className="flex flex-col gap-2 rounded-lg border px-3 py-2">+ <p className="text-muted-foreground text-sm font-light uppercase">+ Auto-resolved+ </p>+ <p className="font-mono text-xl font-semibold">+ {incident.autoResolved ? "true" : "false"}+ </p>+ </div>+ </div>+ <div className="max-w-xl">+ <Event label="Started" icon="alert-triangle" date={incident.startedAt}>+ {incident.incidentScreenshotUrl ? (+ <div className="border-border bg-background relative h-64 w-full overflow-hidden rounded-xl border">+ <a+ href={incident.incidentScreenshotUrl}+ target="_blank"+ rel="noreferrer"+ >+ <Image+ src={incident.incidentScreenshotUrl}+ fill={true}+ alt="incident screenshot"+ className="object-contain"+ />+ </a>+ </div>+ ) : null}+ </Event>+ {incident?.acknowledgedAt ? (+ <Event+ label="Acknowledged"+ icon="eye"+ date={incident.acknowledgedAt}+ />+ ) : null}+ {incident?.resolvedAt ? (+ <Event label="Resolved" icon="check" date={incident.resolvedAt}>+ {incident.recoveryScreenshotUrl ? (+ <div className="border-border bg-background relative h-64 w-full overflow-hidden rounded-xl border">+ <a+ href={incident.recoveryScreenshotUrl}+ target="_blank"+ rel="noreferrer"+ >+ <Image+ src={incident.recoveryScreenshotUrl}+ fill={true}+ alt="recovery screenshot"+ className="object-contain"+ />+ </a>+ </div>+ ) : null}+ </Event>+ ) : null}+ </div>+ </div>+ );+}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/page.tsxindex cf2eed2f8..2265f50db 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/page.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/incidents/[id]/page.tsx@@ -1,3 +1,9 @@-export default async function IncidentPage() {- return <></>;+import { redirect } from "next/navigation";++export default function Page({+ params,+}: {+ params: { workspaceSlug: string; id: string };+}) {+ return redirect(`./${params.id}/overview`);}diff --git a/apps/web/src/components/data-table/incident/columns.tsx b/apps/web/src/components/data-table/incident/columns.tsxindex 4e44f8eec..72d3b956a 100644--- a/apps/web/src/components/data-table/incident/columns.tsx+++ b/apps/web/src/components/data-table/incident/columns.tsx@@ -1,5 +1,6 @@"use client";+import Image from "next/image";import Link from "next/link";import type { ColumnDef } from "@tanstack/react-table";import { formatDistanceStrict } from "date-fns";@@ -30,13 +31,27 @@ export const columns: ColumnDef<Incident>[] = [accessorKey: "startedAt",header: "Started At",cell: ({ row }) => {- const { startedAt } = row.original;+ const { startedAt, incidentScreenshotUrl } = row.original;const date = startedAt ? formatDateTime(startedAt) : "-";return (- <div className="flex">+ <div className="flex gap-2"><span className="text-muted-foreground max-w-[150px] truncate sm:max-w-[200px] lg:max-w-[250px] xl:max-w-[350px]">{date}</span>+ {incidentScreenshotUrl ? (+ <a+ href={incidentScreenshotUrl}+ target="_blank"+ rel="noreferrer"+ className="relative relative h-5 w-5 overflow-hidden rounded border"+ >+ <Image+ src={incidentScreenshotUrl}+ alt="incident screenshot"+ fill={true}+ />+ </a>+ ) : null}</div>);},@@ -60,13 +75,27 @@ export const columns: ColumnDef<Incident>[] = [accessorKey: "resolvedAt",header: "Resolved At",cell: ({ row }) => {- const { resolvedAt } = row.original;+ const { resolvedAt, recoveryScreenshotUrl } = row.original;const date = resolvedAt ? formatDateTime(resolvedAt) : "-";return (- <div className="flex">+ <div className="flex gap-2"><span className="text-muted-foreground max-w-[150px] truncate sm:max-w-[200px] lg:max-w-[250px] xl:max-w-[350px]">{date}</span>+ {recoveryScreenshotUrl ? (+ <a+ href={recoveryScreenshotUrl}+ target="_blank"+ rel="noreferrer"+ className="relative h-5 w-5 overflow-hidden rounded border"+ >+ <Image+ src={recoveryScreenshotUrl}+ alt="recovery screenshot"+ fill={true}+ />+ </a>+ ) : null}</div>);},diff --git a/apps/web/src/components/data-table/incident/data-table-row-actions.tsx b/apps/web/src/components/data-table/incident/data-table-row-actions.tsxindex bf9812702..e4ba8231f 100644--- a/apps/web/src/components/data-table/incident/data-table-row-actions.tsx+++ b/apps/web/src/components/data-table/incident/data-table-row-actions.tsx@@ -1,6 +1,7 @@"use client";import * as React from "react";+import Link from "next/link";import { useRouter } from "next/navigation";import type { Row } from "@tanstack/react-table";import { MoreHorizontal } from "lucide-react";@@ -108,6 +109,10 @@ export function DataTableRowActions<TData>({Resolved</DropdownMenuItem><DropdownMenuSeparator />+ <Link href={`./incidents/${incident.id}/overview`}>+ <DropdownMenuItem>Details</DropdownMenuItem>+ </Link>+ <DropdownMenuSeparator /><AlertDialogTrigger asChild><DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">Deletediff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsxindex 80826531c..a58de3c05 100644--- a/apps/web/src/components/icons.tsx+++ b/apps/web/src/components/icons.tsx@@ -11,6 +11,8 @@ import {Cog,Copy,CreditCard,+ Eye,+ FileClock,Fingerprint,Globe2,Hourglass,@@ -80,10 +82,12 @@ export const Icons = {image: Image,bell: Bell,zap: Zap,+ eye: Eye,users: Users,key: KeyRound,"credit-card": CreditCard,"alert-triangle": AlertTriangle,+ "file-clock": FileClock,megaphone: Megaphone,webhook: Webhook,minus: Minus,diff --git a/apps/web/src/components/layout/app-page-with-sidebar-layout.tsx b/apps/web/src/components/layout/app-page-with-sidebar-layout.tsxindex 34ac25dba..296877e41 100644--- a/apps/web/src/components/layout/app-page-with-sidebar-layout.tsx+++ b/apps/web/src/components/layout/app-page-with-sidebar-layout.tsx@@ -24,7 +24,7 @@ export default function AppPageWithSidebarLayout({<Shell className="hidden max-h-[calc(100vh-8rem)] max-w-min shrink-0 lg:sticky lg:top-28 lg:block"><AppSidebar page={page} /></Shell>- <Shell className="relative flex-1 overflow-x-hidden">+ <Shell className="relative flex-1 overflow-hidden"><divclassName={cn("flex h-full flex-1 flex-col gap-6 md:gap-8",diff --git a/apps/web/src/config/pages.ts b/apps/web/src/config/pages.tsindex c012134f1..a50c809c7 100644--- a/apps/web/src/config/pages.ts+++ b/apps/web/src/config/pages.ts@@ -96,6 +96,16 @@ export const statusPagesPagesConfig: Page[] = [},];+const incidentPagesConfig: Page[] = [+ {+ title: "Overview",+ description: "Timeline with all the actions.",+ href: "/incidents/[id]/overview",+ icon: "file-clock",+ segment: "overview",+ },+];+export const statusReportsPagesConfig: Page[] = [{title: "Overview",@@ -140,6 +150,7 @@ export const pagesConfig = [href: "/incidents",icon: "siren",segment: "incidents",+ children: incidentPagesConfig,},{title: "Status Pages",diff --git a/packages/api/src/router/incident.ts b/packages/api/src/router/incident.tsindex 52645714b..844ecf441 100644--- a/packages/api/src/router/incident.ts+++ b/packages/api/src/router/incident.ts@@ -30,7 +30,7 @@ export const incidentRouter = createTRPCRouter({.input(z.object({ id: z.number() })).output(selectIncidentSchema).query(async (opts) => {- const currentIncident = await opts.ctx.db+ const result = await opts.ctx.db.select().from(schema.incidentTable).where(@@ -39,8 +39,16 @@ export const incidentRouter = createTRPCRouter({eq(schema.incidentTable.workspaceId, opts.ctx.workspace.id),),)+ .leftJoin(+ schema.monitor,+ eq(schema.incidentTable.monitorId, schema.monitor.id),+ ).get();- return selectIncidentSchema.parse(currentIncident);++ return selectIncidentSchema.parse({+ ...result?.incident,+ monitorName: result?.monitor?.name,+ });}),acknowledgeIncident: protectedProcedure