add ip check to all checks
This commit is contained in:
parent
1f8a553fb0
commit
59a22db5f0
|
@ -67,7 +67,7 @@ async function accountWebsiteCheck(done) {
|
||||||
// directServerApiAccessCheck returns the basic server api check on direct server address
|
// directServerApiAccessCheck returns the basic server api check on direct server address
|
||||||
async function directServerApiAccessCheck(done) {
|
async function directServerApiAccessCheck(done) {
|
||||||
if (!process.env.SKYNET_SERVER_API) {
|
if (!process.env.SKYNET_SERVER_API) {
|
||||||
return done({ up: false, info: { message: "SKYNET_SERVER_API env variable not configured" } });
|
return done({ up: false, errors: [{ message: "SKYNET_SERVER_API env variable not configured" }] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const [portalAccessCheck, serverAccessCheck] = await Promise.all([
|
const [portalAccessCheck, serverAccessCheck] = await Promise.all([
|
||||||
|
@ -77,13 +77,14 @@ async function directServerApiAccessCheck(done) {
|
||||||
|
|
||||||
if (portalAccessCheck.ip !== serverAccessCheck.ip) {
|
if (portalAccessCheck.ip !== serverAccessCheck.ip) {
|
||||||
serverAccessCheck.up = false;
|
serverAccessCheck.up = false;
|
||||||
serverAccessCheck.info = {
|
serverAccessCheck.errors = serverAccessCheck.errors ?? [];
|
||||||
|
serverAccessCheck.errors.push({
|
||||||
message: "Access ip mismatch between portal and server access",
|
message: "Access ip mismatch between portal and server access",
|
||||||
response: {
|
response: {
|
||||||
portal: { name: process.env.SKYNET_PORTAL_API, ip: portalAccessCheck.ip },
|
portal: { name: process.env.SKYNET_PORTAL_API, ip: portalAccessCheck.ip },
|
||||||
server: { name: process.env.SKYNET_SERVER_API, ip: serverAccessCheck.ip },
|
server: { name: process.env.SKYNET_SERVER_API, ip: serverAccessCheck.ip },
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return done(serverAccessCheck);
|
return done(serverAccessCheck);
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
const got = require("got");
|
||||||
|
|
||||||
|
const getCurrentAddress = async () => {
|
||||||
|
try {
|
||||||
|
const { body } = await got("http://whatismyip.akamai.com");
|
||||||
|
if (body) return body;
|
||||||
|
throw new Error("whatismyip.akamai.com responded with empty body");
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error.message);
|
||||||
|
return "-- error fetching ip address from whatismyip.akamai.com --";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = async function middleware() {
|
||||||
|
const ip = await getCurrentAddress();
|
||||||
|
|
||||||
|
return (check) => {
|
||||||
|
if (check.ip && check.ip !== ip) {
|
||||||
|
check.up = false;
|
||||||
|
check.errors = check.errors ?? [];
|
||||||
|
check.errors.push({
|
||||||
|
message: "Response ip was different than current server ip - possibly there was an error with routing request",
|
||||||
|
data: { response: check.ip, server: ip },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return check;
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,4 +1,5 @@
|
||||||
const { getYesterdayISOString } = require("./utils");
|
const { getYesterdayISOString } = require("./utils");
|
||||||
|
const createMiddleware = require("./checks/middleware");
|
||||||
|
|
||||||
require("yargs/yargs")(process.argv.slice(2)).command(
|
require("yargs/yargs")(process.argv.slice(2)).command(
|
||||||
"$0 <type>",
|
"$0 <type>",
|
||||||
|
@ -27,10 +28,11 @@ require("yargs/yargs")(process.argv.slice(2)).command(
|
||||||
|
|
||||||
const db = require("../src/db");
|
const db = require("../src/db");
|
||||||
const checks = require(`../src/checks/${type}`);
|
const checks = require(`../src/checks/${type}`);
|
||||||
|
const middleware = await createMiddleware();
|
||||||
|
|
||||||
const entry = {
|
const entry = {
|
||||||
date: new Date().toISOString(),
|
date: new Date().toISOString(),
|
||||||
checks: await Promise.all(checks.map((check) => new Promise(check))),
|
checks: (await Promise.all(checks.map((check) => new Promise(check)))).map(middleware),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.read() // read before writing to make sure no external changes are overwritten
|
db.read() // read before writing to make sure no external changes are overwritten
|
||||||
|
|
Reference in New Issue