Skip to content

Commit 2591e12

Browse files
committed
Merge branch 'release-1.10.0' into druid-auth-OBS-#I637
2 parents e2a5a1d + e0979dc commit 2591e12

File tree

1 file changed

+17
-0
lines changed
  • api-service/src/services/managers/grafana/alert/helpers

1 file changed

+17
-0
lines changed

api-service/src/services/managers/grafana/alert/helpers/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,27 @@ const getMatchingLabels = async (channels: string[]) => {
244244
}
245245
}
246246

247+
const getNotificationChannel = async (channels: string[]) => {
248+
const fetchChannel = (id: string) => {
249+
return Notification.findOne({ where: { id } })
250+
.then(response => response?.toJSON())
251+
.then(channelMetadata => {
252+
const { name, type } = channelMetadata;
253+
return name;
254+
})
255+
.catch(() => null);
256+
}
257+
258+
const [name] = await Promise.all(channels.map(fetchChannel));
259+
return name;
260+
}
261+
247262
const transformRule = async ({ value, condition, metadata, isGroup }: any) => {
248263
const { name, id, interval, category, frequency, labels = {}, annotations = {}, severity, description, notification = {} } = value;
249264
const annotationObj = { ...annotations, description: description };
250265
const channels = _.get(notification, "channels") || [];
251266
const matchingLabelsForNotification = await getMatchingLabels(channels);
267+
const channel = await getNotificationChannel(channels);
252268

253269
const payload = {
254270
grafana_alert: {
@@ -258,6 +274,7 @@ const transformRule = async ({ value, condition, metadata, isGroup }: any) => {
258274
exec_err_state: _.get(metadata, "exec_err_state", "Error"),
259275
data: metadata,
260276
is_paused: false,
277+
...(channel && { notification_settings: { receiver: channel } })
261278
},
262279
for: interval,
263280
annotations: annotationObj,

0 commit comments

Comments
 (0)