Skip to content

Commit

Permalink
Merge pull request #75 from louislam/master
Browse files Browse the repository at this point in the history
Pull Prod
  • Loading branch information
thefourcraft authored Sep 21, 2024
2 parents ddef4e0 + dd75890 commit b9a7852
Show file tree
Hide file tree
Showing 98 changed files with 5,298 additions and 488 deletions.
28 changes: 0 additions & 28 deletions .devcontainer/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions .devcontainer/devcontainer.json

This file was deleted.

1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ README.md
.vscode
.eslint*
.stylelint*
/.devcontainer
/.github
yarn.lock
app.json
Expand Down
6 changes: 0 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,6 @@ The goal is to make the Uptime Kuma installation as easy as installing a mobile
- IDE that supports [`ESLint`](https://eslint.org/) and EditorConfig (I am using [`IntelliJ IDEA`](https://www.jetbrains.com/idea/))
- A SQLite GUI tool (f.ex. [`SQLite Expert Personal`](https://www.sqliteexpert.com/download.html) or [`DBeaver Community`](https://dbeaver.io/download/))
### GitHub Codespaces
If you don't want to setup an local environment, you can now develop on GitHub Codespaces, read more:

https://github.com/louislam/uptime-kuma/tree/master/.devcontainer

## Git Branches
- `master`: 2.X.X development. If you want to add a new feature, your pull request should base on this.
Expand Down
14 changes: 10 additions & 4 deletions config/playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig, devices } from "@playwright/test";

const port = 30001;
const url = `http://localhost:${port}`;
export const url = `http://localhost:${port}`;

export default defineConfig({
// Look for test files in the "tests" directory, relative to this configuration file.
testDir: "../test/e2e",
testDir: "../test/e2e/specs",
outputDir: "../private/playwright-test-results",
fullyParallel: false,
locale: "en-US",
Expand Down Expand Up @@ -40,9 +40,15 @@ export default defineConfig({
// Configure projects for major browsers.
projects: [
{
name: "chromium",
name: "run-once setup",
testMatch: /setup-process\.once\.js/,
use: { ...devices["Desktop Chrome"] },
},
{
name: "specs",
use: { ...devices["Desktop Chrome"] },
dependencies: [ "run-once setup" ],
},
/*
{
name: "firefox",
Expand All @@ -52,7 +58,7 @@ export default defineConfig({

// Run your local dev server before starting the tests.
webServer: {
command: `node extra/remove-playwright-test-data.js && node server/server.js --port=${port} --data-dir=./data/playwright-test`,
command: `node extra/remove-playwright-test-data.js && cross-env NODE_ENV=development node server/server.js --port=${port} --data-dir=./data/playwright-test`,
url,
reuseExistingServer: false,
cwd: "../",
Expand Down
13 changes: 13 additions & 0 deletions db/knex_migrations/2024-08-24-000-add-cache-bust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.up = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.boolean("cache_bust").notNullable().defaultTo(false);
});
};

exports.down = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.dropColumn("cache_bust");
});
};
12 changes: 12 additions & 0 deletions db/knex_migrations/2024-08-24-0000-conditions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports.up = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.text("conditions").notNullable().defaultTo("[]");
});
};

exports.down = function (knex) {
return knex.schema.alterTable("monitor", function (table) {
table.dropColumn("conditions");
});
};
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"build": "vite build --config ./config/vite.config.js",
"test": "npm run test-backend && npm run test-e2e",
"test-with-build": "npm run build && npm test",
"test-backend": "node test/backend-test-entry.js",
"test-backend:14": "cross-env TEST_BACKEND=1 NODE_OPTIONS=\"--experimental-abortcontroller --no-warnings\" node--test test/backend-test",
"test-backend:18": "cross-env TEST_BACKEND=1 node --test test/backend-test",
"test-backend": "cross-env TEST_BACKEND=1 node --test test/backend-test",
"test-e2e": "playwright test --config ./config/playwright.config.js",
"test-e2e-ui": "playwright test --config ./config/playwright.config.js --ui --ui-port=51063",
"playwright-codegen": "playwright codegen localhost:3000 --save-storage=./private/e2e-auth.json",
Expand Down Expand Up @@ -96,6 +94,7 @@
"express": "~4.19.2",
"express-basic-auth": "~1.2.1",
"express-static-gzip": "~2.1.7",
"feed": "^4.2.2",
"form-data": "~4.0.0",
"gamedig": "^4.2.0",
"html-escaper": "^3.0.3",
Expand Down
27 changes: 27 additions & 0 deletions server/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,32 @@ async function sendRemoteBrowserList(socket) {
return list;
}

/**
* Send list of monitor types to client
* @param {Socket} socket Socket.io socket instance
* @returns {Promise<void>}
*/
async function sendMonitorTypeList(socket) {
const result = Object.entries(UptimeKumaServer.monitorTypeList).map(([ key, type ]) => {
return [ key, {
supportsConditions: type.supportsConditions,
conditionVariables: type.conditionVariables.map(v => {
return {
id: v.id,
operators: v.operators.map(o => {
return {
id: o.id,
caption: o.caption,
};
}),
};
}),
}];
});

io.to(socket.userID).emit("monitorTypeList", Object.fromEntries(result));
}

module.exports = {
sendNotificationList,
sendImportantHeartbeatList,
Expand All @@ -222,4 +248,5 @@ module.exports = {
sendInfo,
sendDockerHostList,
sendRemoteBrowserList,
sendMonitorTypeList,
};
22 changes: 20 additions & 2 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ class Monitor extends BeanModel {
kafkaProducerAllowAutoTopicCreation: this.getKafkaProducerAllowAutoTopicCreation(),
kafkaProducerMessage: this.kafkaProducerMessage,
screenshot,
cacheBust: this.getCacheBust(),
remote_browser: this.remote_browser,
snmpOid: this.snmpOid,
jsonPathOperator: this.jsonPathOperator,
snmpVersion: this.snmpVersion,
conditions: JSON.parse(this.conditions),
};

if (includeSensitiveData) {
Expand Down Expand Up @@ -295,6 +297,14 @@ class Monitor extends BeanModel {
return Boolean(this.grpcEnableTls);
}

/**
* Parse to boolean
* @returns {boolean} if cachebusting is enabled
*/
getCacheBust() {
return Boolean(this.cacheBust);
}

/**
* Get accepted status codes
* @returns {object} Accepted status codes
Expand Down Expand Up @@ -336,7 +346,7 @@ class Monitor extends BeanModel {
let previousBeat = null;
let retries = 0;

this.prometheus = new Prometheus(this);
this.prometheus = await Prometheus.createAndInitMetrics(this);

const beat = async () => {

Expand Down Expand Up @@ -500,6 +510,14 @@ class Monitor extends BeanModel {
options.data = bodyValue;
}

if (this.cacheBust) {
const randomFloatString = Math.random().toString(36);
const cacheBust = randomFloatString.substring(2);
options.params = {
uptime_kuma_cachebuster: cacheBust,
};
}

if (this.proxy_id) {
const proxy = await R.load("proxy", this.proxy_id);

Expand Down Expand Up @@ -980,7 +998,7 @@ class Monitor extends BeanModel {
await R.store(bean);

log.debug("monitor", `[${this.name}] prometheus.update`);
this.prometheus?.update(bean, tlsInfo);
await this.prometheus?.update(bean, tlsInfo);

previousBeat = bean;

Expand Down
Loading

0 comments on commit b9a7852

Please sign in to comment.