-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (29 loc) · 983 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
const Elasticsearch = require("./lib/Elasticsearch");
const Request = require("./lib/Request");
const Uptime = require("./lib/Uptime");
const Slack = require("./lib/Slack");
const Config = require("./config.json");
const slack = new Slack(Config.slack_webhookUrl, Config.slack_channel);
const uptime = new Uptime(slack);
const elasticRequest = new Request({
url: Config.elasticsearch_url,
auth: Config.elasticsearch_apikey,
});
setInterval(async () => {
elasticRequest
.post({
path: `/${Config.elasticsearch_index}/_search`,
body: Elasticsearch.getQuery(Config.search_min_ago),
})
.then((data) => {
let parsedData = Elasticsearch.parseResult(data);
uptime.setState(parsedData);
})
.catch((err) => {
if (err === "ElasticsearchParseError") {
slack.sendMessage(`Can't parse Elasticsearch data`);
} else {
slack.sendMessage(`Can't connect to Elasticsearch\n${err}`);
}
});
}, Config.interval_ms);