From 8491576cad0c443a24bbf747dee461e7e2a12fa6 Mon Sep 17 00:00:00 2001
From: Florian Ritterhoff
Date: Mon, 26 Feb 2024 09:42:57 +0100
Subject: [PATCH] fix: correct silence link generation
---
index.ts | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/index.ts b/index.ts
index d46db53..ed3f547 100644
--- a/index.ts
+++ b/index.ts
@@ -38,7 +38,7 @@ function silenceLink(alert: { labels: { [key: string]: string; }; }, externalURL
for (const [label, val] of Object.entries(alert.labels)) {
filters.push(`matcher=${encodeURIComponent(`${label} = "${val}"`)}`);
}
- return `Create Silence`;
+ return `Create Silence`;
}
interface AlertData {
@@ -88,7 +88,7 @@ function transform(data: AlertData): { version: string, empty: boolean } | { ver
**Annotations**:
${Object.entries(alert.annotations).map(([key, value]) => `${key}: ${value}`).join('\n')}
- [Silence](${silenceLink(alert, grafanaUrl)})
+ ${(alert.status === "firing") ? `[Silence](${silenceLink(alert, grafanaUrl)})` : ''}
`);
htmlErrors.push(
`${statusBadge(alert.status, alert.labels.severity)}
@@ -102,9 +102,7 @@ function transform(data: AlertData): { version: string, empty: boolean } | { ver
${Object.entries(alert.annotations).map(([key, value]) => `${key}: ${value}`).join('')}
-
- ${silenceLink(alert, grafanaUrl)}
-
`)
+ ${(alert.status === "firing") ? `${silenceLink(alert, grafanaUrl)}
` : ''}`)
}
return {
version: 'v2',
@@ -131,7 +129,7 @@ app.post("/webhook/:id", async (req: Request, res: Response) => {
res.status(500).send("Failed to forward the data to the upstream service");
} else {
res.status(200).send("Data forwarded successfully");
- }
+ }
} catch (error) {
console.error(error);
res.status(500).send("Failed to forward the data to the upstream service");