This repository has been archived by the owner on Jul 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogentries.js
70 lines (61 loc) · 1.86 KB
/
logentries.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
64
65
66
67
68
69
70
// TODO: in readme to logentries-api it's stated accessKey, the correct is accountKey
const leApi = require('logentries-api')({ accountKey: process.env.LOGENTRIES_API_KEY });
const hl = require('highland');
const LOG_TYPE = 'udp';
module.exports = {
list: list,
get: (hostname) => get(hostname),
createLog: createLog,
createHost: createHost,
createLogAndHost: createLogAndHost,
}
function list() {
leApi.getHosts(function(err, result) {
if (err) console.log('err', err);
else console.log('list:',result);
});
}
function get(name) {
leApi.getHost(name, function(err, result) {
if (err) console.log('err', err);
else console.log('get name:', name, '\n', result);
});
}
// input a app object. Where app.name will be used as the log and host name.
// outputs a highland stream of data
function createLogAndHost(app) {
return hl(function (push, next) {
leApi.registerHost(app.name, function (err, data) {
if(err) {
push(err, { app: app, logs: data })
return push(null, hl.nil);
}
leApi.createLog(
app.name,
LOG_TYPE,
data.host_key,
(error, logData) => {
push(err, {
app: app,
logData: logData
});
push(null, hl.nil);
});
});
});
}
function createHost(hostname) {
leApi.registerHost(hostname, function(err, result) {
if (err) console.log('err', err);
else console.log('Created host:', hostname, '\n', result);
});
}
function createLog(logName, logType, hostKey) {
console.log('logName: ', logName);
console.log('logType: ', logType);
console.log('hostKey: ', hostKey);
leApi.createLog(logName, logType, hostKey, function(err, result) {
if (err) console.log('err', err);
else console.log('Created log:', logName, '\n', result);
});
}