Created
February 2, 2016 09:49
-
-
Save megastef/bc57592f8a664f22d231 to your computer and use it in GitHub Desktop.
Index Slack Messages in Elasticsearch / Logsene
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export SLACK_TOKEN=slack_token_here # https://api.slack.com/web | |
export LOGSENE_TOKEN=logsene_token_here # https://sematext.com/logsene | |
export LOGSENE_URL=https://logsene-receiver.sematext.com:443 | |
node ./slack.js $SLACK_TOKEN | logagent -t $LOGSENE_TOKEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-get install nodejs | |
npm install slack-client | |
npm install logagent-js -g | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// API Token from https://api.slack.com/web | |
function slackClient (apiToken) { | |
var Slack, autoMark, autoReconnect, slack, slackToken | |
Slack = require('slack-client') | |
slackToken = apiToken; autoReconnect = true | |
autoMark = true | |
slack = new Slack(slackToken, autoReconnect, autoMark) | |
slack.on('open', function () { | |
return console.log('Connected to ' + slack.team.name + ' as @' + slack.self.name) | |
}) | |
slack.on('message', function (message) { | |
var channel = slack.getChannelGroupOrDMByID(message.channel) | |
var u = slack.getUserByID(message.user) | |
if (!u) { | |
u = {} | |
} | |
if (!u.profile) { | |
u.profile = {} | |
} | |
return console.log( | |
JSON.stringify({ | |
userName: u.name, | |
userImage: u.profile.image_48, | |
userFirstName: u.profile.first_name, | |
userLastName: u.profile.last_name, | |
channel: channel.name, | |
message: message.text, | |
'@timestamp': new Date()})) | |
}) | |
slack.on('error', function (err) { | |
return console.error('Error', err) | |
}) | |
slack.login() | |
} | |
slackClient(process.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment