Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: structured logging (JSON)" #5175

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const basicAuth = require("express-basic-auth");
const passwordHash = require("./password-hash");
const { R } = require("redbean-node");
const { setting } = require("./util-server");
const { log } = require("../src/util");
const { loginRateLimiter, apiRateLimiter } = require("./rate-limiter");
const { Settings } = require("./settings");
Expand Down Expand Up @@ -138,7 +139,7 @@ exports.basicAuth = async function (req, res, next) {
challenge: true,
});

const disabledAuth = await Settings.get("disableAuth");
const disabledAuth = await setting("disableAuth");

if (!disabledAuth) {
middleware(req, res, next);
Expand Down
8 changes: 4 additions & 4 deletions server/check-version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { setSetting, setting } = require("./util-server");
const axios = require("axios");
const compareVersions = require("compare-versions");
const { log } = require("../src/util");
const { Settings } = require("./settings");

exports.version = require("../package.json").version;
exports.latestVersion = null;
Expand All @@ -14,7 +14,7 @@ let interval;

exports.startInterval = () => {
let check = async () => {
if (await Settings.get("checkUpdate") === false) {
if (await setting("checkUpdate") === false) {
return;
}

Expand All @@ -28,7 +28,7 @@ exports.startInterval = () => {
res.data.slow = "1000.0.0";
}

let checkBeta = await Settings.get("checkBeta");
let checkBeta = await setting("checkBeta");

if (checkBeta && res.data.beta) {
if (compareVersions.compare(res.data.beta, res.data.slow, ">")) {
Expand Down Expand Up @@ -57,7 +57,7 @@ exports.startInterval = () => {
* @returns {Promise<void>}
*/
exports.enableCheckUpdate = async (value) => {
await Settings.set("checkUpdate", value);
await setSetting("checkUpdate", value);

clearInterval(interval);

Expand Down
4 changes: 2 additions & 2 deletions server/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const { R } = require("redbean-node");
const { UptimeKumaServer } = require("./uptime-kuma-server");
const server = UptimeKumaServer.getInstance();
const io = server.io;
const { setting } = require("./util-server");
const checkVersion = require("./check-version");
const { Settings } = require("./settings");
const Database = require("./database");

/**
Expand Down Expand Up @@ -158,8 +158,8 @@ async function sendInfo(socket, hideVersion = false) {
version,
latestVersion,
isContainer,
primaryBaseURL: await Settings.get("primaryBaseURL"),
dbType,
primaryBaseURL: await setting("primaryBaseURL"),
serverTimezone: await server.getTimezone(),
serverTimezoneOffset: server.getTimezoneOffset(),
});
Expand Down
34 changes: 17 additions & 17 deletions server/database.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require("fs");
const { R } = require("redbean-node");
const { setSetting, setting } = require("./util-server");
const { log, sleep } = require("../src/util");
const knex = require("knex");
const path = require("path");
const { EmbeddedMariaDB } = require("./embedded-mariadb");
const mysql = require("mysql2/promise");
const { Settings } = require("./settings");

/**
* Database & App Data Folder
Expand Down Expand Up @@ -420,7 +420,7 @@ class Database {
* @deprecated
*/
static async patchSqlite() {
let version = parseInt(await Settings.get("database_version"));
let version = parseInt(await setting("database_version"));

if (! version) {
version = 0;
Expand All @@ -445,7 +445,7 @@ class Database {
log.info("db", `Patching ${sqlFile}`);
await Database.importSQLFile(sqlFile);
log.info("db", `Patched ${sqlFile}`);
await Settings.set("database_version", i);
await setSetting("database_version", i);
}
} catch (ex) {
await Database.close();
Expand All @@ -471,7 +471,7 @@ class Database {
*/
static async patchSqlite2() {
log.debug("db", "Database Patch 2.0 Process");
let databasePatchedFiles = await Settings.get("databasePatchedFiles");
let databasePatchedFiles = await setting("databasePatchedFiles");

if (! databasePatchedFiles) {
databasePatchedFiles = {};
Expand Down Expand Up @@ -499,7 +499,7 @@ class Database {
process.exit(1);
}

await Settings.set("databasePatchedFiles", databasePatchedFiles);
await setSetting("databasePatchedFiles", databasePatchedFiles);
}

/**
Expand All @@ -512,27 +512,27 @@ class Database {
// Fix 1.13.0 empty slug bug
await R.exec("UPDATE status_page SET slug = 'empty-slug-recover' WHERE TRIM(slug) = ''");

let title = await Settings.get("title");
let title = await setting("title");

if (title) {
log.info("database", "Migrating Status Page");
console.log("Migrating Status Page");

let statusPageCheck = await R.findOne("status_page", " slug = 'default' ");

if (statusPageCheck !== null) {
log.info("database", "Migrating Status Page - Skip, default slug record is already existing");
console.log("Migrating Status Page - Skip, default slug record is already existing");
return;
}

let statusPage = R.dispense("status_page");
statusPage.slug = "default";
statusPage.title = title;
statusPage.description = await Settings.get("description");
statusPage.icon = await Settings.get("icon");
statusPage.theme = await Settings.get("statusPageTheme");
statusPage.published = !!await Settings.get("statusPagePublished");
statusPage.search_engine_index = !!await Settings.get("searchEngineIndex");
statusPage.show_tags = !!await Settings.get("statusPageTags");
statusPage.description = await setting("description");
statusPage.icon = await setting("icon");
statusPage.theme = await setting("statusPageTheme");
statusPage.published = !!await setting("statusPagePublished");
statusPage.search_engine_index = !!await setting("searchEngineIndex");
statusPage.show_tags = !!await setting("statusPageTags");
statusPage.password = null;

if (!statusPage.title) {
Expand Down Expand Up @@ -560,13 +560,13 @@ class Database {
await R.exec("DELETE FROM setting WHERE type = 'statusPage'");

// Migrate Entry Page if it is status page
let entryPage = await Settings.get("entryPage");
let entryPage = await setting("entryPage");

if (entryPage === "statusPage") {
await Settings.set("entryPage", "statusPage-default", "general");
await setSetting("entryPage", "statusPage-default", "general");
}

log.info("database", "Migrating Status Page - Done");
console.log("Migrating Status Page - Done");
}

}
Expand Down
8 changes: 4 additions & 4 deletions server/jobs/clear-old-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { R } = require("redbean-node");
const { log } = require("../../src/util");
const { setSetting, setting } = require("../util-server");
const Database = require("../database");
const { Settings } = require("../settings");

const DEFAULT_KEEP_PERIOD = 180;

Expand All @@ -11,11 +11,11 @@ const DEFAULT_KEEP_PERIOD = 180;
*/

const clearOldData = async () => {
let period = await Settings.get("keepDataPeriodDays");
let period = await setting("keepDataPeriodDays");

// Set Default Period
if (period == null) {
await Settings.set("keepDataPeriodDays", DEFAULT_KEEP_PERIOD, "general");
await setSetting("keepDataPeriodDays", DEFAULT_KEEP_PERIOD, "general");
period = DEFAULT_KEEP_PERIOD;
}

Expand All @@ -25,7 +25,7 @@ const clearOldData = async () => {
parsedPeriod = parseInt(period);
} catch (_) {
log.warn("clearOldData", "Failed to parse setting, resetting to default..");
await Settings.set("keepDataPeriodDays", DEFAULT_KEEP_PERIOD, "general");
await setSetting("keepDataPeriodDays", DEFAULT_KEEP_PERIOD, "general");
parsedPeriod = DEFAULT_KEEP_PERIOD;
}

Expand Down
10 changes: 4 additions & 6 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Prometheus } = require("../prometheus");
const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND,
SQL_DATETIME_FORMAT, evaluateJsonQuery
} = require("../../src/util");
const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, mssqlQuery, postgresQuery, mysqlQuery, httpNtlm, radius, grpcQuery,
const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, setSetting, httpNtlm, radius, grpcQuery,
redisPingAsync, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal
} = require("../util-server");
const { R } = require("redbean-node");
Expand All @@ -24,7 +24,6 @@ const { CookieJar } = require("tough-cookie");
const { HttpsCookieAgent } = require("http-cookie-agent/http");
const https = require("https");
const http = require("http");
const { Settings } = require("../settings");

const rootCertificates = rootCertificatesFingerprints();

Expand Down Expand Up @@ -652,7 +651,7 @@ class Monitor extends BeanModel {

} else if (this.type === "steam") {
const steamApiUrl = "https://api.steampowered.com/IGameServersService/GetServerList/v1/";
const steamAPIKey = await Settings.get("steamAPIKey");
const steamAPIKey = await setting("steamAPIKey");
const filter = `addr\\${this.hostname}:${this.port}`;

if (!steamAPIKey) {
Expand Down Expand Up @@ -1374,12 +1373,11 @@ class Monitor extends BeanModel {
return;
}

let notifyDays = await Settings.get("tlsExpiryNotifyDays");
let notifyDays = await setting("tlsExpiryNotifyDays");
if (notifyDays == null || !Array.isArray(notifyDays)) {
// Reset Default
await Settings.set("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general");
await setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general");
notifyDays = [ 7, 14, 21 ];
await Settings.set("tlsExpiryNotifyDays", notifyDays, "general");
}

if (Array.isArray(notifyDays)) {
Expand Down
Loading
Loading