Merge pull request #1 feature-NEWDWH2021-111 into develop
This commit is contained in:
commit
84dacb1d5b
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
lambda/mbj-newdwh2021-staging-NoticeToSlack/package-lock.json
|
||||||
|
lambda/mbj-newdwh2021-staging-NoticeToSlack/node_modules/*
|
||||||
|
lambda/mbj-newdwh2021-staging-PublishFromLog/package-lock.json
|
||||||
|
lambda/mbj-newdwh2021-staging-PublishFromLog/node_modules/*
|
||||||
37
lambda/mbj-newdwh2021-staging-NoticeToSlack/index.js
Normal file
37
lambda/mbj-newdwh2021-staging-NoticeToSlack/index.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"use-strict";
|
||||||
|
|
||||||
|
const request = require("request-promise");
|
||||||
|
exports.handler = (event, context, callback) => {
|
||||||
|
const attaches = event.Records.map(evt => {
|
||||||
|
return {
|
||||||
|
"fallback":`Notification from mbj-newdwh2021 AWS: ${evt.EventSubscriptionArn}`,
|
||||||
|
"pretext":`Notification from mbj-newdwh2021 AWS: ${evt.EventSubscriptionArn}`,
|
||||||
|
"color":"#0000D0",
|
||||||
|
"fields":[
|
||||||
|
{
|
||||||
|
"title": `${evt.Sns.Subject}`,
|
||||||
|
"value": `${evt.Sns.Timestamp}: ${evt.Sns.Message} (MessageId: ${evt.Sns.MessageId})`,
|
||||||
|
"short": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
request({
|
||||||
|
method: "POST",
|
||||||
|
url: process.env.webhookurl,
|
||||||
|
body: {
|
||||||
|
attachments: attaches
|
||||||
|
|
||||||
|
},
|
||||||
|
json: true
|
||||||
|
}).then((body => {
|
||||||
|
callback(null, `Request succeed. ${body}`);
|
||||||
|
})).catch((err) => {
|
||||||
|
callback("failed to request to slack.", {
|
||||||
|
result: "ERROR",
|
||||||
|
event: event,
|
||||||
|
cause: `request failed. ${err}.`
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
};
|
||||||
Binary file not shown.
15
lambda/mbj-newdwh2021-staging-NoticeToSlack/package.json
Normal file
15
lambda/mbj-newdwh2021-staging-NoticeToSlack/package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "mbj-newdwh2021-staging-noticetoslack",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"request": "^2.88.2",
|
||||||
|
"request-promise": "^4.2.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
30
lambda/mbj-newdwh2021-staging-PublishFromLog/index.js
Normal file
30
lambda/mbj-newdwh2021-staging-PublishFromLog/index.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
const zlib = require("zlib");
|
||||||
|
const aws = require("aws-sdk");
|
||||||
|
const sns = new aws.SNS({
|
||||||
|
apiVersion: "2010-03-31",
|
||||||
|
region: 'ap-northeast-1'
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.handler = function(input, context) {
|
||||||
|
var payload = new Buffer.from(input.awslogs.data, 'base64');
|
||||||
|
zlib.gunzip(payload, function(e, result) {
|
||||||
|
if (e) {
|
||||||
|
context.fail(e);
|
||||||
|
} else {
|
||||||
|
result = JSON.parse(result.toString('UTF-8'));
|
||||||
|
const publishMessage = {
|
||||||
|
Subject: `Application Error(or Warning) in ${result.logGroup}/${result.logStream}`,
|
||||||
|
Message: result.logEvents.map((l) => l.message).join('\n'),
|
||||||
|
TopicArn: process.env.topicArn
|
||||||
|
};
|
||||||
|
console.log(publishMessage);
|
||||||
|
|
||||||
|
sns.publish(publishMessage, (err, data) => {
|
||||||
|
console.log(err, data);
|
||||||
|
if(err){
|
||||||
|
context.fail('fail');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
Binary file not shown.
15
lambda/mbj-newdwh2021-staging-PublishFromLog/package.json
Normal file
15
lambda/mbj-newdwh2021-staging-PublishFromLog/package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "mbj-newdwh2021-staging-publishfromlog",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"aws-sdk": "^2.1011.0",
|
||||||
|
"zlib": "^1.0.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user