@gus-eip/loggers 4.2.6 → 4.2.7
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/dist/cloudwatch.logger.js +110 -34
- package/dist/test.d.ts +2 -0
- package/dist/test.js +168 -0
- package/package.json +1 -1
|
@@ -152,7 +152,9 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
|
152
152
|
entityKey: fullLogObject.entityKey || '',
|
|
153
153
|
event: fullLogObject.event || '',
|
|
154
154
|
status,
|
|
155
|
-
message: type === 'error'
|
|
155
|
+
message: type === 'error'
|
|
156
|
+
? fullLogObject.errorMessage
|
|
157
|
+
: fullLogObject.logMessage,
|
|
156
158
|
logGroupName: this.logGroupName,
|
|
157
159
|
};
|
|
158
160
|
const sqsUrl = await ssm_utils_1.ssmUtils.getSqsUrl();
|
|
@@ -199,40 +201,114 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
|
199
201
|
: typeof summary === 'object'
|
|
200
202
|
? JSON.stringify(summary)
|
|
201
203
|
: summary;
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
204
|
+
const awsLogUrl = `https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/${this.logGroupName}/log-events/${logStreamName}`;
|
|
205
|
+
const isPowerAutomate = webhookUrl.includes('powerautomate');
|
|
206
|
+
const alertMessage = isPowerAutomate
|
|
207
|
+
? {
|
|
208
|
+
attachments: [
|
|
209
|
+
{
|
|
210
|
+
contentType: 'application/vnd.microsoft.card.adaptive',
|
|
211
|
+
content: {
|
|
212
|
+
type: 'AdaptiveCard',
|
|
213
|
+
version: '1.4',
|
|
214
|
+
body: [
|
|
215
|
+
{
|
|
216
|
+
type: 'TextBlock',
|
|
217
|
+
text: `🚨 ${title} 🚨`,
|
|
218
|
+
weight: 'Bolder',
|
|
219
|
+
size: 'Large',
|
|
220
|
+
color: type === 'Error'
|
|
221
|
+
? 'Attention'
|
|
222
|
+
: type === 'Warning'
|
|
223
|
+
? 'Warning'
|
|
224
|
+
: 'Good',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
type: 'TextBlock',
|
|
228
|
+
text: `Handler: ${handler}`,
|
|
229
|
+
wrap: true,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: 'TextBlock',
|
|
233
|
+
text: `Timestamp: ${timestamp}`,
|
|
234
|
+
wrap: true,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
type: 'TextBlock',
|
|
238
|
+
text: `Type: ${type}`,
|
|
239
|
+
wrap: true,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
type: 'Container',
|
|
243
|
+
items: summary.map((item) => ({
|
|
244
|
+
type: 'Container',
|
|
245
|
+
items: Object.entries(item).map(([key, value]) => ({
|
|
246
|
+
type: 'ColumnSet',
|
|
247
|
+
columns: [
|
|
248
|
+
{
|
|
249
|
+
type: 'Column',
|
|
250
|
+
width: 'auto',
|
|
251
|
+
items: [
|
|
252
|
+
{
|
|
253
|
+
type: 'TextBlock',
|
|
254
|
+
text: key,
|
|
255
|
+
weight: 'Bolder',
|
|
256
|
+
wrap: true,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
type: 'Column',
|
|
262
|
+
width: 'stretch',
|
|
263
|
+
items: [
|
|
264
|
+
{
|
|
265
|
+
type: 'TextBlock',
|
|
266
|
+
text: typeof value === 'object'
|
|
267
|
+
? JSON.stringify(value, null, 2)
|
|
268
|
+
: String(value !== null && value !== void 0 ? value : ''),
|
|
269
|
+
wrap: true,
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
})),
|
|
275
|
+
separator: true,
|
|
276
|
+
})),
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
actions: [
|
|
280
|
+
{
|
|
281
|
+
type: 'Action.OpenUrl',
|
|
282
|
+
title: '🔍 View AWS Logs',
|
|
283
|
+
url: awsLogUrl,
|
|
284
|
+
},
|
|
285
|
+
],
|
|
230
286
|
},
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
}
|
|
290
|
+
: {
|
|
291
|
+
'@type': 'MessageCard',
|
|
292
|
+
'@context': 'http://schema.org/extensions',
|
|
293
|
+
summary: 'System Alert',
|
|
294
|
+
themeColor: 'FF0000',
|
|
295
|
+
title: `🚨 ${title} 🚨`,
|
|
296
|
+
sections: [
|
|
297
|
+
{
|
|
298
|
+
facts: [
|
|
299
|
+
{ name: 'summary:', value: summaryMsg },
|
|
300
|
+
{ name: 'component:', value: handler },
|
|
301
|
+
{ name: 'timestamp:', value: timestamp },
|
|
302
|
+
{ name: 'type:', value: type },
|
|
303
|
+
{
|
|
304
|
+
name: '',
|
|
305
|
+
value: `[Click here for more details](${awsLogUrl})`,
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
markdown: true,
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
};
|
|
236
312
|
try {
|
|
237
313
|
await axios_1.default.post(webhookUrl, alertMessage, {
|
|
238
314
|
headers: {
|
package/dist/test.d.ts
ADDED
package/dist/test.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
async function sendNotificationtoTeams(title, summary, handler, logStreamName, isFormattingRequired = true, type) {
|
|
3
|
+
console.log('Notification summary', summary);
|
|
4
|
+
const webhookUrl = 'https://gus.webhook.office.com/webhookb2/a7847242-acac-4b2e-9d64-a3818681a2ec@5665ee7a-3634-4975-9c21-2778cda48edd/IncomingWebhook/6b32fef8240843359b1b3e902fb4d716/e06d3c50-7be6-44a2-87e7-48a4696d8297/V26sOW3X1erzRoeQSKP8rq1toiHD1Qtr41icu1ZxSHyh01';
|
|
5
|
+
const timestamp = new Date().toISOString();
|
|
6
|
+
let headers;
|
|
7
|
+
let headerRow;
|
|
8
|
+
let separatorRow;
|
|
9
|
+
let rows;
|
|
10
|
+
let formattedSummary;
|
|
11
|
+
if (isFormattingRequired) {
|
|
12
|
+
headers = Object.keys(summary[0]);
|
|
13
|
+
headerRow = `| ${headers.join(' | ')} |`;
|
|
14
|
+
separatorRow = `| ${headers.map(() => '---').join(' | ')} |`;
|
|
15
|
+
rows = summary
|
|
16
|
+
.map((item) => `| ${headers.map((header) => item[header] || '').join(' | ')} |`)
|
|
17
|
+
.join('\n');
|
|
18
|
+
formattedSummary = [headerRow, separatorRow, rows].join('\n');
|
|
19
|
+
}
|
|
20
|
+
const summaryMsg = isFormattingRequired
|
|
21
|
+
? formattedSummary
|
|
22
|
+
: typeof summary === 'object'
|
|
23
|
+
? JSON.stringify(summary)
|
|
24
|
+
: summary;
|
|
25
|
+
const awsLogUrl = `https://eu-west-1.console.aws.amazon.com/cloudwatch/home?region=eu-west-1#logsV2:log-groups/log-group/${this.logGroupName}/log-events/${logStreamName}`;
|
|
26
|
+
const isPowerAutomate = webhookUrl.includes('powerautomate');
|
|
27
|
+
const alertMessage = isPowerAutomate
|
|
28
|
+
? {
|
|
29
|
+
attachments: [
|
|
30
|
+
{
|
|
31
|
+
contentType: 'application/vnd.microsoft.card.adaptive',
|
|
32
|
+
content: {
|
|
33
|
+
type: 'AdaptiveCard',
|
|
34
|
+
version: '1.4',
|
|
35
|
+
body: [
|
|
36
|
+
{
|
|
37
|
+
type: 'TextBlock',
|
|
38
|
+
text: `🚨 ${title} 🚨`,
|
|
39
|
+
weight: 'Bolder',
|
|
40
|
+
size: 'Large',
|
|
41
|
+
color: type === 'Error'
|
|
42
|
+
? 'Attention'
|
|
43
|
+
: type === 'Warning'
|
|
44
|
+
? 'Warning'
|
|
45
|
+
: 'Good',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'TextBlock',
|
|
49
|
+
text: `Handler: ${handler}`,
|
|
50
|
+
wrap: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'TextBlock',
|
|
54
|
+
text: `Timestamp: ${timestamp}`,
|
|
55
|
+
wrap: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: 'TextBlock',
|
|
59
|
+
text: `Type: ${type}`,
|
|
60
|
+
wrap: true,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'Container',
|
|
64
|
+
items: summary.map((item) => ({
|
|
65
|
+
type: 'Container',
|
|
66
|
+
items: Object.entries(item).map(([key, value]) => ({
|
|
67
|
+
type: 'ColumnSet',
|
|
68
|
+
columns: [
|
|
69
|
+
{
|
|
70
|
+
type: 'Column',
|
|
71
|
+
width: 'auto',
|
|
72
|
+
items: [
|
|
73
|
+
{
|
|
74
|
+
type: 'TextBlock',
|
|
75
|
+
text: key,
|
|
76
|
+
weight: 'Bolder',
|
|
77
|
+
wrap: true,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'Column',
|
|
83
|
+
width: 'stretch',
|
|
84
|
+
items: [
|
|
85
|
+
{
|
|
86
|
+
type: 'TextBlock',
|
|
87
|
+
text: typeof value === 'object'
|
|
88
|
+
? JSON.stringify(value, null, 2)
|
|
89
|
+
: String(value !== null && value !== void 0 ? value : ''),
|
|
90
|
+
wrap: true,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
})),
|
|
96
|
+
separator: true,
|
|
97
|
+
})),
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
actions: [
|
|
101
|
+
{
|
|
102
|
+
type: 'Action.OpenUrl',
|
|
103
|
+
title: '🔍 View AWS Logs',
|
|
104
|
+
url: awsLogUrl,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
}
|
|
111
|
+
: {
|
|
112
|
+
'@type': 'MessageCard',
|
|
113
|
+
'@context': 'http://schema.org/extensions',
|
|
114
|
+
summary: 'System Alert',
|
|
115
|
+
themeColor: type === 'Error'
|
|
116
|
+
? 'FF0000'
|
|
117
|
+
: type === 'Warning'
|
|
118
|
+
? 'FFFF00'
|
|
119
|
+
: '00FF00',
|
|
120
|
+
title: `🚨 ${title} 🚨`,
|
|
121
|
+
sections: [
|
|
122
|
+
{
|
|
123
|
+
facts: [
|
|
124
|
+
{ name: 'summary:', value: summaryMsg },
|
|
125
|
+
{ name: 'component:', value: handler },
|
|
126
|
+
{ name: 'timestamp:', value: timestamp },
|
|
127
|
+
{ name: 'type:', value: type },
|
|
128
|
+
{
|
|
129
|
+
name: '',
|
|
130
|
+
value: `[Click here for more details](${awsLogUrl})`,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
markdown: true,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
try {
|
|
138
|
+
await axios.post(webhookUrl, alertMessage, {
|
|
139
|
+
headers: {
|
|
140
|
+
'Content-Type': 'application/json',
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
console.log('Message sent successfully');
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Error sending message:', error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
(async () => {
|
|
150
|
+
await sendNotificationtoTeams('Test Alert', [
|
|
151
|
+
{
|
|
152
|
+
job: 'gus-dlq-alert-job',
|
|
153
|
+
runStatus: 'Started',
|
|
154
|
+
ErrorsCount: 0,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
job: 'kyb-kyc-event-listener',
|
|
158
|
+
totalhrsRun: 24,
|
|
159
|
+
listenerErrorsCount: 0,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
job: 'kyb-kyc-verification-process',
|
|
163
|
+
screeningEnquiryCount: 0,
|
|
164
|
+
screeningEnquiryFeedbackCount: 0,
|
|
165
|
+
sfErrorsCount: 0,
|
|
166
|
+
},
|
|
167
|
+
], 'ZoomToBoxSyncHandler', 'TestStream123', true, 'Error');
|
|
168
|
+
})();
|
package/package.json
CHANGED