@oneuptime/common 7.0.3707 → 7.0.3708
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Server/Services/WorkspaceNotificationRuleService.ts +205 -11
- package/Server/Services/WorkspaceProjectAuthTokenService.ts +1 -0
- package/Server/Types/Workflow/Components/BaseModel/OnTriggerBaseModel.ts +18 -7
- package/Server/Utils/Workspace/Slack/Slack.ts +352 -45
- package/Server/Utils/Workspace/Slack/app-manifest.json +9 -4
- package/Server/Utils/Workspace/WorkspaceBase.ts +31 -2
- package/Types/Workflow/Component.ts +1 -0
- package/Types/Workflow/Components/BaseModel.ts +30 -0
- package/Types/Workflow/Components/Manual.ts +10 -0
- package/Types/Workflow/Components/Schedule.ts +1 -0
- package/Types/Workflow/Components/Webhook.ts +26 -0
- package/UI/Components/Workflow/RunForm.tsx +23 -25
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +136 -8
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Services/WorkspaceProjectAuthTokenService.js +1 -0
- package/build/dist/Server/Services/WorkspaceProjectAuthTokenService.js.map +1 -1
- package/build/dist/Server/Types/Workflow/Components/BaseModel/OnTriggerBaseModel.js +14 -5
- package/build/dist/Server/Types/Workflow/Components/BaseModel/OnTriggerBaseModel.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js +251 -36
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +9 -4
- package/build/dist/Server/Utils/Workspace/WorkspaceBase.js +12 -2
- package/build/dist/Server/Utils/Workspace/WorkspaceBase.js.map +1 -1
- package/build/dist/Types/Workflow/Components/BaseModel.js +30 -0
- package/build/dist/Types/Workflow/Components/BaseModel.js.map +1 -1
- package/build/dist/Types/Workflow/Components/Manual.js +10 -0
- package/build/dist/Types/Workflow/Components/Manual.js.map +1 -1
- package/build/dist/Types/Workflow/Components/Schedule.js +1 -0
- package/build/dist/Types/Workflow/Components/Schedule.js.map +1 -1
- package/build/dist/Types/Workflow/Components/Webhook.js +26 -0
- package/build/dist/Types/Workflow/Components/Webhook.js.map +1 -1
- package/build/dist/UI/Components/Workflow/RunForm.js +16 -14
- package/build/dist/UI/Components/Workflow/RunForm.js.map +1 -1
- package/package.json +2 -2
- /package/Server/Utils/Workspace/Slack/{app-manifest-temp.json → app-manifest.example.json} +0 -0
|
@@ -29,8 +29,12 @@ import WorkspaceUserAuthTokenService from "./WorkspaceUserAuthTokenService";
|
|
|
29
29
|
import WorkspaceMessagePayload, {
|
|
30
30
|
WorkspaceMessageBlock,
|
|
31
31
|
} from "../../Types/Workspace/WorkspaceMessagePayload";
|
|
32
|
-
import WorkspaceProjectAuthToken
|
|
32
|
+
import WorkspaceProjectAuthToken, {
|
|
33
|
+
MiscData,
|
|
34
|
+
SlackMiscData,
|
|
35
|
+
} from "../../Models/DatabaseModels/WorkspaceProjectAuthToken";
|
|
33
36
|
import WorkspaceProjectAuthTokenService from "./WorkspaceProjectAuthTokenService";
|
|
37
|
+
import logger from "../Utils/Logger";
|
|
34
38
|
|
|
35
39
|
export interface NotificationFor {
|
|
36
40
|
incidentId?: ObjectID | undefined;
|
|
@@ -44,6 +48,31 @@ export class Service extends DatabaseService<Model> {
|
|
|
44
48
|
super(Model);
|
|
45
49
|
}
|
|
46
50
|
|
|
51
|
+
public getBotUserIdFromprojectAuthToken(data: {
|
|
52
|
+
projectAuthToken: WorkspaceProjectAuthToken;
|
|
53
|
+
workspaceType: WorkspaceType;
|
|
54
|
+
}): string {
|
|
55
|
+
const miscData: MiscData | undefined = data.projectAuthToken.miscData;
|
|
56
|
+
|
|
57
|
+
if (!miscData) {
|
|
58
|
+
throw new BadDataException("Misc data not found in project auth token");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (data.workspaceType === WorkspaceType.Slack) {
|
|
62
|
+
const userId: string = (miscData as SlackMiscData).botUserId;
|
|
63
|
+
|
|
64
|
+
if (!userId) {
|
|
65
|
+
throw new BadDataException(
|
|
66
|
+
"Bot user ID not found in project auth token",
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return userId;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
throw new BadDataException("Workspace type not supported");
|
|
74
|
+
}
|
|
75
|
+
|
|
47
76
|
public async createInviteAndPostToChannelsBasedOnRules(data: {
|
|
48
77
|
projectId: ObjectID;
|
|
49
78
|
notificationRuleEventType: NotificationRuleEventType;
|
|
@@ -53,6 +82,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
53
82
|
}): Promise<{
|
|
54
83
|
channelsCreated: Array<WorkspaceChannel>;
|
|
55
84
|
} | null> {
|
|
85
|
+
logger.debug(
|
|
86
|
+
"WorkspaceNotificationRuleService.createInviteAndPostToChannelsBasedOnRules",
|
|
87
|
+
);
|
|
88
|
+
logger.debug(data);
|
|
89
|
+
|
|
56
90
|
const channelsCreated: Array<WorkspaceChannel> = [];
|
|
57
91
|
|
|
58
92
|
const projectAuths: Array<WorkspaceProjectAuthToken> =
|
|
@@ -60,6 +94,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
60
94
|
projectId: data.projectId,
|
|
61
95
|
});
|
|
62
96
|
|
|
97
|
+
logger.debug("projectAuths");
|
|
98
|
+
logger.debug(projectAuths);
|
|
99
|
+
|
|
63
100
|
if (!projectAuths || projectAuths.length === 0) {
|
|
64
101
|
// do nothing.
|
|
65
102
|
return null;
|
|
@@ -85,10 +122,14 @@ export class Service extends DatabaseService<Model> {
|
|
|
85
122
|
notificationFor: data.notificationFor,
|
|
86
123
|
});
|
|
87
124
|
|
|
125
|
+
logger.debug("notificationRules");
|
|
126
|
+
logger.debug(notificationRules);
|
|
127
|
+
|
|
88
128
|
if (!notificationRules || notificationRules.length === 0) {
|
|
89
129
|
return null;
|
|
90
130
|
}
|
|
91
131
|
|
|
132
|
+
logger.debug("Creating channels based on rules");
|
|
92
133
|
const createdWorkspaceChannels: Array<WorkspaceChannel> =
|
|
93
134
|
await this.createChannelsBasedOnRules({
|
|
94
135
|
projectOrUserAuthTokenForWorkspasce: authToken,
|
|
@@ -100,6 +141,10 @@ export class Service extends DatabaseService<Model> {
|
|
|
100
141
|
notificationEventType: data.notificationRuleEventType,
|
|
101
142
|
});
|
|
102
143
|
|
|
144
|
+
logger.debug("createdWorkspaceChannels");
|
|
145
|
+
logger.debug(createdWorkspaceChannels);
|
|
146
|
+
|
|
147
|
+
logger.debug("Inviting users and teams to channels based on rules");
|
|
103
148
|
await this.inviteUsersAndTeamsToChannelsBasedOnRules({
|
|
104
149
|
projectId: data.projectId,
|
|
105
150
|
projectOrUserAuthTokenForWorkspasce: authToken,
|
|
@@ -114,6 +159,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
114
159
|
),
|
|
115
160
|
});
|
|
116
161
|
|
|
162
|
+
logger.debug("Getting existing channel names from notification rules");
|
|
117
163
|
const existingChannelNames: Array<string> =
|
|
118
164
|
this.getExistingChannelNamesFromNotificationRules({
|
|
119
165
|
notificationRules: notificationRules.map((rule: Model) => {
|
|
@@ -121,14 +167,25 @@ export class Service extends DatabaseService<Model> {
|
|
|
121
167
|
}),
|
|
122
168
|
}) || [];
|
|
123
169
|
|
|
124
|
-
|
|
170
|
+
logger.debug("Existing channel names:");
|
|
171
|
+
logger.debug(existingChannelNames);
|
|
172
|
+
|
|
173
|
+
logger.debug("Adding created channel names to existing channel names");
|
|
125
174
|
for (const channel of createdWorkspaceChannels) {
|
|
126
175
|
if (!existingChannelNames.includes(channel.name)) {
|
|
127
176
|
existingChannelNames.push(channel.name);
|
|
128
177
|
}
|
|
129
178
|
}
|
|
130
179
|
|
|
180
|
+
logger.debug("Final list of channel names to post messages to:");
|
|
181
|
+
logger.debug(existingChannelNames);
|
|
182
|
+
|
|
183
|
+
logger.debug("Posting messages to workspace channels");
|
|
131
184
|
await this.postToWorkspaceChannels({
|
|
185
|
+
workspaceUserId: this.getBotUserIdFromprojectAuthToken({
|
|
186
|
+
projectAuthToken: projectAuth,
|
|
187
|
+
workspaceType: workspaceType,
|
|
188
|
+
}),
|
|
132
189
|
projectOrUserAuthTokenForWorkspasce: authToken,
|
|
133
190
|
workspaceType: workspaceType,
|
|
134
191
|
workspaceMessagePayload: {
|
|
@@ -138,23 +195,34 @@ export class Service extends DatabaseService<Model> {
|
|
|
138
195
|
},
|
|
139
196
|
});
|
|
140
197
|
|
|
198
|
+
logger.debug("Channels created:");
|
|
199
|
+
logger.debug(createdWorkspaceChannels);
|
|
200
|
+
|
|
141
201
|
channelsCreated.push(...createdWorkspaceChannels);
|
|
142
202
|
}
|
|
143
203
|
|
|
204
|
+
logger.debug("Returning created channels");
|
|
144
205
|
return {
|
|
145
206
|
channelsCreated: channelsCreated,
|
|
146
207
|
};
|
|
147
208
|
}
|
|
148
209
|
|
|
149
210
|
public async postToWorkspaceChannels(data: {
|
|
211
|
+
workspaceUserId: string;
|
|
150
212
|
projectOrUserAuthTokenForWorkspasce: string;
|
|
151
213
|
workspaceType: WorkspaceType;
|
|
152
214
|
workspaceMessagePayload: WorkspaceMessagePayload;
|
|
153
215
|
}): Promise<void> {
|
|
216
|
+
logger.debug("postToWorkspaceChannels called with data:");
|
|
217
|
+
logger.debug(data);
|
|
218
|
+
|
|
154
219
|
await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).sendMessage({
|
|
220
|
+
userId: data.workspaceUserId,
|
|
155
221
|
workspaceMessagePayload: data.workspaceMessagePayload,
|
|
156
222
|
authToken: data.projectOrUserAuthTokenForWorkspasce,
|
|
157
223
|
});
|
|
224
|
+
|
|
225
|
+
logger.debug("Message posted to workspace channels successfully");
|
|
158
226
|
}
|
|
159
227
|
|
|
160
228
|
public async inviteUsersAndTeamsToChannelsBasedOnRules(data: {
|
|
@@ -164,11 +232,17 @@ export class Service extends DatabaseService<Model> {
|
|
|
164
232
|
notificationRules: Array<CreateChannelNotificationRule>;
|
|
165
233
|
channelNames: Array<string>;
|
|
166
234
|
}): Promise<void> {
|
|
235
|
+
logger.debug("inviteUsersAndTeamsToChannelsBasedOnRules called with data:");
|
|
236
|
+
logger.debug(data);
|
|
237
|
+
|
|
167
238
|
const inviteUserIds: Array<ObjectID> =
|
|
168
239
|
await this.getUsersIdsToInviteToChannel({
|
|
169
240
|
notificationRules: data.notificationRules,
|
|
170
241
|
});
|
|
171
242
|
|
|
243
|
+
logger.debug("User IDs to invite:");
|
|
244
|
+
logger.debug(inviteUserIds);
|
|
245
|
+
|
|
172
246
|
const workspaceUserIds: Array<string> = [];
|
|
173
247
|
|
|
174
248
|
for (const userId of inviteUserIds) {
|
|
@@ -176,7 +250,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
176
250
|
await this.getWorkspaceUserIdFromOneUptimeUserId({
|
|
177
251
|
projectId: data.projectId,
|
|
178
252
|
workspaceType: data.workspaceType,
|
|
179
|
-
|
|
253
|
+
oneuptimeUserId: userId,
|
|
180
254
|
});
|
|
181
255
|
|
|
182
256
|
if (workspaceUserId) {
|
|
@@ -184,6 +258,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
184
258
|
}
|
|
185
259
|
}
|
|
186
260
|
|
|
261
|
+
logger.debug("Workspace User IDs to invite:");
|
|
262
|
+
logger.debug(workspaceUserIds);
|
|
263
|
+
|
|
187
264
|
await WorkspaceUtil.getWorkspaceTypeUtil(
|
|
188
265
|
data.workspaceType,
|
|
189
266
|
).inviteUsersToChannels({
|
|
@@ -193,19 +270,24 @@ export class Service extends DatabaseService<Model> {
|
|
|
193
270
|
workspaceUserIds: workspaceUserIds,
|
|
194
271
|
},
|
|
195
272
|
});
|
|
273
|
+
|
|
274
|
+
logger.debug("Users invited to channels successfully");
|
|
196
275
|
}
|
|
197
276
|
|
|
198
277
|
public async getWorkspaceUserIdFromOneUptimeUserId(data: {
|
|
199
278
|
projectId: ObjectID;
|
|
200
279
|
workspaceType: WorkspaceType;
|
|
201
|
-
|
|
280
|
+
oneuptimeUserId: ObjectID;
|
|
202
281
|
}): Promise<string | null> {
|
|
282
|
+
logger.debug("getWorkspaceUserIdFromOneUptimeUserId called with data:");
|
|
283
|
+
logger.debug(data);
|
|
284
|
+
|
|
203
285
|
const userAuth: WorkspaceUserAuthToken | null =
|
|
204
286
|
await WorkspaceUserAuthTokenService.findOneBy({
|
|
205
287
|
query: {
|
|
206
288
|
projectId: data.projectId,
|
|
207
289
|
workspaceType: data.workspaceType,
|
|
208
|
-
userId: data.
|
|
290
|
+
userId: data.oneuptimeUserId,
|
|
209
291
|
},
|
|
210
292
|
select: {
|
|
211
293
|
workspaceUserId: true,
|
|
@@ -216,9 +298,13 @@ export class Service extends DatabaseService<Model> {
|
|
|
216
298
|
});
|
|
217
299
|
|
|
218
300
|
if (!userAuth) {
|
|
301
|
+
logger.debug("No userAuth found for given data");
|
|
219
302
|
return null;
|
|
220
303
|
}
|
|
221
304
|
|
|
305
|
+
logger.debug("Found userAuth:");
|
|
306
|
+
logger.debug(userAuth);
|
|
307
|
+
|
|
222
308
|
return userAuth.workspaceUserId?.toString() || null;
|
|
223
309
|
}
|
|
224
310
|
|
|
@@ -229,6 +315,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
229
315
|
channelNameSiffix: string;
|
|
230
316
|
notificationEventType: NotificationRuleEventType;
|
|
231
317
|
}): Promise<Array<WorkspaceChannel>> {
|
|
318
|
+
logger.debug("createChannelsBasedOnRules called with data:");
|
|
319
|
+
logger.debug(data);
|
|
320
|
+
|
|
232
321
|
const createdWorkspaceChannels: Array<WorkspaceChannel> = [];
|
|
233
322
|
const createdChannelNames: Array<string> = [];
|
|
234
323
|
|
|
@@ -239,17 +328,23 @@ export class Service extends DatabaseService<Model> {
|
|
|
239
328
|
notificationEventType: data.notificationEventType,
|
|
240
329
|
});
|
|
241
330
|
|
|
331
|
+
logger.debug("New channel names to be created:");
|
|
332
|
+
logger.debug(newChannelNames);
|
|
333
|
+
|
|
242
334
|
if (!newChannelNames || newChannelNames.length === 0) {
|
|
335
|
+
logger.debug("No new channel names found. Returning empty array.");
|
|
243
336
|
return [];
|
|
244
337
|
}
|
|
245
338
|
|
|
246
339
|
for (const newChannelName of newChannelNames) {
|
|
247
|
-
// if already created then skip it.
|
|
248
340
|
if (createdChannelNames.includes(newChannelName)) {
|
|
341
|
+
logger.debug(
|
|
342
|
+
`Channel name ${newChannelName} already created. Skipping.`,
|
|
343
|
+
);
|
|
249
344
|
continue;
|
|
250
345
|
}
|
|
251
346
|
|
|
252
|
-
|
|
347
|
+
logger.debug(`Creating new channel with name: ${newChannelName}`);
|
|
253
348
|
const channel: WorkspaceChannel =
|
|
254
349
|
await WorkspaceUtil.getWorkspaceTypeUtil(
|
|
255
350
|
data.workspaceType,
|
|
@@ -258,17 +353,25 @@ export class Service extends DatabaseService<Model> {
|
|
|
258
353
|
channelName: newChannelName,
|
|
259
354
|
});
|
|
260
355
|
|
|
261
|
-
|
|
356
|
+
logger.debug("Channel created:");
|
|
357
|
+
logger.debug(channel);
|
|
262
358
|
|
|
359
|
+
createdChannelNames.push(channel.name);
|
|
263
360
|
createdWorkspaceChannels.push(channel);
|
|
264
361
|
}
|
|
265
362
|
|
|
363
|
+
logger.debug("Returning created workspace channels:");
|
|
364
|
+
logger.debug(createdWorkspaceChannels);
|
|
365
|
+
|
|
266
366
|
return createdWorkspaceChannels;
|
|
267
367
|
}
|
|
268
368
|
|
|
269
369
|
public async getUsersIdsToInviteToChannel(data: {
|
|
270
370
|
notificationRules: Array<CreateChannelNotificationRule>;
|
|
271
371
|
}): Promise<Array<ObjectID>> {
|
|
372
|
+
logger.debug("getUsersIdsToInviteToChannel called with data:");
|
|
373
|
+
logger.debug(data);
|
|
374
|
+
|
|
272
375
|
const inviteUserIds: Array<ObjectID> = [];
|
|
273
376
|
|
|
274
377
|
for (const notificationRule of data.notificationRules) {
|
|
@@ -282,6 +385,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
282
385
|
const userIds: Array<ObjectID> =
|
|
283
386
|
workspaceRules.inviteUsersToNewChannel || [];
|
|
284
387
|
|
|
388
|
+
logger.debug("User IDs to invite from rule:");
|
|
389
|
+
logger.debug(userIds);
|
|
390
|
+
|
|
285
391
|
for (const userId of userIds) {
|
|
286
392
|
if (
|
|
287
393
|
!inviteUserIds.find((id: ObjectID) => {
|
|
@@ -304,9 +410,15 @@ export class Service extends DatabaseService<Model> {
|
|
|
304
410
|
return new ObjectID(teamId.toString());
|
|
305
411
|
});
|
|
306
412
|
|
|
413
|
+
logger.debug("Team IDs to invite from rule:");
|
|
414
|
+
logger.debug(teamIds);
|
|
415
|
+
|
|
307
416
|
const usersInTeam: Array<User> =
|
|
308
417
|
await TeamMemberService.getUsersInTeams(teamIds);
|
|
309
418
|
|
|
419
|
+
logger.debug("Users in teams:");
|
|
420
|
+
logger.debug(usersInTeam);
|
|
421
|
+
|
|
310
422
|
for (const user of usersInTeam) {
|
|
311
423
|
if (
|
|
312
424
|
!inviteUserIds.find((id: ObjectID) => {
|
|
@@ -323,12 +435,20 @@ export class Service extends DatabaseService<Model> {
|
|
|
323
435
|
}
|
|
324
436
|
}
|
|
325
437
|
|
|
438
|
+
logger.debug("Final list of user IDs to invite:");
|
|
439
|
+
logger.debug(inviteUserIds);
|
|
440
|
+
|
|
326
441
|
return inviteUserIds;
|
|
327
442
|
}
|
|
328
443
|
|
|
329
444
|
public getExistingChannelNamesFromNotificationRules(data: {
|
|
330
445
|
notificationRules: Array<BaseNotificationRule>;
|
|
331
446
|
}): Array<string> {
|
|
447
|
+
logger.debug(
|
|
448
|
+
"getExistingChannelNamesFromNotificationRules called with data:",
|
|
449
|
+
);
|
|
450
|
+
logger.debug(data);
|
|
451
|
+
|
|
332
452
|
const channelNames: Array<string> = [];
|
|
333
453
|
|
|
334
454
|
for (const notificationRule of data.notificationRules) {
|
|
@@ -338,20 +458,25 @@ export class Service extends DatabaseService<Model> {
|
|
|
338
458
|
const existingChannelNames: Array<string> =
|
|
339
459
|
workspaceRules.existingChannelNames.split(",");
|
|
340
460
|
|
|
461
|
+
logger.debug("Existing channel names from rule:");
|
|
462
|
+
logger.debug(existingChannelNames);
|
|
463
|
+
|
|
341
464
|
for (const channelName of existingChannelNames) {
|
|
342
465
|
if (!channelName) {
|
|
343
|
-
|
|
466
|
+
logger.debug("Empty channel name found. Skipping.");
|
|
344
467
|
continue;
|
|
345
468
|
}
|
|
346
469
|
|
|
347
470
|
if (!channelNames.includes(channelName)) {
|
|
348
|
-
// if channel name is not already added then add it.
|
|
349
471
|
channelNames.push(channelName);
|
|
350
472
|
}
|
|
351
473
|
}
|
|
352
474
|
}
|
|
353
475
|
}
|
|
354
476
|
|
|
477
|
+
logger.debug("Final list of existing channel names:");
|
|
478
|
+
logger.debug(channelNames);
|
|
479
|
+
|
|
355
480
|
return channelNames;
|
|
356
481
|
}
|
|
357
482
|
|
|
@@ -360,11 +485,17 @@ export class Service extends DatabaseService<Model> {
|
|
|
360
485
|
notificationRules: Array<CreateChannelNotificationRule>;
|
|
361
486
|
channelNameSiffix: string;
|
|
362
487
|
}): Array<string> {
|
|
488
|
+
logger.debug("getNewChannelNamesFromNotificationRules called with data:");
|
|
489
|
+
logger.debug(data);
|
|
490
|
+
|
|
363
491
|
const channelNames: Array<string> = [];
|
|
364
492
|
|
|
365
493
|
for (const notificationRule of data.notificationRules) {
|
|
366
494
|
const workspaceRules: CreateChannelNotificationRule = notificationRule;
|
|
367
495
|
|
|
496
|
+
logger.debug("Processing notification rule:");
|
|
497
|
+
logger.debug(workspaceRules);
|
|
498
|
+
|
|
368
499
|
if (
|
|
369
500
|
workspaceRules.shouldCreateNewChannel &&
|
|
370
501
|
workspaceRules.newChannelTemplateName
|
|
@@ -373,16 +504,30 @@ export class Service extends DatabaseService<Model> {
|
|
|
373
504
|
workspaceRules.newChannelTemplateName ||
|
|
374
505
|
`oneuptime-${data.notificationEventType.toLowerCase()}-`;
|
|
375
506
|
|
|
507
|
+
logger.debug("New channel template name:");
|
|
508
|
+
logger.debug(newChannelName);
|
|
509
|
+
|
|
376
510
|
// add suffix and then check if it is already added or not.
|
|
377
511
|
const channelName: string = newChannelName + data.channelNameSiffix;
|
|
378
512
|
|
|
513
|
+
logger.debug("Final channel name with suffix:");
|
|
514
|
+
logger.debug(channelName);
|
|
515
|
+
|
|
379
516
|
if (!channelNames.includes(channelName)) {
|
|
380
517
|
// if channel name is not already added then add it.
|
|
381
518
|
channelNames.push(channelName);
|
|
519
|
+
logger.debug(`Channel name ${channelName} added to the list.`);
|
|
520
|
+
} else {
|
|
521
|
+
logger.debug(
|
|
522
|
+
`Channel name ${channelName} already exists in the list. Skipping.`,
|
|
523
|
+
);
|
|
382
524
|
}
|
|
383
525
|
}
|
|
384
526
|
}
|
|
385
527
|
|
|
528
|
+
logger.debug("Final list of new channel names:");
|
|
529
|
+
logger.debug(channelNames);
|
|
530
|
+
|
|
386
531
|
return channelNames;
|
|
387
532
|
}
|
|
388
533
|
|
|
@@ -391,7 +536,10 @@ export class Service extends DatabaseService<Model> {
|
|
|
391
536
|
workspaceType: WorkspaceType;
|
|
392
537
|
notificationRuleEventType: NotificationRuleEventType;
|
|
393
538
|
}): Promise<Array<Model>> {
|
|
394
|
-
|
|
539
|
+
logger.debug("getNotificationRules called with data:");
|
|
540
|
+
logger.debug(data);
|
|
541
|
+
|
|
542
|
+
const notificationRules: Array<Model> = await this.findBy({
|
|
395
543
|
query: {
|
|
396
544
|
projectId: data.projectId,
|
|
397
545
|
workspaceType: data.workspaceType,
|
|
@@ -406,6 +554,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
406
554
|
skip: 0,
|
|
407
555
|
limit: LIMIT_PER_PROJECT,
|
|
408
556
|
});
|
|
557
|
+
|
|
558
|
+
logger.debug("Notification rules retrieved:");
|
|
559
|
+
logger.debug(notificationRules);
|
|
560
|
+
|
|
561
|
+
return notificationRules;
|
|
409
562
|
}
|
|
410
563
|
|
|
411
564
|
private async getValuesBasedOnNotificationFor(data: {
|
|
@@ -416,7 +569,13 @@ export class Service extends DatabaseService<Model> {
|
|
|
416
569
|
| Array<string>
|
|
417
570
|
| undefined;
|
|
418
571
|
}> {
|
|
572
|
+
logger.debug("getValuesBasedOnNotificationFor called with data:");
|
|
573
|
+
logger.debug(data);
|
|
574
|
+
|
|
419
575
|
if (data.notificationFor.incidentId) {
|
|
576
|
+
logger.debug("Fetching incident details for incident ID:");
|
|
577
|
+
logger.debug(data.notificationFor.incidentId);
|
|
578
|
+
|
|
420
579
|
const incident: Incident | null = await IncidentService.findOneById({
|
|
421
580
|
id: data.notificationFor.incidentId,
|
|
422
581
|
select: {
|
|
@@ -433,9 +592,14 @@ export class Service extends DatabaseService<Model> {
|
|
|
433
592
|
});
|
|
434
593
|
|
|
435
594
|
if (!incident) {
|
|
595
|
+
logger.debug("Incident not found for ID:");
|
|
596
|
+
logger.debug(data.notificationFor.incidentId);
|
|
436
597
|
throw new BadDataException("Incident ID not found");
|
|
437
598
|
}
|
|
438
599
|
|
|
600
|
+
logger.debug("Incident details retrieved:");
|
|
601
|
+
logger.debug(incident);
|
|
602
|
+
|
|
439
603
|
const monitorLabels: Array<Label> =
|
|
440
604
|
await MonitorService.getLabelsForMonitors({
|
|
441
605
|
monitorIds:
|
|
@@ -444,6 +608,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
444
608
|
}) || [],
|
|
445
609
|
});
|
|
446
610
|
|
|
611
|
+
logger.debug("Monitor labels retrieved:");
|
|
612
|
+
logger.debug(monitorLabels);
|
|
613
|
+
|
|
447
614
|
return {
|
|
448
615
|
[NotificationRuleConditionCheckOn.MonitorName]: undefined,
|
|
449
616
|
[NotificationRuleConditionCheckOn.IncidentTitle]: incident.title || "",
|
|
@@ -482,6 +649,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
482
649
|
}
|
|
483
650
|
|
|
484
651
|
if (data.notificationFor.alertId) {
|
|
652
|
+
logger.debug("Fetching alert details for alert ID:");
|
|
653
|
+
logger.debug(data.notificationFor.alertId);
|
|
654
|
+
|
|
485
655
|
const alert: Alert | null = await AlertService.findOneById({
|
|
486
656
|
id: data.notificationFor.alertId,
|
|
487
657
|
select: {
|
|
@@ -498,14 +668,22 @@ export class Service extends DatabaseService<Model> {
|
|
|
498
668
|
});
|
|
499
669
|
|
|
500
670
|
if (!alert) {
|
|
671
|
+
logger.debug("Alert not found for ID:");
|
|
672
|
+
logger.debug(data.notificationFor.alertId);
|
|
501
673
|
throw new BadDataException("Alert ID not found");
|
|
502
674
|
}
|
|
503
675
|
|
|
676
|
+
logger.debug("Alert details retrieved:");
|
|
677
|
+
logger.debug(alert);
|
|
678
|
+
|
|
504
679
|
const monitorLabels: Array<Label> =
|
|
505
680
|
await MonitorService.getLabelsForMonitors({
|
|
506
681
|
monitorIds: alert?.monitor?.id ? [alert?.monitor?.id] : [],
|
|
507
682
|
});
|
|
508
683
|
|
|
684
|
+
logger.debug("Monitor labels retrieved:");
|
|
685
|
+
logger.debug(monitorLabels);
|
|
686
|
+
|
|
509
687
|
return {
|
|
510
688
|
[NotificationRuleConditionCheckOn.MonitorName]: undefined,
|
|
511
689
|
[NotificationRuleConditionCheckOn.IncidentTitle]: undefined,
|
|
@@ -543,6 +721,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
543
721
|
}
|
|
544
722
|
|
|
545
723
|
if (data.notificationFor.scheduledMaintenanceId) {
|
|
724
|
+
logger.debug("Fetching scheduled maintenance details for ID:");
|
|
725
|
+
logger.debug(data.notificationFor.scheduledMaintenanceId);
|
|
726
|
+
|
|
546
727
|
const scheduledMaintenance: ScheduledMaintenance | null =
|
|
547
728
|
await ScheduledMaintenanceService.findOneById({
|
|
548
729
|
id: data.notificationFor.scheduledMaintenanceId,
|
|
@@ -559,9 +740,14 @@ export class Service extends DatabaseService<Model> {
|
|
|
559
740
|
});
|
|
560
741
|
|
|
561
742
|
if (!scheduledMaintenance) {
|
|
743
|
+
logger.debug("Scheduled maintenance not found for ID:");
|
|
744
|
+
logger.debug(data.notificationFor.scheduledMaintenanceId);
|
|
562
745
|
throw new BadDataException("Scheduled Maintenance ID not found");
|
|
563
746
|
}
|
|
564
747
|
|
|
748
|
+
logger.debug("Scheduled maintenance details retrieved:");
|
|
749
|
+
logger.debug(scheduledMaintenance);
|
|
750
|
+
|
|
565
751
|
const monitorLabels: Array<Label> =
|
|
566
752
|
await MonitorService.getLabelsForMonitors({
|
|
567
753
|
monitorIds:
|
|
@@ -572,6 +758,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
572
758
|
) || [],
|
|
573
759
|
});
|
|
574
760
|
|
|
761
|
+
logger.debug("Monitor labels retrieved:");
|
|
762
|
+
logger.debug(monitorLabels);
|
|
763
|
+
|
|
575
764
|
return {
|
|
576
765
|
[NotificationRuleConditionCheckOn.MonitorName]: undefined,
|
|
577
766
|
[NotificationRuleConditionCheckOn.IncidentTitle]: undefined,
|
|
@@ -611,6 +800,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
611
800
|
}
|
|
612
801
|
|
|
613
802
|
if (data.notificationFor.monitorStatusTimelineId) {
|
|
803
|
+
logger.debug("Fetching monitor status timeline details for ID:");
|
|
804
|
+
logger.debug(data.notificationFor.monitorStatusTimelineId);
|
|
805
|
+
|
|
614
806
|
const monitorStatusTimeline: MonitorStatusTimeline | null =
|
|
615
807
|
await MonitorStatusTimelineService.findOneById({
|
|
616
808
|
id: data.notificationFor.monitorStatusTimelineId,
|
|
@@ -628,6 +820,8 @@ export class Service extends DatabaseService<Model> {
|
|
|
628
820
|
});
|
|
629
821
|
|
|
630
822
|
if (!monitorStatusTimeline) {
|
|
823
|
+
logger.debug("Monitor status timeline not found for ID:");
|
|
824
|
+
logger.debug(data.notificationFor.monitorStatusTimelineId);
|
|
631
825
|
throw new BadDataException("Monitor Status Timeline ID not found");
|
|
632
826
|
}
|
|
633
827
|
|
|
@@ -74,7 +74,15 @@ export default class OnTriggerBaseModel<
|
|
|
74
74
|
args: JSONObject,
|
|
75
75
|
options: RunOptions,
|
|
76
76
|
): Promise<RunReturnType> {
|
|
77
|
-
|
|
77
|
+
let data: JSONObject = args["data"] as JSONObject;
|
|
78
|
+
|
|
79
|
+
if (!data) {
|
|
80
|
+
data = {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (args["_id"]) {
|
|
84
|
+
data["_id"] = args["_id"];
|
|
85
|
+
}
|
|
78
86
|
|
|
79
87
|
const miscData: JSONObject = (data?.["miscData"] as JSONObject) || {};
|
|
80
88
|
|
|
@@ -106,14 +114,15 @@ export default class OnTriggerBaseModel<
|
|
|
106
114
|
|
|
107
115
|
let select: Select<TBaseModel> = args["select"] as Select<TBaseModel>;
|
|
108
116
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
logger.debug("Select: ");
|
|
118
|
+
logger.debug(select);
|
|
119
|
+
|
|
120
|
+
if (select && typeof select === "string") {
|
|
121
|
+
select = JSONFunctions.parse(select) as Select<TBaseModel>;
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
const model: TBaseModel | null = await this.service!.findOneById({
|
|
116
|
-
id: new ObjectID(data["_id"]
|
|
125
|
+
id: new ObjectID(data["_id"].toString()),
|
|
117
126
|
props: {
|
|
118
127
|
isRoot: true,
|
|
119
128
|
},
|
|
@@ -124,8 +133,10 @@ export default class OnTriggerBaseModel<
|
|
|
124
133
|
});
|
|
125
134
|
|
|
126
135
|
if (!model) {
|
|
136
|
+
options.log("Model not found with id " + data["_id"].toString());
|
|
137
|
+
|
|
127
138
|
throw new BadDataException(
|
|
128
|
-
("Model not found with id " +
|
|
139
|
+
("Model not found with id " + data["_id"].toString()) as string,
|
|
129
140
|
);
|
|
130
141
|
}
|
|
131
142
|
|