mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-04 16:35:57 +00:00
✨ feat: done with elasticSearchQueryAsync
Signed-off-by: Muhammed Hussein Karimi <info@karimi.dev>
This commit is contained in:
parent
7b705219de
commit
aef175f5d7
1 changed files with 31 additions and 18 deletions
|
@ -132,35 +132,48 @@ exports.pingAsync = function (hostname, ipv6 = false, size = 56) {
|
|||
});
|
||||
};
|
||||
|
||||
exports.elasticSearchQueryAsync = function (version, nodes, headers, index, query) {
|
||||
exports.elasticSearchQueryAsync = function (version, nodes, headers, index, query, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { interval = 20, ssl = true } = options;
|
||||
|
||||
const timeoutID = setTimeout(() => {
|
||||
log.debug("elasticSearchQuery", "ElasticSearchQuery timeout triggered");
|
||||
reject(new Error("Timeout"));
|
||||
}, interval * 1000 * 0.8);
|
||||
|
||||
const opts = {
|
||||
headers: headers,
|
||||
nodes: nodes,
|
||||
ssl: {
|
||||
rejectUnauthorized: ssl !== false,
|
||||
},
|
||||
};
|
||||
|
||||
let client;
|
||||
switch (version) {
|
||||
case 6:
|
||||
client = new esClient6({
|
||||
headers: headers,
|
||||
nodes: nodes,
|
||||
});
|
||||
client = new esClient6(opts);
|
||||
break;
|
||||
case 7:
|
||||
client = new esClient7({
|
||||
headers: headers,
|
||||
nodes: nodes,
|
||||
});
|
||||
client = new esClient7(opts);
|
||||
break;
|
||||
case 8:
|
||||
client = new esClient8({
|
||||
headers: headers,
|
||||
nodes: nodes,
|
||||
});
|
||||
client = new esClient8(opts);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Invalid Elasticsearch version");
|
||||
throw new Error("Elasticsearch version is not valid");
|
||||
}
|
||||
try {
|
||||
client.search({
|
||||
index: index,
|
||||
query: query,
|
||||
});
|
||||
clearTimeout(timeoutID);
|
||||
resolve("Successfully ran query");
|
||||
} catch (e) {
|
||||
clearTimeout(timeoutID);
|
||||
reject(new Error("Error querying data: " + e.message));
|
||||
}
|
||||
client.search({
|
||||
index: index,
|
||||
query: query,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue