feat(notifications): add Rocket.Chat attachments
This commit is contained in:
1 parent
ee25c6b479
commit
2c780b8101
2 files changed
+71
-77
No files matched your search
@@ -64,7 +64,7 @@ export class RocketChatProvider extends NotificationProvider {
|
||||
|
||||
try {
|
||||
await got.post(notification.address, {
|
||||
json: { text: this.buildText(message) },
|
||||
json: this.buildPayload(message),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
@@ -83,34 +83,38 @@ export class RocketChatProvider extends NotificationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private buildText(message: NotificationMessage): string {
|
||||
const lines = [
|
||||
message.content.title,
|
||||
message.content.summary,
|
||||
"",
|
||||
`Monitor: ${message.monitor.name}`,
|
||||
`Type: ${message.monitor.type}`,
|
||||
`Status: ${message.monitor.status}`,
|
||||
`URL: ${message.monitor.url}`,
|
||||
];
|
||||
private buildPayload(message: NotificationMessage): RocketChatPayload {
|
||||
return {
|
||||
text: message.content.summary,
|
||||
attachments: [
|
||||
{
|
||||
color: this.severityColor(message.severity),
|
||||
title: message.content.title,
|
||||
title_link: `${message.clientHost}/infrastructure/${message.monitor.id}`,
|
||||
fields: [
|
||||
{ title: "Monitor", value: message.monitor.name, short: true },
|
||||
{ title: "Type", value: message.monitor.type, short: true },
|
||||
{ title: "Status", value: message.monitor.status, short: true },
|
||||
{ title: "URL", value: message.monitor.url, short: false },
|
||||
],
|
||||
ts: message.content.timestamp.toISOString(),
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
if (message.content.details?.length) {
|
||||
lines.push("", "Details:", ...message.content.details.map((detail) => `- ${detail}`));
|
||||
private severityColor(severity: NotificationMessage["severity"]): string {
|
||||
switch (severity) {
|
||||
case "critical":
|
||||
return "#FF0000";
|
||||
case "warning":
|
||||
return "#FFA500";
|
||||
case "success":
|
||||
return "#00FF00";
|
||||
case "info":
|
||||
return "#0000FF";
|
||||
default:
|
||||
return "#808080";
|
||||
}
|
||||
if (message.content.thresholds?.length) {
|
||||
lines.push(
|
||||
"",
|
||||
"Thresholds:",
|
||||
...message.content.thresholds.map(
|
||||
(threshold) => `- ${threshold.metric.toUpperCase()}: ${threshold.formattedValue} (threshold: ${threshold.threshold}${threshold.unit})`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (message.content.incident) {
|
||||
lines.push("", `Incident: ${message.clientHost}/infrastructure/${message.monitor.id}`);
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user