-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (38 loc) · 955 Bytes
/
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
const numerify = require('./lib/numerify');
const { pattern } = require('./lib/pattern');
const NUMERIC_FIELDS = [
'shard',
'took_millis',
'total_hits',
'total_shards'
];
module.exports = (string) => {
const match = pattern.exec(string);
if (!match) {
return {};
}
const [, timestamp, severity, source, node, index, shard, took, took_millis, total_hits, types, stats, search_type, total_shards, query, id] = match;
return process({
timestamp,
severity,
source,
node,
index,
shard,
took,
took_millis,
total_hits,
types,
stats,
search_type,
total_shards,
query,
id
});
};
function process(entry) {
// convert elasticsearch timestamp to unix timestamp
entry.timestamp = Date.parse(entry.timestamp.replace(',', '.'));
numerify(entry, NUMERIC_FIELDS);
return entry;
}