MCPcopy Create free account
hub / github.com/assertible/lambda-cloudwatch-slack / handleCatchAll

Function handleCatchAll

index.js:314–354  ·  view source on GitHub ↗
(event, context)

Source from the content-addressed store, hash-verified

312};
313
314var handleCatchAll = function(event, context) {
315
316 var record = event.Records[0]
317 var subject = record.Sns.Subject
318 var timestamp = new Date(record.Sns.Timestamp).getTime() / 1000;
319 var message = JSON.parse(record.Sns.Message)
320 var color = "warning";
321
322 if (message.NewStateValue === "ALARM") {
323 color = "danger";
324 } else if (message.NewStateValue === "OK") {
325 color = "good";
326 }
327
328 // Add all of the values from the event message to the Slack message description
329 var description = ""
330 for(key in message) {
331
332 var renderedMessage = typeof message[key] === 'object'
333 ? JSON.stringify(message[key])
334 : message[key]
335
336 description = description + "\n" + key + ": " + renderedMessage
337 }
338
339 var slackMessage = {
340 text: "*" + subject + "*",
341 attachments: [
342 {
343 "color": color,
344 "fields": [
345 { "title": "Message", "value": record.Sns.Subject, "short": false },
346 { "title": "Description", "value": description, "short": false }
347 ],
348 "ts": timestamp
349 }
350 ]
351 }
352
353 return _.merge(slackMessage, baseSlackMessage);
354}
355
356var processEvent = function(event, context) {
357 console.log("sns received:" + JSON.stringify(event, null, 2));

Callers 1

processEventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected