-
Notifications
You must be signed in to change notification settings - Fork 0
/
tremor-elastic
executable file
·47 lines (39 loc) · 1.1 KB
/
tremor-elastic
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
#!/usr/bin/env node
var log = require("leg")(process.stdout),
Tremor = require("tremor"),
package = require("./package.json"),
request = require("request");
if (process.argv.length !== 4) {
console.warn("Usage: tremor-elastic <elasticsearch url> <glob>");
process.exit(1);
}
var elasticSearch = process.argv[2],
glob = process.argv[3];
var tremor = new Tremor({glob: glob});
tremor.on("following", function(o) {
log.info("following file", {name: o.name, file: o.file});
});
tremor.on("data", function(o) {
request({method: "POST", uri: elasticSearch, json: o}, function(err, res, data) {
if (err) {
// disabled for now
//return log.warn("couldn't submit entry", {err: err, input: o});
return;
}
if (res.statusCode !== 201) {
// disabled for now
//return log.warn("invalid response from elasticsearch", {code: res.statusCode, input: o, data: data});
return;
}
});
});
log.info("successfully started", {
package: {
name: package.name,
version: package.version,
},
config: {
elasticSearch: elasticSearch,
glob: glob,
},
});