Skip to content

Commit

Permalink
reporting to slack
Browse files Browse the repository at this point in the history
Former-commit-id: 806c819
  • Loading branch information
AndreyKozlov1984 committed Aug 1, 2018
1 parent 27fbc7e commit 29215e5
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
23 changes: 23 additions & 0 deletions tools/reportToSlack.js
@@ -0,0 +1,23 @@
import rp from 'request-promise';

const url = `https://hooks.slack.com/services/${process.env.SLACK_CHANNEL}`;
console.info(process.env.ERROR_STATUS);
const errorStatus = process.env.ERROR_STATUS === '0' ? 'SUCCESS' : 'FAILURE'
const payload = {
text: `Update from ${new Date().toISOString()} finished with ${errorStatus}`,
attachments: [{
title: 'Log File: (update.log)',
text: require('fs').readFileSync(process.env.LOGFILE_PATH, 'utf-8')
}]
};

async function main() {
const result = await rp({
method: 'POST',
json: payload,
url: url
});
console.info(result);

}
main();
81 changes: 81 additions & 0 deletions tools/reportToSlackTest.js
@@ -0,0 +1,81 @@
import rp from 'request-promise';

const url = `https://hooks.slack.com/services/${process.env.SLACK_CHANNEL}`;
const payload = {
text: 'Test',
attachments: [{
title: 'Example log file',
fields: [{
title: 'Status',
value: 'Warning'
}, {
title: 'Crunchbase warnings: ',
value: '5'
}, {
title: 'Github warnings: ',
value: '-'
}, {
title: 'Badge warnings: ',
value: '-'
}],
text: `
Fetching crunchbase entries
***E**E************************************************E***********************************************************************************E*************************************************E************
**********************************************************************************************************************************************************************************************************
*************************************************************************E**********************************************************************************
Using cached entry, because can not fetch: accenture Can't resolve stock ticker ACNN; please manually a 0 [ 'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please
manually a',
'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a',
'Using cached entry, because can not fetch: tencent Can\'t resolve stock ticker 0700; please manually a',
'Using cached entry, because can not fetch: rackspace Cannot read property \'raw\' of undefined',
'Using cached entry, because can not fetch: octo-technology Can\'t resolve stock ticker ALOCT; please manually ',
'Using cached entry, because can not fetch: callidus-software Cannot read property \'raw\' of undefined' ]
Using cached entry, because can not fetch: accenture Can't resolve stock ticker ACNN; please manually a 1 [ 'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please
manually a',
'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a',
'Using cached entry, because can not fetch: tencent Can\'t resolve stock ticker 0700; please manually a',
'Using cached entry, because can not fetch: rackspace Cannot read property \'raw\' of undefined',
'Using cached entry, because can not fetch: octo-technology Can\'t resolve stock ticker ALOCT; please manually ',
'Using cached entry, because can not fetch: callidus-software Cannot read property \'raw\' of undefined' ]
Using cached entry, because can not fetch: tencent Can't resolve stock ticker 0700; please manually a 2 [ 'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please m
anually a',
'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a',
'Using cached entry, because can not fetch: tencent Can\'t resolve stock ticker 0700; please manually a',
'Using cached entry, because can not fetch: rackspace Cannot read property \'raw\' of undefined',
'Using cached entry, because can not fetch: octo-technology Can\'t resolve stock ticker ALOCT; please manually ',
'Using cached entry, because can not fetch: callidus-software Cannot read property \'raw\' of undefined' ]
Using cached entry, because can not fetch: rackspace Cannot read property 'raw' of undefined 3 [ 'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a
',
'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a',
'Using cached entry, because can not fetch: tencent Can\'t resolve stock ticker 0700; please manually a',
'Using cached entry, because can not fetch: rackspace Cannot read property \'raw\' of undefined',
'Using cached entry, because can not fetch: octo-technology Can\'t resolve stock ticker ALOCT; please manually ',
'Using cached entry, because can not fetch: callidus-software Cannot read property \'raw\' of undefined' ]
Using cached entry, because can not fetch: octo-technology Can't resolve stock ticker ALOCT; please manually 4 [ 'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN;
please manually a',
'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a',
'Using cached entry, because can not fetch: tencent Can\'t resolve stock ticker 0700; please manually a',
'Using cached entry, because can not fetch: rackspace Cannot read property \'raw\' of undefined',
'Using cached entry, because can not fetch: octo-technology Can\'t resolve stock ticker ALOCT; please manually ',
'Using cached entry, because can not fetch: callidus-software Cannot read property \'raw\' of undefined' ]
Using cached entry, because can not fetch: callidus-software Cannot read property 'raw' of undefined 5 [ 'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please ma
nually a',
'Using cached entry, because can not fetch: accenture Can\'t resolve stock ticker ACNN; please manually a',
'Using cached entry, because can not fetch: tencent Can\'t resolve stock ticker 0700; please manually a',
'Using cached entry, because can not fetch: rackspace Cannot read property \'raw\' of undefined',
'Using cached entry, because can not fetch: octo-technology Can\'t resolve stock ticker ALOCT; please manually ',
'Using cached entry, because can not fetch: callidus-software Cannot read property \'raw\' of undefined' ]
`
}]
};

async function main() {
const result = await rp({
method: 'POST',
json: payload,
url: url
});
console.info(result);

}
main();
5 changes: 3 additions & 2 deletions update_server/setup.bash
Expand Up @@ -24,7 +24,7 @@ which yarn || (
apt-get update && apt-get -y install yarn
)
echo '
0 0 * * * root bash -l -c "bash /root/update.sh >> /root/update.log"
0 0 * * * root bash -l -c "bash /root/update.sh"
' > /etc/cron.d/updater
echo '
set -e
Expand All @@ -37,7 +37,8 @@ echo '
' > /root/real_update.sh
echo '
set -e
bash /root/real_update.sh || bash /root/real_update.sh || bash root/real_update.sh
(bash /root/real_update.sh || bash /root/real_update.sh || bash root/real_update.sh) > /root/update.log
ERROR_STATUS=$? LOGFILE_PATH=/root/update.log (cd /repo && ./node_modules/.bin/babel-node tools/reportToSlack.js)
' > /root/update.sh
EOSSH

0 comments on commit 29215e5

Please sign in to comment.