logs.js
1.56 KB
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
'use strict';
// const capi = new Capi({
// SecretId: 'AKIDKXZR8e2JNGhy9AogEdZKuJXaSAot7X7W',
// SecretKey: 'Mhuw11qY5KPK5fBYxDHAsQnzzpU4Xqzx',
// serviceType: 'logset'
// });
const _ = require('lodash');
const moment = require('moment');
const rp = require('request-promise');
const Model = require('./model');
const qcloud = require('../../lib/qcloud');
let _convert = res => {
res = JSON.parse(res);
let message;
_.each(res.results, (item, idx) => {
message = JSON.parse(JSON.parse(item.content)['__CONTENT__'].message);
res.results[idx].message = message.message;
res.results[idx].level = message.level;
// res.results[idx].t = moment(message.timestamp).format('YYYY-MM-DD HH:mm:ss');
delete res.results[idx].content;
});
return res;
};
class Logs extends Model {
constructor() {
super('logs');
}
async init({query = '', limit = 10}) {
const res = await rp(qcloud.sign({
method: 'get',
baseUrl: 'http://ap-beijing.cls.myqcloud.com',
uri: '/searchlog',
qs: {
logset_id: '3a292186-9241-4d2c-98de-a13896ed7b25',
topic_ids: '3cb90ed6-0f92-40cb-b064-42f36d13b11a',
start_time: moment(Date.now() - 3600 * 1000 * 48).format('YYYY-MM-DD HH:mm:ss'),
end_time: moment().format('YYYY-MM-DD HH:mm:ss'),
query,
limit
},
headers: {}
}, {query, limit}));
return _convert(res)
}
}
module.exports = Logs;