diff --git a/libs/dingding-alert.js b/libs/dingding-alert.js index bdc40a9..83e8a20 100644 --- a/libs/dingding-alert.js +++ b/libs/dingding-alert.js @@ -1,10 +1,10 @@ const rp = require('request-promise'); const REG_AT = /@(\d+)/g; -module.exports = (text) => { +module.exports = (text, sendTo) => { let match; + let accessToken = sendTo === 'bjSpider' ? 'ed18d72771bb5df6ee70ee6d59e67d7399f6c5b9a67ebffa06a47c29cc5235c8' : '499f845e894e0aebb6d29ec9f3b186cbb99bfa89cd4347fa4c0e8efd4081ecd5'; const ats = []; - while ((match = REG_AT.exec(text))) { ats.push(match[1]); } @@ -18,9 +18,8 @@ module.exports = (text) => { isAtAll: false } }; - return rp({ - uri: 'https://oapi.dingtalk.com/robot/send?access_token=499f845e894e0aebb6d29ec9f3b186cbb99bfa89cd4347fa4c0e8efd4081ecd5', + uri : 'https://oapi.dingtalk.com/robot/send?access_token='+accessToken, method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' diff --git a/libs/spider.js b/libs/spider.js index 66a25b6..2083b38 100644 --- a/libs/spider.js +++ b/libs/spider.js @@ -4,8 +4,10 @@ const nodeLockup = require('node-lockup'); const chalk = require('chalk'); const {logger} = require('./logger'); +const ddAlert = require('../libs/dingding-alert'); const config = require('../config/index'); +const moment = require('moment'); const detailUrl = 'https://app.poizon.com/api/v1/h5/index/fire/flow/product/detail'; const buyNowInfoUrl = 'https://app.poizon.com/api/v1/h5/inventory/price/h5/queryBuyNowInfo'; @@ -130,6 +132,8 @@ const task = async(options, tick = 1) => { } catch (error) { logger.error(chalk.red(`error:${options}:tick:${tick} ====> ${error}`)); if (tick >= 3) { + var currentime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss') + ddAlert(`监控报警 : ${error} — ${currentime} `, 'bjSpider'); return Promise.resolve({}); } return task(options, tick + 1);