Permalink
Browse files

added slack integration

  • Loading branch information...
tiger5226 committed Oct 28, 2018
1 parent 36db99d commit 965746b9d26d6461424efbc1efb0e287fc2975bc
Showing with 155 additions and 15 deletions.
  1. +1 −1 .travis.yml
  2. +1 −0 package.json
  3. +6 −5 server/controllers/lighthouse.js
  4. +24 −2 server/index.js
  5. +6 −3 server/utils/chainquery/index.js
  6. +117 −4 yarn.lock
View
@@ -3,4 +3,4 @@ node_js:
- "node"
notifications:
email: false
webhooks: https://lhdev.lbry.tech/autoupdate
webhooks: https://lighthouse.lbry.io/autoupdate
View
@@ -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",
@@ -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
@@ -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',
});
}
@@ -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);
});
});
Oops, something went wrong.

0 comments on commit 965746b

Please sign in to comment.