Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct silence link generation #4

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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