This repository was archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (59 loc) · 1.31 KB
/
index.js
File metadata and controls
67 lines (59 loc) · 1.31 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
55
56
57
58
59
60
61
62
63
64
65
66
67
var request = require('request');
require('array.prototype.find');
var sources = {
token: 'token',
udp: 'syslog'
};
var apiUri = 'https://api.logentries.com';
function api(data, cb) {
var options = {
uri: apiUri,
method: 'POST',
form: data
};
request(options, function(err, res, body) {
if (err) return cb(err);
var result = JSON.parse(body);
if (result.response === 'error') return cb(new Error(result.reason));
return cb(null, result);
});
}
module.exports = function(options) {
return {
getHosts: function(cb) {
api({
request: 'get_user',
load_hosts: 1,
user_key: options.accountKey
}, cb);
},
getHost: function(hostname, cb) {
this.getHosts(function(err, result) {
if (err) return cb(err);
var host = result.hosts.find(function(host) {
return host.name === hostname;
});
return cb(null, host);
});
},
registerHost: function(host, cb) {
api({
request: 'register',
user_key: options.accountKey,
name: host,
hostname: 'nolocation'
}, cb);
},
createLog: function(name, type, hostKey, cb) {
if (!sources[type]) return cb(new Error('Invalid log type.'));
api({
request: 'new_log',
user_key: options.accountKey,
host_key: hostKey,
source: sources[type],
name: name,
retention: '-1'
}, cb);
}
};
};