From c6bc3ce62b7b57d37f207d965b3c12bac62c1855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20P=C3=A9rez?= Date: Wed, 2 Oct 2019 15:42:33 -0500 Subject: [PATCH 1/2] Added simple change to use different channel from the endpoint --- config.js | 3 ++- index.js | 8 +++++--- package-lock.json | 6 +++--- package.json | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/config.js b/config.js index ce51bc7..3f3563d 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,7 @@ module.exports = { kmsEncryptedHookUrl: process.env.KMS_ENCRYPTED_HOOK_URL, // encrypted slack webhook url unencryptedHookUrl: process.env.UNENCRYPTED_HOOK_URL, // unencrypted slack webhook url + slackChannel: process.env.SLACK_CHANNEL, // slack channel services: { elasticbeanstalk: { @@ -27,4 +28,4 @@ module.exports = { } } -} \ No newline at end of file +} diff --git a/index.js b/index.js index c61ab4e..17c605f 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,9 @@ var config = require('./config'); var _ = require('lodash'); var hookUrl; -var baseSlackMessage = {} +var channel = config.slackChannel; + +var baseSlackMessage = {"channel": channel} var postMessage = function(message, callback) { var body = JSON.stringify(message); @@ -412,7 +414,7 @@ var processEvent = function(event, context) { exports.handler = function(event, context) { if (hookUrl) { - processEvent(event, context); + processEvent(event, context); } else if (config.unencryptedHookUrl) { hookUrl = config.unencryptedHookUrl; processEvent(event, context); @@ -430,7 +432,7 @@ exports.handler = function(event, context) { processEvent(event, context); } }); - } else { + }else { context.fail('hook url has not been set.'); } }; diff --git a/package-lock.json b/package-lock.json index d7b1ca2..17c2583 100644 --- a/package-lock.json +++ b/package-lock.json @@ -677,9 +677,9 @@ } }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lru-cache": { "version": "4.1.3", diff --git a/package.json b/package.json index 6e1e021..95eccb1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "lambda-cloudwatch-slack", "version": "0.3.0", "description": "Better Slack notifications for AWS CloudWatch", - "authors": [ + "authors": [ "Christopher Reichert ", "Cody Reichert ", "Alexandr Promakh " @@ -13,7 +13,7 @@ "dependencies": { "aws-sdk": "^2.4.0", "https": "^1.0.0", - "lodash": "^4.15.0", + "lodash": "^4.17.15", "url": "^0.11.0" }, "devDependencies": { From 77231d03ee6d3b2da2629390ec23091adcb639a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20P=C3=A9rez?= Date: Wed, 2 Oct 2019 15:48:56 -0500 Subject: [PATCH 2/2] modify deploy script to include slack_channel enviroment variable --- scripts/deploy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 8c49fc7..d29f7e9 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -3,4 +3,5 @@ NODE_LAMBDA=./node_modules/node-lambda/bin/node-lambda test -s $NODE_LAMBDA || { echo "node-lambda not installed. Run 'npm install' first."; exit 1; } mkdir -p tmp cat .env | grep HOOK_URL > ./tmp/deploy.env -$NODE_LAMBDA deploy --configFile ./tmp/deploy.env \ No newline at end of file +cat .env | grep SLACK_CHANNEL > ./tmp/deploy.env +$NODE_LAMBDA deploy --configFile ./tmp/deploy.env