added slack integration

This commit is contained in:
Mark Beamer Jr 2018-10-28 02:28:24 -04:00
parent 36db99ddca
commit 965746b9d2
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973
6 changed files with 155 additions and 15 deletions

View file

@ -3,4 +3,4 @@ node_js:
- "node"
notifications:
email: false
webhooks: https://lhdev.lbry.tech/autoupdate
webhooks: https://lighthouse.lbry.io/autoupdate

View file

@ -56,6 +56,7 @@
"koa-logger": "^2.0.0",
"koa-router": "^7.0.0",
"limited-request-queue": "^3.0.4",
"node-slack": "^0.0.7",
"oas": "^0.8.8",
"ora": "^1.3.0",
"prettysize": "^1.1.0",

View file

@ -8,6 +8,7 @@ import {claimSync} from '../utils/chainquery';
import {getStats} from '../utils/importer';
import crypto from 'crypto';
import got from 'got';
import {logToSlack} from '../index';
const loggerStream = winstonStream(winston, 'info');
@ -441,22 +442,22 @@ class LighthouseControllers {
let status = verifier.verify(travisPublicKey, travisSignature);
if (status) {
let notification = JSON.parse(payload);
if (notification.branch === 'auto_deploy_api') {
if (notification.branch === 'master') {
if (!notification.isPullRequest) {
console.log('Auto Updating Lighthouse - ', notification.message);
logToSlack('Auto Updating Lighthouse - ' + notification.message);
update();
ctx.body = 'OK';
} else {
ctx.status = 400;
ctx.body = 'skip auto update: pull request';
ctx.body = 'skip auto update: pull request'; logToSlack(ctx.body);
}
} else {
ctx.status = 400;
ctx.body = 'only deploys on master branch';
ctx.body = 'skip auto update: only deploys on master branch'; logToSlack(ctx.body);
}
} else {
ctx.status = 500;
ctx.body = 'could not verify webhook';
ctx.body = 'skip auto update: could not verify webhook'; logToSlack(ctx.body);
}
}

View file

@ -6,12 +6,14 @@ import helmet from 'koa-helmet';
import routing from './routes/';
import { port } from './config';
import winston from 'winston';
import slack from 'node-slack';
require('winston-daily-rotate-file');
// Setup logging
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, { colorize: true, timestamp: true, prettyPrint: true });
var slackAPIKey = process.env.SLACK_HOOK_URL;
var mySlack = new slack(slackAPIKey, {});
// Create Koa Application
const app = new Koa();
@ -24,6 +26,26 @@ app
routing(app);
// Start the application
app.listen(port, () => winston.log('info', `Lighthouse API server is running at http://localhost:${port}/`));
app.listen(port, () => logToSlack(`Lighthouse API server is running at http://localhost:${port}/`));
export default app;
export function logToSlack (message) {
winston.log('info', 'SentToSlack: ' + message);
mySlack.send({
text : message,
channel : '#lighthouse-status',
username : 'Lighthouse',
icon_emoji: 'lighthouse',
});
}
export function logErrorToSlack (message) {
winston.log('error', 'SentToSlack: ' + message);
mySlack.send({
text : message,
channel : '#lighthouse-status',
username : 'Lighthouse',
icon_emoji: 'lighthouse',
});
}

View file

