mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-07 13:32:35 +02:00
feat(monitor-checks): ensure old exports are converted to the new format
This commit is contained in:
parent
72fd5d5ca2
commit
2c910885b8
3 changed files with 46 additions and 7 deletions
|
@ -6,7 +6,7 @@ dayjs.extend(utc);
|
|||
dayjs.extend(timezone);
|
||||
const axios = require("axios");
|
||||
const { Prometheus } = require("../prometheus");
|
||||
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger, MONITOR_CHECK_SELECTOR_TYPES } = require("../../src/util");
|
||||
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger, MONITOR_CHECK_SELECTOR_TYPES, HTTP_STATUS_CODE_SHOULD_EQUAL } = require("../../src/util");
|
||||
const { tcping, ping, dnsResolve, checkCertificate, getTotalClientInRoom } = require("../util-server");
|
||||
const { R } = require("redbean-node");
|
||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||
|
@ -537,7 +537,7 @@ class Monitor extends BeanModel {
|
|||
if (MONITOR_CHECK_SELECTOR_TYPES.includes(check.type) && typeof check.value === "string" && check.value.startsWith("{")) {
|
||||
check.value = JSON.parse(check.value);
|
||||
}
|
||||
if (check.type === "HTTP_STATUS_CODE_SHOULD_EQUAL" && typeof check.value === "string" && check.value.startsWith("[")) {
|
||||
if (check.type === HTTP_STATUS_CODE_SHOULD_EQUAL && typeof check.value === "string" && check.value.startsWith("[")) {
|
||||
check.value = JSON.parse(check.value);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -6,7 +6,10 @@ if (!process.env.NODE_ENV) {
|
|||
|
||||
console.log("Node Env: " + process.env.NODE_ENV);
|
||||
|
||||
const { sleep, debug, getRandomInt, genSecret } = require("../src/util");
|
||||
const { sleep, debug, getRandomInt, genSecret,
|
||||
HTTP_STATUS_CODE_SHOULD_EQUAL,
|
||||
RESPONSE_SHOULD_CONTAIN_TEXT
|
||||
} = require("../src/util");
|
||||
|
||||
console.log("Importing Node libraries");
|
||||
const fs = require("fs");
|
||||
|
@ -1080,10 +1083,36 @@ exports.entryPage = "dashboard";
|
|||
let notificationIDList = monitor.notificationIDList;
|
||||
delete monitor.notificationIDList;
|
||||
|
||||
monitor.checks_json = JSON.stringify(monitor.checks);
|
||||
// TODO remove this if clause once we no longer expect export files to contain the old accepted_statuscodes and keyword format
|
||||
if (monitor.type === "http" || monitor.type === "keyword") {
|
||||
if (monitor.accepted_statuscodes) {
|
||||
// old format for checking http status codes
|
||||
// Convert to new format which uses separate monitor check
|
||||
monitor.checks = monitor.checks || [];
|
||||
monitor.checks.push({
|
||||
monitor_id: monitor.id,
|
||||
type: HTTP_STATUS_CODE_SHOULD_EQUAL,
|
||||
value: monitor.accepted_statuscodes,
|
||||
});
|
||||
}
|
||||
|
||||
delete monitor.accepted_statuscodes; // TODO convert to check
|
||||
delete monitor.keyword; // TODO convert to check
|
||||
if (monitor.keyword) {
|
||||
// old format for checking response contains keyword
|
||||
// Convert to new format which uses separate monitor check
|
||||
monitor.checks = monitor.checks || [];
|
||||
monitor.checks.push({
|
||||
monitor_id: monitor.id,
|
||||
type: RESPONSE_SHOULD_CONTAIN_TEXT,
|
||||
value: monitor.keyword,
|
||||
});
|
||||
}
|
||||
|
||||
monitor.type = "http";
|
||||
delete monitor.accepted_statuscodes;
|
||||
delete monitor.keyword;
|
||||
}
|
||||
|
||||
monitor.checks_json = JSON.stringify(monitor.checks);
|
||||
|
||||
const checks = monitor.checks;
|
||||
delete monitor.checks;
|
||||
|
|
12
src/util.ts
12
src/util.ts
|
@ -19,7 +19,17 @@ export const STATUS_PAGE_ALL_DOWN = 0;
|
|||
export const STATUS_PAGE_ALL_UP = 1;
|
||||
export const STATUS_PAGE_PARTIAL_DOWN = 2;
|
||||
|
||||
export const MONITOR_CHECK_STRING_TYPES = ["HTTP_STATUS_CODE_SHOULD_EQUAL", "RESPONSE_SHOULD_CONTAIN_TEXT", "RESPONSE_SHOULD_NOT_CONTAIN_TEXT", "RESPONSE_SHOULD_MATCH_REGEX", "RESPONSE_SHOULD_NOT_MATCH_REGEX"];
|
||||
export const HTTP_STATUS_CODE_SHOULD_EQUAL = "HTTP_STATUS_CODE_SHOULD_EQUAL";
|
||||
export const RESPONSE_SHOULD_CONTAIN_TEXT = "RESPONSE_SHOULD_CONTAIN_TEXT";
|
||||
export const RESPONSE_SHOULD_NOT_CONTAIN_TEXT = "RESPONSE_SHOULD_NOT_CONTAIN_TEXT";
|
||||
export const RESPONSE_SHOULD_MATCH_REGEX = "RESPONSE_SHOULD_MATCH_REGEX";
|
||||
export const RESPONSE_SHOULD_NOT_MATCH_REGEX = "RESPONSE_SHOULD_NOT_MATCH_REGEX";
|
||||
export const RESPONSE_SELECTOR_SHOULD_EQUAL = "RESPONSE_SELECTOR_SHOULD_EQUAL";
|
||||
export const RESPONSE_SELECTOR_SHOULD_NOT_EQUAL = "RESPONSE_SELECTOR_SHOULD_NOT_EQUAL";
|
||||
export const RESPONSE_SELECTOR_SHOULD_MATCH_REGEX = "RESPONSE_SELECTOR_SHOULD_MATCH_REGEX";
|
||||
export const RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX = "RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX";
|
||||
|
||||
export const MONITOR_CHECK_STRING_TYPES = ["RESPONSE_SHOULD_CONTAIN_TEXT", "RESPONSE_SHOULD_NOT_CONTAIN_TEXT", "RESPONSE_SHOULD_MATCH_REGEX", "RESPONSE_SHOULD_NOT_MATCH_REGEX"];
|
||||
export const MONITOR_CHECK_SELECTOR_TYPES = ["RESPONSE_SELECTOR_SHOULD_EQUAL", "RESPONSE_SELECTOR_SHOULD_NOT_EQUAL", "RESPONSE_SELECTOR_SHOULD_MATCH_REGEX", "RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX"];
|
||||
|
||||
export function flipStatus(s: number) {
|
||||
|
|
Loading…
Add table
Reference in a new issue