verbose => extended
This commit is contained in:
parent
209a12ccad
commit
cd7dac5b7e
|
@ -8,7 +8,7 @@ COPY src src
|
||||||
COPY cli cli
|
COPY cli cli
|
||||||
|
|
||||||
RUN echo '*/5 * * * * /usr/app/cli/run critical' >> /etc/crontabs/root
|
RUN echo '*/5 * * * * /usr/app/cli/run critical' >> /etc/crontabs/root
|
||||||
RUN echo '0 * * * * /usr/app/cli/run verbose' >> /etc/crontabs/root
|
RUN echo '0 * * * * /usr/app/cli/run extended' >> /etc/crontabs/root
|
||||||
|
|
||||||
EXPOSE 3100
|
EXPOSE 3100
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
const db = require("../db");
|
const db = require("../db");
|
||||||
const { getYesterdayISOString } = require("../utils");
|
const { getYesterdayISOString } = require("../utils");
|
||||||
|
|
||||||
// returns all verbose health check entries
|
// returns all extended health check entries
|
||||||
module.exports = (req, res) => {
|
module.exports = (req, res) => {
|
||||||
const yesterday = getYesterdayISOString();
|
const yesterday = getYesterdayISOString();
|
||||||
const entries = db
|
const entries = db
|
||||||
.get("verbose")
|
.get("extended")
|
||||||
.orderBy("date", "desc")
|
.orderBy("date", "desc")
|
||||||
.filter(({ date }) => date > yesterday)
|
.filter(({ date }) => date > yesterday)
|
||||||
.value();
|
.value();
|
|
@ -558,7 +558,7 @@ function dappExampleCheck(done) {
|
||||||
skylinkVerification(done, linkInfo);
|
skylinkVerification(done, linkInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const developMomentumBodyHash = "53b44a9d3cfa9b3d66ce5c29976f4383725d3652";
|
const developMomentumBodyHash = "08e96877dd6c99c3e1d98105f2fd9df377b53d65";
|
||||||
const developMomentumMetadata = require("../fixtures/developMomentumMetadata.json");
|
const developMomentumMetadata = require("../fixtures/developMomentumMetadata.json");
|
||||||
|
|
||||||
// developMomentumCheck returns the result of trying to download the skylink
|
// developMomentumCheck returns the result of trying to download the skylink
|
||||||
|
@ -811,7 +811,7 @@ function skyBinRedirectCheck(done) {
|
||||||
skylinkVerification(done, linkInfo);
|
skylinkVerification(done, linkInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const skyGalleryBodyHash = "077e54054748d278114f1870f8045a162eb73641";
|
const skyGalleryBodyHash = "cb5905023a29bdd60d58817f26503345c9a1bd09";
|
||||||
const skyGalleryMetadata = require("../fixtures/skygalleryMetadata.json");
|
const skyGalleryMetadata = require("../fixtures/skygalleryMetadata.json");
|
||||||
|
|
||||||
// skyGalleryCheck returns the result of trying to download the skylink for the SkyGallery Application.
|
// skyGalleryCheck returns the result of trying to download the skylink for the SkyGallery Application.
|
||||||
|
@ -1101,13 +1101,12 @@ function parseHeaderString(header) {
|
||||||
// skylinkVerification verifies a skylink against provided information.
|
// skylinkVerification verifies a skylink against provided information.
|
||||||
async function skylinkVerification(done, expected, { followRedirect = true, method = "get" } = {}) {
|
async function skylinkVerification(done, expected, { followRedirect = true, method = "get" } = {}) {
|
||||||
const time = process.hrtime();
|
const time = process.hrtime();
|
||||||
|
const details = { name: expected.name, skylink: expected.skylink };
|
||||||
// Create the query for the skylink
|
|
||||||
const query = `${process.env.PORTAL_URL}/${expected.skylink}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const query = `${process.env.PORTAL_URL}/${expected.skylink}`;
|
||||||
const response = await got[method](query, { followRedirect, headers: { cookie: "nocache=true" } });
|
const response = await got[method](query, { followRedirect, headers: { cookie: "nocache=true" } });
|
||||||
const entry = { name: expected.name, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) };
|
const entry = { ...details, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) };
|
||||||
const info = {};
|
const info = {};
|
||||||
|
|
||||||
if (expected.statusCode && expected.statusCode !== response.statusCode) {
|
if (expected.statusCode && expected.statusCode !== response.statusCode) {
|
||||||
|
@ -1119,7 +1118,6 @@ async function skylinkVerification(done, expected, { followRedirect = true, meth
|
||||||
if (expected.bodyHash) {
|
if (expected.bodyHash) {
|
||||||
const currentBodyHash = hasha(response.rawBody, { algorithm: "sha1" });
|
const currentBodyHash = hasha(response.rawBody, { algorithm: "sha1" });
|
||||||
if (currentBodyHash !== expected.bodyHash) {
|
if (currentBodyHash !== expected.bodyHash) {
|
||||||
console.log(expected.name, currentBodyHash);
|
|
||||||
entry.up = false;
|
entry.up = false;
|
||||||
info.bodyHash = { expected: expected.bodyHash, current: currentBodyHash };
|
info.bodyHash = { expected: expected.bodyHash, current: currentBodyHash };
|
||||||
}
|
}
|
||||||
|
@ -1145,7 +1143,7 @@ async function skylinkVerification(done, expected, { followRedirect = true, meth
|
||||||
done(entry); // Return the entry information
|
done(entry); // Return the entry information
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
done({
|
done({
|
||||||
name: expected.name,
|
...details,
|
||||||
up: false,
|
up: false,
|
||||||
statusCode: error?.response?.statusCode || error.statusCode || error.status,
|
statusCode: error?.response?.statusCode || error.statusCode || error.status,
|
||||||
errorMessage: error.message,
|
errorMessage: error.message,
|
|
@ -7,6 +7,6 @@ if (!fs.existsSync(process.env.STATE_DIR)) fs.mkdirSync(process.env.STATE_DIR);
|
||||||
const adapter = new FileSync(`${process.env.STATE_DIR}/state.json`);
|
const adapter = new FileSync(`${process.env.STATE_DIR}/state.json`);
|
||||||
const db = low(adapter);
|
const db = low(adapter);
|
||||||
|
|
||||||
db.defaults({ disabled: false, critical: [], verbose: [] }).write();
|
db.defaults({ disabled: false, critical: [], extended: [] }).write();
|
||||||
|
|
||||||
module.exports = db;
|
module.exports = db;
|
||||||
|
|
|
@ -21,7 +21,7 @@ server.use((req, res, next) => {
|
||||||
|
|
||||||
server.get("/health-check", require("./api/index"));
|
server.get("/health-check", require("./api/index"));
|
||||||
server.get("/health-check/critical", require("./api/critical"));
|
server.get("/health-check/critical", require("./api/critical"));
|
||||||
server.get("/health-check/verbose", require("./api/verbose"));
|
server.get("/health-check/extended", require("./api/extended"));
|
||||||
server.get("/health-check/disabled", require("./api/disabled"));
|
server.get("/health-check/disabled", require("./api/disabled"));
|
||||||
|
|
||||||
server.listen(port, host, (error) => {
|
server.listen(port, host, (error) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@ require("yargs/yargs")(process.argv.slice(2)).command(
|
||||||
.positional("type", {
|
.positional("type", {
|
||||||
describe: "Type of checks to run",
|
describe: "Type of checks to run",
|
||||||
type: "string",
|
type: "string",
|
||||||
choices: ["critical", "verbose"],
|
choices: ["critical", "extended"],
|
||||||
})
|
})
|
||||||
.option("portal-url", {
|
.option("portal-url", {
|
||||||
describe: "Skynet portal url",
|
describe: "Skynet portal url",
|
||||||
|
|
|
@ -144,8 +144,8 @@ async def check_health():
|
||||||
json_critical = requests.get(
|
json_critical = requests.get(
|
||||||
"http://localhost/health-check/critical", verify=False
|
"http://localhost/health-check/critical", verify=False
|
||||||
).json()
|
).json()
|
||||||
json_verbose = requests.get(
|
json_extended = requests.get(
|
||||||
"http://localhost/health-check/verbose", verify=False
|
"http://localhost/health-check/extended", verify=False
|
||||||
).json()
|
).json()
|
||||||
except:
|
except:
|
||||||
trace = traceback.format_exc()
|
trace = traceback.format_exc()
|
||||||
|
@ -157,8 +157,8 @@ async def check_health():
|
||||||
critical_checks_total = 0
|
critical_checks_total = 0
|
||||||
critical_checks_failed = 0
|
critical_checks_failed = 0
|
||||||
|
|
||||||
verbose_checks_total = 0
|
extended_checks_total = 0
|
||||||
verbose_checks_failed = 0
|
extended_checks_failed = 0
|
||||||
|
|
||||||
failed_records = []
|
failed_records = []
|
||||||
failed_records_file = None
|
failed_records_file = None
|
||||||
|
@ -178,18 +178,18 @@ async def check_health():
|
||||||
if bad:
|
if bad:
|
||||||
failed_records.append(critical)
|
failed_records.append(critical)
|
||||||
|
|
||||||
for verbose in json_verbose:
|
for extended in json_extended:
|
||||||
time = datetime.strptime(verbose["date"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
time = datetime.strptime(extended["date"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
if time < time_limit:
|
if time < time_limit:
|
||||||
continue
|
continue
|
||||||
bad = False
|
bad = False
|
||||||
for check in verbose["checks"]:
|
for check in extended["checks"]:
|
||||||
verbose_checks_total += 1
|
extended_checks_total += 1
|
||||||
if check["up"] == False:
|
if check["up"] == False:
|
||||||
verbose_checks_failed += 1
|
extended_checks_failed += 1
|
||||||
bad = True
|
bad = True
|
||||||
if bad:
|
if bad:
|
||||||
failed_records.append(verbose)
|
failed_records.append(extended)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# create a message
|
# create a message
|
||||||
|
@ -213,14 +213,14 @@ async def check_health():
|
||||||
message += "All {} critical checks passed. ".format(
|
message += "All {} critical checks passed. ".format(
|
||||||
critical_checks_total)
|
critical_checks_total)
|
||||||
|
|
||||||
if verbose_checks_failed:
|
if extended_checks_failed:
|
||||||
message += "{}/{} verbose checks failed over the last {} hours! ".format(
|
message += "{}/{} extended checks failed over the last {} hours! ".format(
|
||||||
verbose_checks_failed, verbose_checks_total, CHECK_HOURS
|
extended_checks_failed, extended_checks_total, CHECK_HOURS
|
||||||
)
|
)
|
||||||
force_notify = True
|
force_notify = True
|
||||||
else:
|
else:
|
||||||
message += "All {} verbose checks passed. ".format(
|
message += "All {} extended checks passed. ".format(
|
||||||
verbose_checks_total)
|
extended_checks_total)
|
||||||
|
|
||||||
if len(failed_records):
|
if len(failed_records):
|
||||||
failed_records_file = json.dumps(failed_records, indent=2)
|
failed_records_file = json.dumps(failed_records, indent=2)
|
||||||
|
|
Reference in New Issue