refactor: upload check label when monitor empty

This commit is contained in:
guguji5 2023-08-30 16:43:06 +08:00
parent c4e222d1e6
commit 6346e0db52

View file

@ -59,6 +59,17 @@ class FlashDuty extends NotificationProvider {
* @returns {string} * @returns {string}
*/ */
async postNotification(notification, title, body, monitorInfo, eventStatus) { async postNotification(notification, title, body, monitorInfo, eventStatus) {
let labels = {
resource: this.genMonitorUrl(monitorInfo),
check: monitorInfo.name,
};
if (monitorInfo?.tags?.length > 0) {
labels = monitorInfo?.tags?.reduce(
(acc, item) => ({ ...acc,
[item.name]: item.value }),
labels
);
}
const options = { const options = {
method: "POST", method: "POST",
url: "https://api.flashcat.cloud/event/push/alert/standard?integration_key=" + notification.flashdutyIntegrationKey, url: "https://api.flashcat.cloud/event/push/alert/standard?integration_key=" + notification.flashdutyIntegrationKey,
@ -68,9 +79,7 @@ class FlashDuty extends NotificationProvider {
title, title,
event_status: eventStatus || "Info", event_status: eventStatus || "Info",
alert_key: String(monitorInfo.id) || Math.random().toString(36).substring(7), alert_key: String(monitorInfo.id) || Math.random().toString(36).substring(7),
labels: monitorInfo?.tags?.reduce((acc, item) => ({ ...acc, labels,
[item.name]: item.value
}), { resource: this.genMonitorUrl(monitorInfo) }),
} }
}; };