-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (49 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const request = require('request');
const _ = require('lodash');
function dingAppender(_config, layout) {
return (loggingEvent) => {
const dingding = _config.hookUrl;
const title = _.get(_config, 'title', 'Msg From log4js');
let text = layout(loggingEvent, _config.timezoneOffset);
sendToDingding(dingding, title, text);
};
}
function configure(_config, layouts) {
let layout = layouts.basicLayout;
if (_config.layout) {
layout = layouts.layout(_config.layout.type, _config.layout);
}
return dingAppender(_config, layout);
}
/*
* 发送钉钉接口
* */
function sendToDingding(dingding, title, text) {
let rqbody = {
msgtype: "markdown",
markdown: {
title:title,
text: text
}
};
let options = {
url: dingding,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(rqbody)
};
request.post(options, (err, res, body)=>{
if(!err && res.statusCode == 200){
let info = JSON.parse(body);
// console.log(info);
if(info.errcode != 0){
console.error(info);
}
}else{
console.error(err);
}
});
}
module.exports.configure = configure;