@ -12,6 +12,7 @@ import appRoot from 'app-root-path';
import fs from 'fs';
import fileExists from 'file-exists';
import * as util from '../../utils/importer/util';
import {logErrorToSlack} from '../../index';
const elasticsearchloglevel = 'info';
const loggerStream = winstonStream(winston, elasticsearchloglevel);
@ -68,7 +69,7 @@ export async function claimSync () {
await sleep(600000);
claimSync();
} catch (err) {
winston.log(err);
logErrorToSlack(err);
status.err = err;
await sleep(600000);
claimSync();
@ -116,6 +117,7 @@ function getJSON (path) {
return new Promise((resolve, reject) => {
jsonfile.readFile(path, function (err, jsoncontent) {
if (err) {
logErrorToSlack(err);
reject(err);
} else {
resolve(jsoncontent);
@ -127,6 +129,7 @@ function saveJSON (path, obj) {
return new Promise((resolve, reject) => {
jsonfile.writeFile(path, obj, function (err, jsoncontent) {
if (err) {
logErrorToSlack(err);
reject(err);
} else {
resolve();
@ -146,7 +149,7 @@ function getBlockedOutpoints () {
resolve(htmlString);
})
.catch(function (err) {
winston.log('error', '[Importer] Error getting blocked outpoints. ' + err);
logErrorToSlack('[Importer] Error getting blocked outpoints. ' + err);
reject(err);
});
});
@ -174,7 +177,7 @@ function getClaimsSince (time) {
resolve(htmlString);
})
.catch(function (err) {
winston.log('error', '[Importer] Error getting updated claims. ' + err);
logErrorToSlack('[Importer] Error getting updated claims. ' + err);
reject(err);
});
});

121
yarn.lock
View file

@ -74,7 +74,7 @@ ajv@^4.7.0:
co "^4.6.0"
json-stable-stringify "^1.0.1"
ajv@^5.0.1, ajv@^5.1.0:
ajv@^5.0.1, ajv@^5.1.0, ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
dependencies:
@ -284,6 +284,10 @@ aws4@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.7.0.tgz#d4d0e9b9dbfca77bf08eeb0a8a471550fe39e289"
aws4@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
babel-cli@^6.5.1:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.26.0.tgz#502ab54874d7db88ad00b887a06383ce03d002f1"
@ -1298,6 +1302,12 @@ combined-stream@1.0.6, combined-stream@^1.0.5, combined-stream@~1.0.5:
dependencies:
delayed-stream "~1.0.0"
combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.7.tgz#2d1d24317afb8abe95d6d2c0b07b57813539d828"
dependencies:
delayed-stream "~1.0.0"
commander@2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
@ -1477,6 +1487,12 @@ d@1:
dependencies:
es5-ext "^0.10.9"
d@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309"
dependencies:
es5-ext "~0.10.2"
dashdash@^1.12.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0"
@ -1575,6 +1591,15 @@ defer-to-connect@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-1.0.1.tgz#41ec1dd670dc4c6dcbe7e54c9e44d784d025fe63"
deferred@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/deferred/-/deferred-0.7.1.tgz#f65cd3c05683f3df554bf5c153851494811d01f4"
dependencies:
d "~0.1.1"
es5-ext "~0.10.2"
event-emitter "~0.3.1"
next-tick "~0.2.2"
define-property@^0.2.5:
version "0.2.5"
resolved "https://registry.yarnpkg.com/define-property/-/define-property-0.2.5.tgz#c35b1ef918ec3c990f9a5bc57be04aacec5c8116"
@ -1784,6 +1809,14 @@ es5-ext@^0.10.14, es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.14:
es6-symbol "~3.1.1"
next-tick "1"
es5-ext@~0.10.2:
version "0.10.46"
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.46.tgz#efd99f67c5a7ec789baa3daa7f79870388f7f572"
dependencies:
es6-iterator "~2.0.3"
es6-symbol "~3.1.1"
next-tick "1"
es6-iterator@^2.0.1, es6-iterator@~2.0.1, es6-iterator@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.3.tgz#a7de889141a05a94b0854403b2d0a0fbfa98f3b7"
@ -1983,7 +2016,7 @@ etag@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
event-emitter@~0.3.5:
event-emitter@~0.3.1, event-emitter@~0.3.5:
version "0.3.5"
resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39"
dependencies:
@ -2116,6 +2149,10 @@ extend@^3.0.0, extend@~3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
extend@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
external-editor@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-1.1.1.tgz#12d7b0db850f7ff7e7081baf4005700060c4600b"
@ -2338,6 +2375,14 @@ form-data@~2.3.1:
combined-stream "1.0.6"
mime-types "^2.1.12"
form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.6"
mime-types "^2.1.12"
format-util@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.3.tgz#032dca4a116262a12c43f4c3ec8566416c5b2d95"
@ -2645,6 +2690,13 @@ har-validator@~5.0.3:
ajv "^5.1.0"
har-schema "^2.0.0"
har-validator@~5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.1.0.tgz#44657f5688a22cfd4b72486e81b3a3fb11742c29"
dependencies:
ajv "^5.3.0"
har-schema "^2.0.0"
has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
@ -3925,12 +3977,22 @@ mime-db@~1.33.0:
version "1.33.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db"
mime-db@~1.37.0:
version "1.37.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.37.0.tgz#0b6a0ce6fdbe9576e25f1f2d2fde8830dc0ad0d8"
mime-types@^2.0.7, mime-types@^2.1.10, mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.18:
version "2.1.18"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8"
dependencies:
mime-db "~1.33.0"
mime-types@~2.1.19:
version "2.1.21"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.21.tgz#28995aa1ecb770742fe6ae7e58f9181c744b3f96"
dependencies:
mime-db "~1.37.0"
mime@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"
@ -4124,6 +4186,10 @@ next-tick@1:
version "1.0.0"
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
next-tick@~0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-0.2.2.tgz#75da4a927ee5887e39065880065b7336413b310d"
nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
@ -4166,6 +4232,13 @@ node-readfiles@^0.2.0:
dependencies:
es6-promise "^3.2.1"
node-slack@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/node-slack/-/node-slack-0.0.7.tgz#2a022d3b5b47eaaa693fb167fcbfbcad7697ace7"
dependencies:
deferred "0.7.1"
request "~2.x"
node-status@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-status/-/node-status-1.0.0.tgz#7906a7c47a6587d03496bf74ec634abaa03f8e80"
@ -4302,6 +4375,10 @@ oauth-sign@~0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
oauth-sign@~0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
@ -4772,6 +4849,10 @@ pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
psl@^1.1.24:
version "1.1.29"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.29.tgz#60f580d360170bb722a797cc704411e6da850c67"
pstree.remy@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pstree.remy/-/pstree.remy-1.1.0.tgz#f2af27265bd3e5b32bbfcc10e80bac55ba78688b"
@ -4793,7 +4874,7 @@ qs@6.5.1:
version "6.5.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
qs@^6.1.0, qs@~6.5.1:
qs@^6.1.0, qs@~6.5.1, qs@~6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
@ -5196,6 +5277,31 @@ request@^2.81.0:
tunnel-agent "^0.6.0"
uuid "^3.1.0"
request@~2.x:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
dependencies:
aws-sign2 "~0.7.0"
aws4 "^1.8.0"
caseless "~0.12.0"
combined-stream "~1.0.6"
extend "~3.0.2"
forever-agent "~0.6.1"
form-data "~2.3.2"
har-validator "~5.1.0"
http-signature "~1.2.0"
is-typedarray "~1.0.0"
isstream "~0.1.2"
json-stringify-safe "~5.0.1"
mime-types "~2.1.19"
oauth-sign "~0.9.0"
performance-now "^2.1.0"
qs "~6.5.2"
safe-buffer "^5.1.2"
tough-cookie "~2.4.3"
tunnel-agent "^0.6.0"
uuid "^3.3.2"
require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@ -5984,6 +6090,13 @@ tough-cookie@>=2.3.3, tough-cookie@~2.3.3:
dependencies:
punycode "^1.4.1"
tough-cookie@~2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781"
dependencies:
psl "^1.1.24"
punycode "^1.4.1"
tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
@ -6203,7 +6316,7 @@ uuid@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.0.tgz#b237147804881d7b86f40a7ff8f590f15c37de32"
uuid@^3.2.1:
uuid@^3.2.1, uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"