MCPcopy Index your code
hub / github.com/assertible/lambda-cloudwatch-slack / processEvent

Function processEvent

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

Source from the content-addressed store, hash-verified

354}
355
356var processEvent = function(event, context) {
357 console.log("sns received:" + JSON.stringify(event, null, 2));
358 var slackMessage = null;
359 var eventSubscriptionArn = event.Records[0].EventSubscriptionArn;
360 var eventSnsSubject = event.Records[0].Sns.Subject || 'no subject';
361 var eventSnsMessageRaw = event.Records[0].Sns.Message;
362 var eventSnsMessage = null;
363
364 try {
365 eventSnsMessage = JSON.parse(eventSnsMessageRaw);
366 }
367 catch (e) {
368 }
369
370 if(eventSubscriptionArn.indexOf(config.services.codepipeline.match_text) > -1 || eventSnsSubject.indexOf(config.services.codepipeline.match_text) > -1 || eventSnsMessageRaw.indexOf(config.services.codepipeline.match_text) > -1){
371 console.log("processing codepipeline notification");
372 slackMessage = handleCodePipeline(event,context)
373 }
374 else if(eventSubscriptionArn.indexOf(config.services.elasticbeanstalk.match_text) > -1 || eventSnsSubject.indexOf(config.services.elasticbeanstalk.match_text) > -1 || eventSnsMessageRaw.indexOf(config.services.elasticbeanstalk.match_text) > -1){
375 console.log("processing elasticbeanstalk notification");
376 slackMessage = handleElasticBeanstalk(event,context)
377 }
378 else if(eventSnsMessage && 'AlarmName' in eventSnsMessage && 'AlarmDescription' in eventSnsMessage){
379 console.log("processing cloudwatch notification");
380 slackMessage = handleCloudWatch(event,context);
381 }
382 else if(eventSubscriptionArn.indexOf(config.services.codedeploy.match_text) > -1 || eventSnsSubject.indexOf(config.services.codedeploy.match_text) > -1 || eventSnsMessageRaw.indexOf(config.services.codedeploy.match_text) > -1){
383 console.log("processing codedeploy notification");
384 slackMessage = handleCodeDeploy(event,context);
385 }
386 else if(eventSubscriptionArn.indexOf(config.services.elasticache.match_text) > -1 || eventSnsSubject.indexOf(config.services.elasticache.match_text) > -1 || eventSnsMessageRaw.indexOf(config.services.elasticache.match_text) > -1){
387 console.log("processing elasticache notification");
388 slackMessage = handleElasticache(event,context);
389 }
390 else if(eventSubscriptionArn.indexOf(config.services.autoscaling.match_text) > -1 || eventSnsSubject.indexOf(config.services.autoscaling.match_text) > -1 || eventSnsMessageRaw.indexOf(config.services.autoscaling.match_text) > -1){
391 console.log("processing autoscaling notification");
392 slackMessage = handleAutoScaling(event, context);
393 }
394 else{
395 slackMessage = handleCatchAll(event, context);
396 }
397
398 postMessage(slackMessage, function(response) {
399 if (response.statusCode < 400) {
400 console.info('message posted successfully');
401 context.succeed();
402 } else if (response.statusCode < 500) {
403 console.error("error posting message to slack API: " + response.statusCode + " - " + response.statusMessage);
404 // Don't retry because the error is due to a problem with the request
405 context.succeed();
406 } else {
407 // Let Lambda retry
408 context.fail("server error when processing message: " + response.statusCode + " - " + response.statusMessage);
409 }
410 });
411};
412
413exports.handler = function(event, context) {

Callers 1

index.jsFile · 0.85

Calls 8

handleCodePipelineFunction · 0.85
handleElasticBeanstalkFunction · 0.85
handleCloudWatchFunction · 0.85
handleCodeDeployFunction · 0.85
handleElasticacheFunction · 0.85
handleAutoScalingFunction · 0.85
handleCatchAllFunction · 0.85
postMessageFunction · 0.85

Tested by

no test coverage detected