2021-04-27 16:30:51 +00:00
|
|
|
const got = require("got");
|
|
|
|
const FormData = require("form-data");
|
2020-09-09 12:25:00 +00:00
|
|
|
const { StatusCodes } = require("http-status-codes");
|
2020-09-30 14:20:55 +00:00
|
|
|
const { calculateElapsedTime, getResponseContent } = require("../utils");
|
2020-09-09 12:25:00 +00:00
|
|
|
|
|
|
|
// uploadCheck returns the result of uploading a sample file
|
|
|
|
async function uploadCheck(done) {
|
|
|
|
const time = process.hrtime();
|
2021-04-27 16:30:51 +00:00
|
|
|
const form = new FormData();
|
2021-05-05 12:18:10 +00:00
|
|
|
const payload = Buffer.from(new Date()); // current date to ensure data uniqueness
|
|
|
|
const data = { up: false };
|
2021-04-27 16:30:51 +00:00
|
|
|
|
2021-05-05 12:18:10 +00:00
|
|
|
form.append("file", payload, { filename: "time.txt", contentType: "text/plain" });
|
2021-04-27 16:30:51 +00:00
|
|
|
|
|
|
|
try {
|
2021-05-05 12:18:10 +00:00
|
|
|
const response = await got.post(`${process.env.SKYNET_PORTAL_API}/skynet/skyfile`, { body: form });
|
2021-04-27 16:30:51 +00:00
|
|
|
|
2021-05-05 12:18:10 +00:00
|
|
|
data.statusCode = response.statusCode;
|
|
|
|
data.up = true;
|
|
|
|
data.ip = response.ip;
|
2021-04-27 16:30:51 +00:00
|
|
|
} catch (error) {
|
2021-05-05 12:18:10 +00:00
|
|
|
data.statusCode = error.response?.statusCode || error.statusCode || error.status;
|
|
|
|
data.errorMessage = error.message;
|
|
|
|
data.errorResponseContent = getResponseContent(error.response);
|
|
|
|
data.ip = error?.response?.ip ?? null;
|
2021-04-27 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done({
|
|
|
|
name: "upload_file",
|
|
|
|
time: calculateElapsedTime(time),
|
2021-05-05 12:18:10 +00:00
|
|
|
...data,
|
2021-04-27 16:30:51 +00:00
|
|
|
});
|
2020-09-09 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// downloadCheck returns the result of downloading the hard coded link
|
|
|
|
async function downloadCheck(done) {
|
|
|
|
const time = process.hrtime();
|
|
|
|
const skylink = "AACogzrAimYPG42tDOKhS3lXZD8YvlF8Q8R17afe95iV2Q";
|
2021-05-05 12:18:10 +00:00
|
|
|
const data = { up: false };
|
2020-09-09 12:25:00 +00:00
|
|
|
|
|
|
|
try {
|
2021-05-05 12:18:10 +00:00
|
|
|
const response = await got(`${process.env.SKYNET_PORTAL_API}/${skylink}?nocache=true`);
|
2020-09-09 12:25:00 +00:00
|
|
|
|
2021-05-05 12:18:10 +00:00
|
|
|
data.statusCode = response.statusCode;
|
|
|
|
data.up = true;
|
|
|
|
data.ip = response.ip;
|
2020-09-09 12:25:00 +00:00
|
|
|
} catch (error) {
|
2021-05-05 12:18:10 +00:00
|
|
|
data.statusCode = error?.response?.statusCode || error.statusCode || error.status;
|
|
|
|
data.errorMessage = error.message;
|
|
|
|
data.errorResponseContent = getResponseContent(error.response);
|
|
|
|
data.ip = error?.response?.ip ?? null;
|
2020-09-09 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done({
|
|
|
|
name: "download_file",
|
2020-09-09 12:53:05 +00:00
|
|
|
time: calculateElapsedTime(time),
|
2021-05-05 12:18:10 +00:00
|
|
|
...data,
|
2020-09-09 12:25:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-05 12:18:10 +00:00
|
|
|
async function accountHealthCheck(done) {
|
|
|
|
const time = process.hrtime();
|
|
|
|
const data = { up: false };
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await got(`${process.env.SKYNET_DASHBOARD_URL}/health`, { responseType: "json" });
|
|
|
|
|
|
|
|
data.statusCode = response.statusCode;
|
|
|
|
data.response = response.body;
|
|
|
|
data.up = response.body.dbAlive === true;
|
|
|
|
data.ip = response.ip;
|
|
|
|
} catch (error) {
|
|
|
|
data.statusCode = error?.response?.statusCode || error.statusCode || error.status;
|
|
|
|
data.errorMessage = error.message;
|
|
|
|
data.errorResponseContent = getResponseContent(error.response);
|
|
|
|
data.ip = error?.response?.ip ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
done({
|
|
|
|
name: "account_health",
|
|
|
|
time: calculateElapsedTime(time),
|
|
|
|
...data,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const checks = [uploadCheck, downloadCheck];
|
|
|
|
|
|
|
|
if (process.env.ACCOUNTS_ENABLED) {
|
|
|
|
checks.push(accountHealthCheck);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = checks;
|