Skip to content

Commit 9b1320f

Browse files
committed
slack webhook
1 parent 8cfdbb2 commit 9b1320f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

database-connect/keys.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = function (){
1818
globalSettings : "_Settings",
1919
analyticsKey : "109eb359-3d22-4165-9e21-21439637f975",
2020
logToken : "c064fc7e-4fc6-41e6-b51f-32c30deafdcc",
21-
logglySubDomain : "cloudboost"
21+
logglySubDomain : "cloudboost",
22+
slackWebHook : process.env['SLACK_WEBHOOK']
2223
};
2324
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"uuid": "^2.0.1",
6565
"web-push": "^2.1.1",
6666
"winston": "^1.1.2",
67+
"winston-bishop-slack": "^0.2.1",
6768
"winston-loggly": "^1.1.0",
6869
"wns": "^0.5.3"
6970
},

server.js

+27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ global.mongoDisconnected = false;
2020
global.winston = require('winston');
2121
expressWinston = require('express-winston');
2222
require('winston-loggly');
23+
var slack = require('winston-bishop-slack').Slack;
24+
var util = require('util');
2325

2426
global.keys = require('./database-connect/keys.js')();
2527

@@ -36,6 +38,31 @@ global.winston.add(global.winston.transports.Loggly, {
3638
json: true
3739
});
3840

41+
// add slack transport if API key found
42+
if(global.keys.slackWebHook){
43+
var envVal = process.env["IS_STAGING"] ? 'STAGING' : 'PRODUCTION'
44+
global.winston.add(slack, {
45+
webhook_url: global.keys.slackWebHook,
46+
icon_url: "https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-128.png",
47+
channel: "#devlogs",
48+
username: "API ERROR BOT - " + envVal,
49+
level: 'error',
50+
handleExceptions: true,
51+
customFormatter: function(level, message, meta) {
52+
return { attachments: [ {
53+
fallback: "An Error occured on API POD in - " + envVal,
54+
pretext: "An Error occured on API POD in - " + envVal,
55+
color: '#D00000',
56+
fields: [{
57+
title: util.format(":scream_cat: %s", 'Critical Error'),
58+
value: meta.error,
59+
short: false
60+
}]
61+
}]}
62+
}
63+
})
64+
}
65+
3966
global.keyService = require('./database-connect/keyService.js');
4067

4168
global.q = require('q');

0 commit comments

Comments
 (0)