Skip to content

Open-source status page, incident response and uptime monitoring

📟 OpsGenie (#1160)

Thibault Le Ouay9a1d7152369f
diff --git a/apps/docs/src/assets/notification/opsgenie/opsgenie-1.png b/apps/docs/src/assets/notification/opsgenie/opsgenie-1.png
new file mode 100644
index 000000000..2cf8110db
Binary files /dev/null and b/apps/docs/src/assets/notification/opsgenie/opsgenie-1.png differ
diff --git a/apps/docs/src/assets/notification/opsgenie/opsgenie-2.png b/apps/docs/src/assets/notification/opsgenie/opsgenie-2.png
new file mode 100644
index 000000000..eebeca54e
Binary files /dev/null and b/apps/docs/src/assets/notification/opsgenie/opsgenie-2.png differ
diff --git a/apps/docs/src/assets/notification/opsgenie/opsgenie-3.png b/apps/docs/src/assets/notification/opsgenie/opsgenie-3.png
new file mode 100644
index 000000000..3be659fe6
Binary files /dev/null and b/apps/docs/src/assets/notification/opsgenie/opsgenie-3.png differ
diff --git a/apps/docs/src/assets/notification/opsgenie/opsgenie-4.png b/apps/docs/src/assets/notification/opsgenie/opsgenie-4.png
new file mode 100644
index 000000000..9ed138986
Binary files /dev/null and b/apps/docs/src/assets/notification/opsgenie/opsgenie-4.png differ
diff --git a/apps/docs/src/assets/notification/opsgenie/opsgenie-5.png b/apps/docs/src/assets/notification/opsgenie/opsgenie-5.png
new file mode 100644
index 000000000..f943308d0
Binary files /dev/null and b/apps/docs/src/assets/notification/opsgenie/opsgenie-5.png differ
diff --git a/apps/docs/src/content/docs/alerting/providers/opsgenie.mdx b/apps/docs/src/content/docs/alerting/providers/opsgenie.mdx
new file mode 100644
index 000000000..e29673889
--- /dev/null
+++ b/apps/docs/src/content/docs/alerting/providers/opsgenie.mdx
@@ -0,0 +1,69 @@
+---
+title: OpsGenie
+description: "How to set up OpsGenie notifications in OpenStatus to get alerts when your synthetic check fail"
+
+---
+import { Image} from 'astro:assets';
+import OpsGenie1 from '../../../../assets/notification/opsgenie/opsgenie-1.png';
+import OpsGenie2 from '../../../../assets/notification/opsgenie/opsgenie-2.png';
+import OpsGenie3 from '../../../../assets/notification/opsgenie/opsgenie-3.png';
+import OpsGenie4 from '../../../../assets/notification/opsgenie/opsgenie-4.png';
+import OpsGenie5 from '../../../../assets/notification/opsgenie/opsgenie-5.png';
+
+Get Notified on OpsGenie when we create an incident.
+
+## How to connect OpsGenie
+
+### Create an OpsGenie Integration
+
+First we need to create an integration in OpsGenie.
+
+Go to your team in OpsGenie and select `Integrations` from the menu.
+
+
+ <Image
+ src={OpsGenie1}
+ alt="OpsGenie integration page"
+ />
+In the integrations page, search for `API` and select it.
+
+
+ <Image
+ src={OpsGenie2}
+ alt="Connect to OpsGenie"
+ />
+
+Give your integration a name and save it.
+Copy your API key and save it. You will need it to connect OpenStatus to OpsGenie.
+
+ <Image
+ src={OpsGenie3}
+ alt="Connect to OpsGenie"
+ />
+
+
+### Connect your OpenStatus account to OpsGenie
+
+
+Go to the Alerts Page . Select `OpsGenie` from the list of available integrations.
+
+
+ <Image
+ src={OpsGenie4}
+ alt="OpenStatus Notifications Page"
+ />
+
+
+Give you integration a name and paste the API key you copied from OpsGenie and select the region of your OpsGenie account.
+
+ <Image
+ src={OpsGenie5}
+ alt="Connect to OpsGenie in OpenStatus"
+ />
+
+Select the service you want to use to send notifications. You can create a new service if you don't have one.
+
+
+You are now connected to OpsGenie.
+
+You will receive some notifications if we detect an incident
diff --git a/apps/server/package.json b/apps/server/package.json
index e54c489bd..0cbd8c5cc 100644
--- a/apps/server/package.json
+++ b/apps/server/package.json
@@ -21,6 +21,7 @@
"@openstatus/error": "workspace:*",
"@openstatus/notification-discord": "workspace:*",
"@openstatus/notification-emails": "workspace:*",
+ "@openstatus/notification-opsgenie": "workspace:*",
"@openstatus/notification-pagerduty": "workspace:*",
"@openstatus/notification-slack": "workspace:*",
"@openstatus/notification-twillio-sms": "workspace:*",
diff --git a/apps/server/src/routes/checker/utils.ts b/apps/server/src/routes/checker/utils.ts
index ed0f7f1ee..1b0fe6ba5 100644
--- a/apps/server/src/routes/checker/utils.ts
+++ b/apps/server/src/routes/checker/utils.ts
@@ -30,6 +30,12 @@ import {
sendAlert as sendPagerdutyAlert,
} from "@openstatus/notification-pagerduty";
+import {
+ sendAlert as sendOpsGenieAlert,
+ sendDegraded as sendOpsGenieDegraded,
+ sendRecovery as sendOpsGenieRecovery,
+} from "@openstatus/notification-opsgenie";
+
type SendNotification = ({
monitor,
notification,
@@ -73,7 +79,11 @@ export const providerToFunction = {
sendRecovery: sendSmsRecovery,
sendDegraded: sendSmsDegraded,
},
-
+ opsgenie: {
+ sendAlert: sendOpsGenieAlert,
+ sendRecovery: sendOpsGenieRecovery,
+ sendDegraded: sendOpsGenieDegraded,
+ },
pagerduty: {
sendAlert: sendPagerdutyAlert,
sendRecovery: sendPagerDutyRecovery,
diff --git a/apps/server/src/routes/v1/statusReports/delete.test.ts b/apps/server/src/routes/v1/statusReports/delete.test.ts
index d9933dc0a..2e17b9374 100644
--- a/apps/server/src/routes/v1/statusReports/delete.test.ts
+++ b/apps/server/src/routes/v1/statusReports/delete.test.ts
@@ -1,17 +1,40 @@
import { expect, test } from "bun:test";
import { app } from "@/index";
+import { StatusReportSchema } from "./schema";
test("delete the status report", async () => {
- const res = await app.request("/v1/status_report/3", {
+ // Create a status report we will delete
+ const date = new Date();
+ date.setMilliseconds(0);
+
+ const res = await app.request("/v1/status_report", {
+ method: "POST",
+ headers: {
+ "x-openstatus-key": "1",
+ "content-type": "application/json",
+ },
+ body: JSON.stringify({
+ status: "investigating",
+ title: "New Status Report",
+ message: "Message",
+ monitorIds: [1],
+ date: date.toISOString(),
+ pageId: 1,
+ }),
+ });
+
+ const result = StatusReportSchema.safeParse(await res.json());
+
+ const del = await app.request(`/v1/status_report/${result.data?.id}`, {
method: "DELETE",
headers: {
"x-openstatus-key": "1",
},
});
- expect(res.status).toBe(200);
- expect(await res.json()).toMatchObject({});
+ expect(del.status).toBe(200);
+ expect(await del.json()).toMatchObject({});
});
test("no auth key should return 401", async () => {
diff --git a/apps/web/package.json b/apps/web/package.json
index b6ffa980b..64dc4d32c 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -26,6 +26,7 @@
"@openstatus/notification-emails": "workspace:*",
"@openstatus/notification-pagerduty": "workspace:*",
"@openstatus/notification-slack": "workspace:*",
+ "@openstatus/notification-opsgenie": "workspace:*",
"@openstatus/react": "workspace:*",
"@openstatus/tinybird": "workspace:*",
"@openstatus/tracker": "workspace:*",
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/_components/channel-table.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/_components/channel-table.tsx
index 8c9dbb410..29b9b2095 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/_components/channel-table.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/(overview)/_components/channel-table.tsx
@@ -12,8 +12,6 @@ interface ChannelTable {
}
export default function ChannelTable({ workspace, disabled }: ChannelTable) {
- const isPagerDutyAllowed = getLimit(workspace.limits, "pagerduty");
- const isSMSAllowed = getLimit(workspace.limits, "sms");
return (
<div className="col-span-full w-full rounded-lg border border-border border-dashed bg-background p-8">
<h2 className="font-cal text-2xl">Channels</h2>
@@ -41,7 +39,7 @@ export default function ChannelTable({ workspace, disabled }: ChannelTable) {
? "http://localhost:3000"
: "https://www.openstatus.dev"
}/app/${workspace.slug}/notifications/new/pagerduty&version=2`}
- disabled={disabled || !isPagerDutyAllowed}
+ disabled={disabled || !workspace.limits.pagerduty}
/>
<Separator />
<Channel
@@ -55,7 +53,14 @@ export default function ChannelTable({ workspace, disabled }: ChannelTable) {
title="SMS"
description="Send notifications to your phones."
href="./notifications/new/sms"
- disabled={disabled || !isSMSAllowed}
+ disabled={disabled || !workspace.limits.sms}
+ />
+ <Separator />
+ <Channel
+ title="OpsGenie"
+ description="Send notifications to OpsGenie."
+ href="./notifications/new/opsgenie"
+ disabled={disabled || !workspace.limits.opsgenie}
/>
</div>
</div>
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/layout.tsx
index da8b37426..84b31f950 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/layout.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/layout.tsx
@@ -24,7 +24,10 @@ export default async function Layout(props: {
return (
<AppPageWithSidebarLayout id="notifications">
- <Header title={notification.name} description={notification.provider} />
+ <Header
+ title={notification.name}
+ description={<span className="font-mono">{notification.provider}</span>}
+ />
{children}
</AppPageWithSidebarLayout>
);
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/[channel]/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/[channel]/page.tsx
index 7384b82b5..b258b1d6e 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/[channel]/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/[channel]/page.tsx
@@ -29,8 +29,9 @@ export default async function ChannelPage(props: {
const isLimitReached =
await api.notification.isNotificationLimitReached.query();
- if (isLimitReached)
+ if (isLimitReached) {
return <ProFeatureAlert feature="More notification channel" />;
+ }
return (
<NotificationForm
diff --git a/apps/web/src/components/forms/notification/config.ts b/apps/web/src/components/forms/notification/config.ts
deleted file mode 100644
index 1a5bd032f..000000000
--- a/apps/web/src/components/forms/notification/config.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-import type {
- InsertNotification,
- NotificationProvider,
-} from "@openstatus/db/src/schema";
-import { allPlans } from "@openstatus/db/src/schema/plan/config";
-import { workspacePlans } from "@openstatus/db/src/schema/workspaces/constants";
-import { sendTestDiscordMessage } from "@openstatus/notification-discord";
-import { sendTestSlackMessage } from "@openstatus/notification-slack";
-export function getDefaultProviderData(defaultValues?: InsertNotification) {
- if (!defaultValues?.provider) return ""; // FIXME: input can empty - needs to be undefined
- return JSON.parse(defaultValues?.data || "{}")[defaultValues?.provider];
-}
-
-export function setProviderData(provider: NotificationProvider, data: string) {
- return { [provider]: data };
-}
-
-export function getProviderMetaData(provider: NotificationProvider) {
- switch (provider) {
- case "email":
- return {
- label: "Email",
- dataType: "email",
- placeholder: "[email protected]",
- setupDocLink: null,
- sendTest: null,
- plans: workspacePlans,
- };
-
- case "slack":
- return {
- label: "Slack",
- dataType: "url",
- placeholder: "https://hooks.slack.com/services/xxx...",
- setupDocLink:
- "https://api.slack.com/messaging/webhooks#getting_started",
- sendTest: sendTestSlackMessage,
- plans: workspacePlans,
- };
-
- case "discord":
- return {
- label: "Discord",
- dataType: "url",
- placeholder: "https://discord.com/api/webhooks/{channelId}/xxx...",
- setupDocLink: "https://support.discord.com/hc/en-us/articles/228383668",
- sendTest: sendTestDiscordMessage,
- plans: workspacePlans,
- };
- case "sms":
- return {
- label: "SMS",
- dataType: "tel",
- placeholder: "+123456789",
- setupDocLink: null,
- sendTest: null,
- plans: workspacePlans.filter((plan) => allPlans[plan].limits.sms),
- };
-
- case "pagerduty":
- return {
- label: "PagerDuty",
- dataType: null,
- placeholder: "",
- setupDocLink:
- "https://docs.openstatus.dev/synthetic/features/notification/pagerduty",
- sendTest: null,
- plans: workspacePlans.filter((plan) => allPlans[plan].limits.pagerduty),
- };
-
- default:
- return {
- label: "Webhook",
- dataType: "url",
- placeholder: "xxxx",
- setupDocLink: `https://docs.openstatus.dev/integrations/${provider}`,
- send: null,
- plans: workspacePlans,
- };
- }
-}
diff --git a/apps/web/src/components/forms/notification/form.tsx b/apps/web/src/components/forms/notification/form.tsx
index 927b79a5f..a5c245aef 100644
--- a/apps/web/src/components/forms/notification/form.tsx
+++ b/apps/web/src/components/forms/notification/form.tsx
@@ -7,11 +7,12 @@ import { useForm } from "react-hook-form";
import type {
InsertNotification,
+ InsertNotificationWithData,
Monitor,
NotificationProvider,
WorkspacePlan,
} from "@openstatus/db/src/schema";
-import { insertNotificationSchema } from "@openstatus/db/src/schema";
+import { InsertNotificationWithDataSchema } from "@openstatus/db/src/schema";
import { Badge, Form } from "@openstatus/ui";
import {
@@ -24,7 +25,6 @@ import { toast, toastAction } from "@/lib/toast";
import { api } from "@/trpc/client";
import { TRPCClientError } from "@trpc/client";
import { SaveButton } from "../shared/save-button";
-import { getDefaultProviderData, setProviderData } from "./config";
import { General } from "./general";
import { SectionConnect } from "./section-connect";
@@ -51,38 +51,39 @@ export function NotificationForm({
}: Props) {
const [isPending, startTransition] = useTransition();
const router = useRouter();
- const form = useForm<InsertNotification>({
- resolver: zodResolver(insertNotificationSchema),
+ const form = useForm<InsertNotificationWithData>({
+ resolver: zodResolver(InsertNotificationWithDataSchema),
defaultValues: {
...defaultValues,
provider,
name: defaultValues?.name || "",
- data: getDefaultProviderData(defaultValues),
+ data: JSON.parse(defaultValues?.data || "{}"),
},
});
- async function onSubmit({ provider, data, ...rest }: InsertNotification) {
+ async function onSubmit({
+ provider,
+ data,
+ ...rest
+ }: InsertNotificationWithData) {
+ console.log({ provider, data, ...rest });
startTransition(async () => {
try {
if (provider === "pagerduty") {
if (callbackData) {
- data = callbackData;
+ data.pagerduty = callbackData;
}
}
- if (data === "") {
- form.setError("data", { message: "This field is required" });
- return;
- }
if (defaultValues) {
await api.notification.update.mutate({
provider,
- data: JSON.stringify(setProviderData(provider, data)),
+ data: JSON.stringify(data),
...rest,
});
} else {
await api.notification.create.mutate({
provider,
- data: JSON.stringify(setProviderData(provider, data)),
+ data: JSON.stringify(data),
...rest,
});
}
@@ -103,7 +104,7 @@ export function NotificationForm({
return (
<Form {...form}>
<form
- onSubmit={form.handleSubmit(onSubmit)}
+ onSubmit={form.handleSubmit(onSubmit, console.log)}
id="notification-form" // we use a form id to connect the submit button to the form (as we also have the form nested inside of `MonitorForm`)
className="flex flex-col gap-4"
>
diff --git a/apps/web/src/components/forms/notification/general.tsx b/apps/web/src/components/forms/notification/general.tsx
index a3126538b..a71f57f43 100644
--- a/apps/web/src/components/forms/notification/general.tsx
+++ b/apps/web/src/components/forms/notification/general.tsx
@@ -1,14 +1,13 @@
"use client";
-import { useMemo, useTransition } from "react";
+import { useMemo } from "react";
import type { UseFormReturn } from "react-hook-form";
import type {
- InsertNotification,
+ InsertNotificationWithData,
WorkspacePlan,
} from "@openstatus/db/src/schema";
import {
- Button,
FormControl,
FormDescription,
FormField,
@@ -18,43 +17,55 @@ import {
Input,
} from "@openstatus/ui";
-import { LoadingAnimation } from "@/components/loading-animation";
-import { toastAction } from "@/lib/toast";
import { SectionHeader } from "../shared/section-header";
-import { getProviderMetaData } from "./config";
+import { SectionDiscord } from "./provider/section-discord";
+import { SectionEmail } from "./provider/section-email";
+import { SectionOpsGenie } from "./provider/section-opsgenie";
+import { SectionPagerDuty } from "./provider/section-pagerduty";
+import { SectionSlack } from "./provider/section-slack";
+import { SectionSms } from "./provider/section-sms";
+
+const LABELS = {
+ slack: "Slack",
+ discord: "Discord",
+ sms: "SMS",
+ pagerduty: "PagerDuty",
+ opsgenie: "OpsGenie",
+ email: "Email",
+};
interface Props {
- form: UseFormReturn<InsertNotification>;
+ form: UseFormReturn<InsertNotificationWithData>;
plan: WorkspacePlan;
}
export function General({ form, plan }: Props) {
- const [isTestPending, startTestTransition] = useTransition();
const watchProvider = form.watch("provider");
- const watchWebhookUrl = form.watch("data");
- const providerMetaData = useMemo(
- () => getProviderMetaData(watchProvider),
- [watchProvider],
- );
- async function sendTestWebhookPing() {
- const webhookUrl = form.getValues("data");
- if (!webhookUrl) return;
- startTestTransition(async () => {
- const isSuccessfull = await providerMetaData.sendTest?.(webhookUrl);
- if (isSuccessfull) {
- toastAction("test-success");
- } else {
- toastAction("test-error");
- }
- });
+ function renderProviderSection() {
+ switch (watchProvider) {
+ case "slack":
+ return <SectionSlack form={form} />;
+ case "discord":
+ return <SectionDiscord form={form} />;
+ case "sms":
+ return <SectionSms form={form} />;
+ case "pagerduty":
+ return <SectionPagerDuty form={form} plan={plan} />;
+ case "opsgenie":
+ return <SectionOpsGenie form={form} plan={plan} />;
+ case "email":
+ return <SectionEmail form={form} />;
+ default:
+ return <div>No provider selected</div>;
+ }
}
return (
<div className="grid gap-4 sm:grid-cols-3 sm:gap-6">
<SectionHeader
title="Alert"
- description={`Update your ${providerMetaData.label} settings`}
+ description={`Update your ${LABELS[watchProvider]} settings`}
/>
<div className="grid gap-4 sm:col-span-2 sm:grid-cols-2">
<FormField
@@ -71,56 +82,7 @@ export function General({ form, plan }: Props) {
</FormItem>
)}
/>
- {providerMetaData.dataType && (
- <FormField
- control={form.control}
- name="data"
- render={({ field }) => (
- <FormItem className="sm:col-span-full">
- <FormLabel>{providerMetaData.label}</FormLabel>
- <FormControl>
- <Input
- type={providerMetaData.dataType}
- placeholder={providerMetaData.placeholder}
- {...field}
- disabled={!providerMetaData.plans?.includes(plan)}
- />
- </FormControl>
- <FormDescription className="flex items-center justify-between">
- The data is required.
- {providerMetaData.setupDocLink && (
- <a
- href={providerMetaData.setupDocLink}
- target="_blank"
- className="underline hover:no-underline"
- rel="noreferrer"
- >
- How to setup your {providerMetaData.label} webhook
- </a>
- )}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- )}
- <div className="col-span-full text-right">
- {providerMetaData.sendTest && (
- <Button
- type="button"
- variant="secondary"
- className="w-full sm:w-auto"
- disabled={!watchWebhookUrl || isTestPending}
- onClick={sendTestWebhookPing}
- >
- {!isTestPending ? (
- "Test Webhook"
- ) : (
- <LoadingAnimation variant="inverse" />
- )}
- </Button>
- )}
- </div>
+ {renderProviderSection()}
</div>
</div>
);
diff --git a/apps/web/src/components/forms/notification/provider/actions.ts b/apps/web/src/components/forms/notification/provider/actions.ts
new file mode 100644
index 000000000..d2dae9927
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/actions.ts
@@ -0,0 +1,11 @@
+"use server";
+
+import { sendTest } from "@openstatus/notification-opsgenie";
+
+export async function sendOpsGenieTestAlert(
+ apiKey: string,
+ region: "us" | "eu",
+) {
+ const isSuccessfull = await sendTest({ apiKey, region });
+ return isSuccessfull;
+}
diff --git a/apps/web/src/components/forms/notification/provider/section-discord.tsx b/apps/web/src/components/forms/notification/provider/section-discord.tsx
new file mode 100644
index 000000000..aecb87d00
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/section-discord.tsx
@@ -0,0 +1,90 @@
+"use client";
+
+import { useTransition } from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertNotificationWithData } from "@openstatus/db/src/schema";
+import {
+ Button,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+} from "@openstatus/ui";
+
+import { LoadingAnimation } from "@/components/loading-animation";
+import { toastAction } from "@/lib/toast";
+import { sendTestDiscordMessage } from "@openstatus/notification-discord";
+
+interface Props {
+ form: UseFormReturn<InsertNotificationWithData>;
+}
+
+export function SectionDiscord({ form }: Props) {
+ const [isTestPending, startTestTransition] = useTransition();
+ const watchUrl = form.watch("data.discord");
+
+ async function sendTestWebhookPing() {
+ if (!watchUrl) return;
+ startTestTransition(async () => {
+ const isSuccessfull = await sendTestDiscordMessage(watchUrl);
+ if (isSuccessfull) {
+ toastAction("test-success");
+ } else {
+ toastAction("test-error");
+ }
+ });
+ }
+
+ return (
+ <>
+ <FormField
+ control={form.control}
+ name="data.discord"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ <FormLabel>Webhook URL</FormLabel>
+ <FormControl>
+ <Input
+ type="url"
+ placeholder="https://discord.com/api/webhooks/{channelId}/xxx..."
+ required
+ {...field}
+ />
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The data is required.
+ <a
+ href={"https://support.discord.com/hc/en-us/articles/228383668"}
+ target="_blank"
+ className="underline hover:no-underline"
+ rel="noreferrer"
+ >
+ How to setup your Discord webhook
+ </a>
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <div className="col-span-full text-right">
+ <Button
+ type="button"
+ variant="secondary"
+ className="w-full sm:w-auto"
+ disabled={isTestPending || !watchUrl}
+ onClick={sendTestWebhookPing}
+ >
+ {!isTestPending ? (
+ "Test Webhook"
+ ) : (
+ <LoadingAnimation variant="inverse" />
+ )}
+ </Button>
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/src/components/forms/notification/provider/section-email.tsx b/apps/web/src/components/forms/notification/provider/section-email.tsx
new file mode 100644
index 000000000..92405b811
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/section-email.tsx
@@ -0,0 +1,44 @@
+"use client";
+
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertNotificationWithData } from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+} from "@openstatus/ui";
+
+interface Props {
+ form: UseFormReturn<InsertNotificationWithData>;
+}
+
+export function SectionEmail({ form }: Props) {
+ return (
+ <FormField
+ control={form.control}
+ name="data.email"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ <FormLabel>Email</FormLabel>
+ <FormControl>
+ <Input
+ type="email"
+ placeholder="[email protected]"
+ required
+ {...field}
+ />
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The email is required.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ );
+}
diff --git a/apps/web/src/components/forms/notification/provider/section-opsgenie.tsx b/apps/web/src/components/forms/notification/provider/section-opsgenie.tsx
new file mode 100644
index 000000000..c524ecd32
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/section-opsgenie.tsx
@@ -0,0 +1,124 @@
+"use client";
+
+import type { UseFormReturn } from "react-hook-form";
+
+import { LoadingAnimation } from "@/components/loading-animation";
+import { toastAction } from "@/lib/toast";
+import type {
+ InsertNotificationWithData,
+ WorkspacePlan,
+} from "@openstatus/db/src/schema";
+import {
+ Button,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@openstatus/ui";
+import { useTransition } from "react";
+
+import { sendOpsGenieTestAlert } from "./actions";
+
+interface Props {
+ form: UseFormReturn<InsertNotificationWithData>;
+ plan: WorkspacePlan;
+}
+
+export function SectionOpsGenie({ form, plan }: Props) {
+ const [isTestPending, startTestTransition] = useTransition();
+ const watchApiKey = form.watch("data.opsgenie.apiKey");
+ const watchRegion = form.watch("data.opsgenie.region");
+
+ async function sendTestAlert() {
+ if (!watchApiKey || !watchRegion) return;
+ startTestTransition(async () => {
+ const isSuccessfull = await sendOpsGenieTestAlert(
+ watchApiKey,
+ watchRegion,
+ );
+ if (isSuccessfull) {
+ toastAction("test-success");
+ } else {
+ toastAction("test-error");
+ }
+ });
+ }
+
+ return (
+ <>
+ <FormField
+ control={form.control}
+ name="data.opsgenie.apiKey"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ <FormLabel>API Key</FormLabel>
+ <FormControl>
+ <Input placeholder={"xxx-yyy-zzz"} {...field} />
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The API key is required.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="data.opsgenie.region"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ <FormLabel>Region</FormLabel>
+ <FormControl>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select a region" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ <SelectItem value="us">US</SelectItem>
+ <SelectItem value="eu">EU</SelectItem>
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The region is required.
+ <a
+ href="https://docs.openstatus.dev/synthetic/features/notification/opsgenie"
+ target="_blank"
+ className="underline hover:no-underline"
+ rel="noreferrer"
+ >
+ How to setup your OpsGenie.
+ </a>
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <div className="col-span-full text-right">
+ <Button
+ type="button"
+ variant="secondary"
+ className="w-full sm:w-auto"
+ disabled={isTestPending || !watchApiKey || !watchRegion}
+ onClick={sendTestAlert}
+ >
+ {!isTestPending ? (
+ "Test Alert"
+ ) : (
+ <LoadingAnimation variant="inverse" />
+ )}
+ </Button>
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/src/components/forms/notification/provider/section-pagerduty.tsx b/apps/web/src/components/forms/notification/provider/section-pagerduty.tsx
new file mode 100644
index 000000000..8319be3f9
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/section-pagerduty.tsx
@@ -0,0 +1,17 @@
+"use client";
+
+import type { UseFormReturn } from "react-hook-form";
+
+import type {
+ InsertNotificationWithData,
+ WorkspacePlan,
+} from "@openstatus/db/src/schema";
+
+interface Props {
+ form: UseFormReturn<InsertNotificationWithData>;
+ plan: WorkspacePlan;
+}
+
+export function SectionPagerDuty({ form }: Props) {
+ return null;
+}
diff --git a/apps/web/src/components/forms/notification/provider/section-slack.tsx b/apps/web/src/components/forms/notification/provider/section-slack.tsx
new file mode 100644
index 000000000..af2dba438
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/section-slack.tsx
@@ -0,0 +1,92 @@
+"use client";
+
+import { useTransition } from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertNotificationWithData } from "@openstatus/db/src/schema";
+import {
+ Button,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+} from "@openstatus/ui";
+
+import { LoadingAnimation } from "@/components/loading-animation";
+import { toastAction } from "@/lib/toast";
+import { sendTestSlackMessage } from "@openstatus/notification-slack";
+
+interface Props {
+ form: UseFormReturn<InsertNotificationWithData>;
+}
+
+export function SectionSlack({ form }: Props) {
+ const [isTestPending, startTestTransition] = useTransition();
+ const watchUrl = form.watch("data.slack");
+
+ async function sendTestWebhookPing() {
+ if (!watchUrl) return;
+ startTestTransition(async () => {
+ const isSuccessfull = await sendTestSlackMessage(watchUrl);
+ if (isSuccessfull) {
+ toastAction("test-success");
+ } else {
+ toastAction("test-error");
+ }
+ });
+ }
+
+ return (
+ <>
+ <FormField
+ control={form.control}
+ name="data.slack"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ <FormLabel>Webhook URL</FormLabel>
+ <FormControl>
+ <Input
+ type="url"
+ placeholder="https://hooks.slack.com/services/xxx..."
+ required
+ {...field}
+ />
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The data is required.
+ <a
+ href={
+ "https://api.slack.com/messaging/webhooks#getting_started"
+ }
+ target="_blank"
+ className="underline hover:no-underline"
+ rel="noreferrer"
+ >
+ How to setup your Slack webhook
+ </a>
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <div className="col-span-full text-right">
+ <Button
+ type="button"
+ variant="secondary"
+ className="w-full sm:w-auto"
+ disabled={isTestPending || !watchUrl}
+ onClick={sendTestWebhookPing}
+ >
+ {!isTestPending ? (
+ "Test Webhook"
+ ) : (
+ <LoadingAnimation variant="inverse" />
+ )}
+ </Button>
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/src/components/forms/notification/provider/section-sms.tsx b/apps/web/src/components/forms/notification/provider/section-sms.tsx
new file mode 100644
index 000000000..b0c63f8f5
--- /dev/null
+++ b/apps/web/src/components/forms/notification/provider/section-sms.tsx
@@ -0,0 +1,39 @@
+"use client";
+
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertNotificationWithData } from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+} from "@openstatus/ui";
+
+interface Props {
+ form: UseFormReturn<InsertNotificationWithData>;
+}
+
+export function SectionSms({ form }: Props) {
+ return (
+ <FormField
+ control={form.control}
+ name="data.sms"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ <FormLabel>Phone Number</FormLabel>
+ <FormControl>
+ <Input type="tel" placeholder="+1234567890" required {...field} />
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The phone number is required.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ );
+}
diff --git a/apps/web/src/components/forms/notification/section-connect.tsx b/apps/web/src/components/forms/notification/section-connect.tsx
index b80e3f6ac..3690b5692 100644
--- a/apps/web/src/components/forms/notification/section-connect.tsx
+++ b/apps/web/src/components/forms/notification/section-connect.tsx
@@ -3,7 +3,10 @@
import * as React from "react";
import type { UseFormReturn } from "react-hook-form";
-import type { InsertNotification, Monitor } from "@openstatus/db/src/schema";
+import type {
+ InsertNotificationWithData,
+ Monitor,
+} from "@openstatus/db/src/schema";
import {
FormControl,
FormDescription,
@@ -16,7 +19,7 @@ import {
import { CheckboxLabel } from "../shared/checkbox-label";
interface Props {
- form: UseFormReturn<InsertNotification>;
+ form: UseFormReturn<InsertNotificationWithData>;
monitors?: Monitor[];
}
diff --git a/packages/api/src/router/notification.ts b/packages/api/src/router/notification.ts
index 3c9bd5a64..c425053b1 100644
--- a/packages/api/src/router/notification.ts
+++ b/packages/api/src/router/notification.ts
@@ -40,7 +40,23 @@ export const notificationRouter = createTRPCRouter({
});
}
+ const limitedProviders = ["sms", "pagerduty", "opsgenie"];
+ if (limitedProviders.includes(props.provider)) {
+ const isAllowed =
+ opts.ctx.workspace.limits[
+ props.provider as "sms" | "pagerduty" | "opsgenie"
+ ];
+
+ if (!isAllowed) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "Upgrade to use the notification channel.",
+ });
+ }
+ }
+
const _data = NotificationDataSchema.safeParse(JSON.parse(props.data));
+
if (!_data.success) {
throw new TRPCError({
code: "BAD_REQUEST",
diff --git a/packages/db/src/schema/notifications/constants.ts b/packages/db/src/schema/notifications/constants.ts
index 573d31a71..6ca77d890 100644
--- a/packages/db/src/schema/notifications/constants.ts
+++ b/packages/db/src/schema/notifications/constants.ts
@@ -4,4 +4,5 @@ export const notificationProvider = [
"slack",
"sms",
"pagerduty",
+ "opsgenie",
] as const;
diff --git a/packages/db/src/schema/notifications/validation.ts b/packages/db/src/schema/notifications/validation.ts
index f050cbe3a..3c1563dae 100644
--- a/packages/db/src/schema/notifications/validation.ts
+++ b/packages/db/src/schema/notifications/validation.ts
@@ -36,11 +36,18 @@ export const phoneSchema = z.string().regex(phoneRegex, "Invalid Number!");
export const emailSchema = z.string().email();
export const urlSchema = z.string().url();
+export const webhookDataSchema = z.object({ webhook: urlSchema });
export const emailDataSchema = z.object({ email: emailSchema });
export const phoneDataSchema = z.object({ sms: phoneSchema });
export const slackDataSchema = z.object({ slack: urlSchema });
export const discordDataSchema = z.object({ discord: urlSchema });
export const pagerdutyDataSchema = z.object({ pagerduty: z.string() });
+export const opsgenieDataSchema = z.object({
+ opsgenie: z.object({
+ apiKey: z.string(),
+ region: z.enum(["us", "eu"]),
+ }),
+});
export const NotificationDataSchema = z.union([
emailDataSchema,
@@ -48,4 +55,51 @@ export const NotificationDataSchema = z.union([
slackDataSchema,
discordDataSchema,
pagerdutyDataSchema,
+ opsgenieDataSchema,
]);
+
+export const InsertNotificationWithDataSchema = z.discriminatedUnion(
+ "provider",
+ [
+ insertNotificationSchema.merge(
+ z.object({
+ provider: z.literal("email"),
+ data: emailDataSchema,
+ }),
+ ),
+ insertNotificationSchema.merge(
+ z.object({
+ provider: z.literal("sms"),
+ data: phoneDataSchema,
+ }),
+ ),
+ insertNotificationSchema.merge(
+ z.object({
+ provider: z.literal("slack"),
+ data: slackDataSchema,
+ }),
+ ),
+ insertNotificationSchema.merge(
+ z.object({
+ provider: z.literal("discord"),
+ data: discordDataSchema,
+ }),
+ ),
+ insertNotificationSchema.merge(
+ z.object({
+ provider: z.literal("pagerduty"),
+ data: pagerdutyDataSchema,
+ }),
+ ),
+ insertNotificationSchema.merge(
+ z.object({
+ provider: z.literal("opsgenie"),
+ data: opsgenieDataSchema,
+ }),
+ ),
+ ],
+);
+
+export type InsertNotificationWithData = z.infer<
+ typeof InsertNotificationWithDataSchema
+>;
diff --git a/packages/db/src/schema/plan/config.ts b/packages/db/src/schema/plan/config.ts
index 4e2a228c9..b2d3ad9ef 100644
--- a/packages/db/src/schema/plan/config.ts
+++ b/packages/db/src/schema/plan/config.ts
@@ -35,6 +35,7 @@ export const allPlans: Record<
notifications: true,
sms: false,
pagerduty: false,
+ opsgenie: false,
"notification-channels": 1,
members: 1,
"audit-log": false,
@@ -64,6 +65,7 @@ export const allPlans: Record<
"white-label": false,
notifications: true,
pagerduty: true,
+ opsgenie: true,
sms: true,
"notification-channels": 10,
members: "Unlimited",
@@ -131,6 +133,7 @@ export const allPlans: Record<
notifications: true,
sms: true,
pagerduty: true,
+ opsgenie: true,
"notification-channels": 20,
members: "Unlimited",
"audit-log": true,
@@ -197,6 +200,7 @@ export const allPlans: Record<
notifications: true,
sms: true,
pagerduty: true,
+ opsgenie: true,
"notification-channels": 50,
members: "Unlimited",
"audit-log": true,
diff --git a/packages/db/src/schema/plan/schema.ts b/packages/db/src/schema/plan/schema.ts
index 5e7305325..389b77b19 100644
--- a/packages/db/src/schema/plan/schema.ts
+++ b/packages/db/src/schema/plan/schema.ts
@@ -37,6 +37,7 @@ export const limitsSchema = z.object({
*/
notifications: z.boolean().default(true),
pagerduty: z.boolean().default(false),
+ opsgenie: z.boolean().default(false),
sms: z.boolean().default(false),
"notification-channels": z.number().default(1),
/**
diff --git a/packages/notifications/discord/package.json b/packages/notifications/discord/package.json
index 728c81294..051bb49a8 100644
--- a/packages/notifications/discord/package.json
+++ b/packages/notifications/discord/package.json
@@ -3,7 +3,8 @@
"version": "1.0.0",
"main": "src/index.ts",
"dependencies": {
- "@openstatus/db": "workspace:*"
+ "@openstatus/db": "workspace:*",
+ "zod": "3.22.4"
},
"devDependencies": {
"@openstatus/tsconfig": "workspace:*",
diff --git a/packages/notifications/discord/src/index.ts b/packages/notifications/discord/src/index.ts
index d62b56353..290a2f204 100644
--- a/packages/notifications/discord/src/index.ts
+++ b/packages/notifications/discord/src/index.ts
@@ -1,4 +1,5 @@
import type { Monitor, Notification } from "@openstatus/db/src/schema";
+import { DataSchema } from "./schema";
const postToWebhook = async (content: string, webhookUrl: string) => {
await fetch(webhookUrl, {
@@ -29,7 +30,7 @@ export const sendAlert = async ({
incidentId?: string;
cronTimestamp: number;
}) => {
- const notificationData = JSON.parse(notification.data);
+ const notificationData = DataSchema.parse(JSON.parse(notification.data));
const { discord: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
@@ -61,7 +62,7 @@ export const sendRecovery = async ({
incidentId?: string;
cronTimestamp: number;
}) => {
- const notificationData = JSON.parse(notification.data);
+ const notificationData = DataSchema.parse(JSON.parse(notification.data));
const { discord: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
@@ -93,7 +94,7 @@ export const sendDegraded = async ({
incidentId?: string;
cronTimestamp: number;
}) => {
- const notificationData = JSON.parse(notification.data);
+ const notificationData = DataSchema.parse(JSON.parse(notification.data));
const { discord: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
diff --git a/packages/notifications/discord/src/schema.ts b/packages/notifications/discord/src/schema.ts
new file mode 100644
index 000000000..7e80ca73d
--- /dev/null
+++ b/packages/notifications/discord/src/schema.ts
@@ -0,0 +1,5 @@
+import { z } from "zod";
+
+export const DataSchema = z.object({
+ discord: z.string(),
+});
diff --git a/packages/notifications/opsgenie/package.json b/packages/notifications/opsgenie/package.json
new file mode 100644
index 000000000..f513c4a9f
--- /dev/null
+++ b/packages/notifications/opsgenie/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "@openstatus/notification-opsgenie",
+ "version": "0.0.0",
+ "main": "src/index.ts",
+ "dependencies": {
+ "@openstatus/db": "workspace:*",
+ "@t3-oss/env-core": "0.7.1",
+ "@types/validator": "13.11.6",
+ "validator": "13.12.0",
+ "zod": "3.22.4"
+ },
+ "devDependencies": {
+ "@openstatus/tsconfig": "workspace:*",
+ "@types/node": "20.8.0",
+ "@types/react": "18.2.64",
+ "@types/react-dom": "18.2.21",
+ "typescript": "5.4.5"
+ }
+}
diff --git a/packages/notifications/opsgenie/src/index.ts b/packages/notifications/opsgenie/src/index.ts
new file mode 100644
index 000000000..5ba3a694a
--- /dev/null
+++ b/packages/notifications/opsgenie/src/index.ts
@@ -0,0 +1,183 @@
+import type { Monitor, Notification } from "@openstatus/db/src/schema";
+import { OpsGeniePayloadAlert, OpsGenieSchema } from "./schema";
+
+export const sendAlert = async ({
+ monitor,
+ notification,
+ statusCode,
+ message,
+ incidentId,
+ cronTimestamp,
+}: {
+ monitor: Monitor;
+ notification: Notification;
+ statusCode?: number;
+ message?: string;
+ incidentId?: string;
+ cronTimestamp: number;
+}) => {
+ const { opsgenie } = OpsGenieSchema.parse(JSON.parse(notification.data));
+ const { name } = monitor;
+
+ const event = OpsGeniePayloadAlert.parse({
+ alias: `${monitor.id}}-${incidentId}`,
+ message: `${name} is down`,
+ description: message,
+ details: {
+ message,
+ status: statusCode,
+ severity: "down",
+ },
+ });
+
+ const url =
+ opsgenie.region === "eu"
+ ? "https://api.eu.opsgenie.com/v2/alerts"
+ : "https://api.opsgenie.com/v2/alerts";
+ try {
+ await fetch(url, {
+ method: "POST",
+ body: JSON.stringify(event),
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `GenieKey ${opsgenie.apiKey}`,
+ },
+ });
+ } catch (err) {
+ console.log(err);
+ // Do something
+ }
+};
+
+export const sendDegraded = async ({
+ monitor,
+ notification,
+ statusCode,
+ message,
+ incidentId,
+}: {
+ monitor: Monitor;
+ notification: Notification;
+ statusCode?: number;
+ message?: string;
+ incidentId?: string;
+ cronTimestamp: number;
+}) => {
+ const { opsgenie } = OpsGenieSchema.parse(JSON.parse(notification.data));
+ const { name } = monitor;
+
+ const event = OpsGeniePayloadAlert.parse({
+ alias: `${monitor.id}}-${incidentId}`,
+ message: `${name} is down`,
+ description: message,
+ details: {
+ message,
+ status: statusCode,
+ severity: "degraded",
+ },
+ });
+
+ const url =
+ opsgenie.region === "eu"
+ ? "https://api.eu.opsgenie.com/v2/alerts"
+ : "https://api.opsgenie.com/v2/alerts";
+ try {
+ await fetch(url, {
+ method: "POST",
+ body: JSON.stringify(event),
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `GenieKey ${opsgenie.apiKey}`,
+ },
+ });
+ } catch (err) {
+ console.log(err);
+ // Do something
+
+ // Do something
+ }
+};
+
+export const sendRecovery = async ({
+ monitor,
+ notification,
+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>
+ statusCode,
+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>
+ message,
+ incidentId,
+}: {
+ monitor: Monitor;
+ notification: Notification;
+ statusCode?: number;
+ message?: string;
+ incidentId?: string;
+ cronTimestamp: number;
+}) => {
+ const { opsgenie } = OpsGenieSchema.parse(JSON.parse(notification.data));
+
+ const url =
+ opsgenie.region === "eu"
+ ? `https://api.eu.opsgenie.com/v2/alerts/${monitor.id}}-${incidentId}/close`
+ : `https://api.opsgenie.com/v2/alerts/${monitor.id}}-${incidentId}/close`;
+
+ const event = OpsGeniePayloadAlert.parse({
+ alias: `${monitor.id}}-${incidentId}`,
+ message: `${monitor.name} has recovered`,
+ description: message,
+ details: {
+ message,
+ status: statusCode,
+ },
+ });
+ try {
+ await fetch(url, {
+ method: "POST",
+ body: JSON.stringify(event),
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `GenieKey ${opsgenie.apiKey}`,
+ },
+ });
+ } catch (err) {
+ console.log(err);
+ // Do something
+ }
+};
+export const sendTest = async (props: {
+ apiKey: string;
+ region: "eu" | "us";
+}) => {
+ const { apiKey, region } = props;
+
+ const url =
+ region === "eu"
+ ? "https://api.eu.opsgenie.com/v2/alerts"
+ : "https://api.opsgenie.com/v2/alerts";
+
+ const alert = OpsGeniePayloadAlert.parse({
+ alias: "test-openstatus",
+ message: "Test Alert <OpenStatus>",
+ description:
+ "If you can read this, your OpsGenie integration is functioning correctly! Please ignore this alert and delete it.",
+ });
+
+ try {
+ const res = await fetch(url, {
+ method: "POST",
+ body: JSON.stringify(alert),
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `GenieKey ${apiKey}`,
+ "Access-Control-Allow-Origin": "*",
+ },
+ });
+ console.log(await res.json());
+ return true;
+ } catch (err) {
+ console.log(err);
+ return false;
+ }
+};
+
+export { OpsGenieSchema };
diff --git a/packages/notifications/opsgenie/src/schema.ts b/packages/notifications/opsgenie/src/schema.ts
new file mode 100644
index 000000000..d2ffa419d
--- /dev/null
+++ b/packages/notifications/opsgenie/src/schema.ts
@@ -0,0 +1,26 @@
+import { z } from "zod";
+
+export const OpsGenieSchema = z.object({
+ opsgenie: z.object({
+ apiKey: z.string(),
+ region: z.enum(["eu", "us"]),
+ }),
+});
+
+export const OpsGeniePayloadAlert = z.object({
+ message: z.string(),
+ alias: z.string(),
+ description: z.string(),
+ source: z.string().default("OpenStatus"),
+ details: z
+ .object({
+ message: z.string(),
+ status: z.number().optional(),
+ severity: z.enum(["degraded", "down"]),
+ })
+ .optional(),
+});
+
+export const OpsGenieCloseAlert = z.object({
+ source: z.string().default("OpenStatus"),
+});
diff --git a/packages/notifications/opsgenie/tsconfig.json b/packages/notifications/opsgenie/tsconfig.json
new file mode 100644
index 000000000..a8a8c9309
--- /dev/null
+++ b/packages/notifications/opsgenie/tsconfig.json
@@ -0,0 +1,4 @@
+{
+ "extends": "@openstatus/tsconfig/nextjs.json",
+ "include": ["src", "*.ts"]
+}
diff --git a/packages/notifications/slack/package.json b/packages/notifications/slack/package.json
index ac7d70d21..785105d53 100644
--- a/packages/notifications/slack/package.json
+++ b/packages/notifications/slack/package.json
@@ -3,7 +3,8 @@
"version": "0.0.0",
"main": "src/index.ts",
"dependencies": {
- "@openstatus/db": "workspace:*"
+ "@openstatus/db": "workspace:*",
+ "zod": "3.22.4"
},
"devDependencies": {
"@openstatus/tsconfig": "workspace:*",
diff --git a/packages/notifications/slack/src/index.ts b/packages/notifications/slack/src/index.ts
index ee82ae76f..5205a3c92 100644
--- a/packages/notifications/slack/src/index.ts
+++ b/packages/notifications/slack/src/index.ts
@@ -1,4 +1,5 @@
import type { Monitor, Notification } from "@openstatus/db/src/schema";
+import { DataSchema } from "./schema";
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const postToWebhook = async (body: any, webhookUrl: string) => {
@@ -29,7 +30,7 @@ export const sendAlert = async ({
incidentId?: string;
cronTimestamp: number;
}) => {
- const notificationData = JSON.parse(notification.data);
+ const notificationData = DataSchema.parse(JSON.parse(notification.data));
const { slack: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
@@ -88,7 +89,7 @@ export const sendRecovery = async ({
incidentId?: string;
cronTimestamp: number;
}) => {
- const notificationData = JSON.parse(notification.data);
+ const notificationData = DataSchema.parse(JSON.parse(notification.data));
const { slack: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
@@ -139,7 +140,7 @@ export const sendDegraded = async ({
message?: string;
cronTimestamp: number;
}) => {
- const notificationData = JSON.parse(notification.data);
+ const notificationData = DataSchema.parse(JSON.parse(notification.data));
const { slack: webhookUrl } = notificationData; // webhook url
const { name } = monitor;
diff --git a/packages/notifications/slack/src/schema.ts b/packages/notifications/slack/src/schema.ts
new file mode 100644
index 000000000..efb235a97
--- /dev/null
+++ b/packages/notifications/slack/src/schema.ts
@@ -0,0 +1,5 @@
+import { z } from "zod";
+
+export const DataSchema = z.object({
+ slack: z.string(),
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 67bb87038..3e521a3a7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -142,6 +142,9 @@ importers:
'@openstatus/notification-emails':
specifier: workspace:*
version: link:../../packages/notifications/email
+ '@openstatus/notification-opsgenie':
+ specifier: workspace:*
+ version: link:../../packages/notifications/opsgenie
'@openstatus/notification-pagerduty':
specifier: workspace:*
version: link:../../packages/notifications/pagerduty
@@ -248,6 +251,9 @@ importers:
'@openstatus/notification-emails':
specifier: workspace:*
version: link:../../packages/notifications/email
+ '@openstatus/notification-opsgenie':
+ specifier: workspace:*
+ version: link:../../packages/notifications/opsgenie
'@openstatus/notification-pagerduty':
specifier: workspace:*
version: link:../../packages/notifications/pagerduty
@@ -277,7 +283,7 @@ importers:
'@sentry/nextjs':
specifier: 8.46.0
'@stripe/stripe-js':
specifier: 2.1.6
version: 2.1.6
@@ -304,7 +310,7 @@ importers:
'@trpc/next':
specifier: 11.0.0-rc.666
'@trpc/react-query':
specifier: 11.0.0-rc.666
@@ -352,19 +358,19 @@ importers:
version: 5.0.7
next:
specifier: 15.1.1
next-auth:
specifier: 5.0.0-beta.25
next-plausible:
specifier: 3.12.4
next-themes:
specifier: 0.2.1
nuqs:
specifier: 2.2.3
random-word-slugs:
specifier: 0.1.7
version: 0.1.7
@@ -434,7 +440,7 @@ importers:
'@content-collections/next':
specifier: 0.2.4
'@openstatus/tsconfig':
specifier: workspace:*
version: link:../../packages/tsconfig
@@ -721,6 +727,9 @@ importers:
'@openstatus/db':
specifier: workspace:*
version: link:../../db
+ zod:
+ specifier: 3.22.4
+ version: 3.22.4
devDependencies:
'@openstatus/tsconfig':
specifier: workspace:*
@@ -769,6 +778,40 @@ importers:
specifier: 5.6.2
version: 5.6.2
+ packages/notifications/opsgenie:
+ dependencies:
+ '@openstatus/db':
+ specifier: workspace:*
+ version: link:../../db
+ '@t3-oss/env-core':
+ specifier: 0.7.1
+ '@types/validator':
+ specifier: 13.11.6
+ version: 13.11.6
+ validator:
+ specifier: 13.12.0
+ version: 13.12.0
+ zod:
+ specifier: 3.22.4
+ version: 3.22.4
+ devDependencies:
+ '@openstatus/tsconfig':
+ specifier: workspace:*
+ version: link:../../tsconfig
+ '@types/node':
+ specifier: 20.8.0
+ version: 20.8.0
+ '@types/react':
+ specifier: 18.2.64
+ version: 18.2.64
+ '@types/react-dom':
+ specifier: 18.2.21
+ version: 18.2.21
+ typescript:
+ specifier: 5.4.5
+ version: 5.4.5
+
packages/notifications/pagerduty:
dependencies:
'@openstatus/db':
@@ -808,6 +851,9 @@ importers:
'@openstatus/db':
specifier: workspace:*
version: link:../../db
+ zod:
+ specifier: 3.22.4
+ version: 3.22.4
devDependencies:
'@openstatus/tsconfig':
specifier: workspace:*
@@ -11417,11 +11463,11 @@ snapshots:
- acorn
- supports-color
dependencies:
'@content-collections/core': 0.7.3([email protected])
'@content-collections/integrations': 0.2.1(@content-collections/[email protected]([email protected]))
'@cspotcode/[email protected]':
dependencies:
@@ -13996,7 +14042,7 @@ snapshots:
'@sentry/types': 8.9.2
'@sentry/utils': 8.9.2
dependencies:
'@opentelemetry/api': 1.9.0
'@opentelemetry/semantic-conventions': 1.28.0
@@ -14009,7 +14055,7 @@ snapshots:
'@sentry/vercel-edge': 8.46.0
'@sentry/webpack-plugin': 2.22.7([email protected])([email protected]([email protected]))
chalk: 3.0.0
resolve: 1.22.8
rollup: 3.29.5
stacktrace-parser: 0.1.10
@@ -14629,11 +14675,11 @@ snapshots:
'@trpc/server': 11.0.0-rc.666([email protected])
typescript: 5.6.2
dependencies:
'@trpc/client': 11.0.0-rc.666(@trpc/[email protected]([email protected]))([email protected])
'@trpc/server': 11.0.0-rc.666([email protected])
react: 19.0.0
react-dom: 19.0.0([email protected])
typescript: 5.6.2
@@ -17527,7 +17573,7 @@ snapshots:
dependencies:
- '@types/node': 20.14.8
+ '@types/node': 22.10.2
merge-stream: 2.0.0
supports-color: 8.1.1
@@ -18600,27 +18646,15 @@ snapshots:
- dependencies:
- '@auth/core': 0.37.2
- react: 19.0.0
-
dependencies:
'@auth/core': 0.37.2
react: 19.0.0
- dependencies:
- react: 19.0.0
- react-dom: 19.0.0([email protected])
-
dependencies:
react: 19.0.0
react-dom: 19.0.0([email protected])
@@ -18656,32 +18690,6 @@ snapshots:
- '@babel/core'
- babel-plugin-macros
- dependencies:
- '@next/env': 15.1.1
- '@swc/counter': 0.1.3
- '@swc/helpers': 0.5.15
- busboy: 1.6.0
- caniuse-lite: 1.0.30001689
- postcss: 8.4.31
- react: 19.0.0
- react-dom: 19.0.0([email protected])
- styled-jsx: 5.1.6(@babel/[email protected])([email protected])
- optionalDependencies:
- '@next/swc-darwin-arm64': 15.1.1
- '@next/swc-darwin-x64': 15.1.1
- '@next/swc-linux-arm64-gnu': 15.1.1
- '@next/swc-linux-arm64-musl': 15.1.1
- '@next/swc-linux-x64-gnu': 15.1.1
- '@next/swc-linux-x64-musl': 15.1.1
- '@next/swc-win32-arm64-msvc': 15.1.1
- '@next/swc-win32-x64-msvc': 15.1.1
- '@opentelemetry/api': 1.9.0
- sharp: 0.33.5
- transitivePeerDependencies:
- - '@babel/core'
- - babel-plugin-macros
-
dependencies:
'@next/env': 15.1.1
@@ -18781,12 +18789,12 @@ snapshots:
dependencies:
boolbase: 1.0.0
dependencies:
mitt: 3.0.1
react: 19.0.0
optionalDependencies:
@@ -20334,13 +20342,6 @@ snapshots:
optionalDependencies:
'@babel/core': 7.24.5
- dependencies:
- client-only: 0.0.1
- react: 19.0.0
- optionalDependencies:
- '@babel/core': 7.26.0
-
dependencies:
'@jridgewell/gen-mapping': 0.3.5
@@ -20672,7 +20673,7 @@ snapshots:
'@tsconfig/node14': 1.0.3
'@tsconfig/node16': 1.0.4
'@types/node': 20.14.8
- acorn: 8.14.0
+ acorn: 8.11.3
acorn-walk: 8.3.2
arg: 4.1.3
create-require: 1.1.1