Skip to content

Commit

Permalink
fix: correct silence link generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fritterhoff committed Feb 26, 2024
1 parent 7a8652a commit 8491576
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<a href="${externalURL}${filters.join("&")}}">Create Silence</a>`;
return `<a href="${externalURL}${filters.join("&")}">Create Silence</a>`;
}

interface AlertData {
Expand Down Expand Up @@ -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(
`<p>${statusBadge(alert.status, alert.labels.severity)}</p>
Expand All @@ -102,9 +102,7 @@ function transform(data: AlertData): { version: string, empty: boolean } | { ver
${Object.entries(alert.annotations).map(([key, value]) => `<li>${key}: ${value}</li>`).join('')}
</ul>
</p>
<p>
${silenceLink(alert, grafanaUrl)}
</p>`)
${(alert.status === "firing") ? `<p>${silenceLink(alert, grafanaUrl)}</p>` : ''}`)
}
return {
version: 'v2',
Expand All @@ -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");
Expand Down

0 comments on commit 8491576

Please sign in to comment.