diff --git a/server/database.js b/server/database.js index 415624b9f..db31c2d9e 100644 --- a/server/database.js +++ b/server/database.js @@ -111,7 +111,7 @@ class Database { "patch-notification-config.sql": true, "patch-fix-kafka-producer-booleans.sql": true, "patch-timeout.sql": true, - "patch-monitor-tls-info-add-fk.sql": true, + "patch-monitor-tls-info-add-fk.sql": true, "patch-add-ping-advanced-options.sql": true, // The last file so far converted to a knex migration file }; diff --git a/server/model/monitor.js b/server/model/monitor.js index 67c295f68..73612bd0b 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1519,15 +1519,15 @@ class Monitor extends BeanModel { if (this.packetSize && (this.packetSize < PING_PACKET_SIZE_MIN || this.packetSize > PING_PACKET_SIZE_MAX)) { throw new Error(`Packet size must be between ${PING_PACKET_SIZE_MIN} and ${PING_PACKET_SIZE_MAX}`); } - + if (this.ping_deadline && (this.ping_deadline < PING_DEADLINE_MIN || this.ping_deadline > PING_DEADLINE_MAX)) { throw new Error(`Deadline must be between ${PING_DEADLINE_MIN} and ${PING_DEADLINE_MAX} seconds`); } - + if (this.ping_count && (this.ping_count < PING_COUNT_MIN || this.ping_count > PING_COUNT_MAX)) { throw new Error(`Echo requests count must be between ${PING_COUNT_MIN} and ${PING_COUNT_MAX}`); } - + if (this.ping_timeout && (this.ping_timeout < PING_TIMEOUT_MIN || this.ping_timeout > PING_TIMEOUT_MAX)) { throw new Error(`Timeout must be between ${PING_TIMEOUT_MIN} and ${PING_TIMEOUT_MAX} seconds`); } diff --git a/server/util-server.js b/server/util-server.js index 187872589..33d2d78e6 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -1,7 +1,7 @@ const tcpp = require("tcp-ping"); const ping = require("@louislam/ping"); const { R } = require("redbean-node"); -const { +const { log, genSecret, badgeConstants, PING_PACKET_SIZE_DEFAULT, PING_DEADLINE_DEFAULT, PING_COUNT_DEFAULT, PING_TIMEOUT_DEFAULT @@ -122,9 +122,9 @@ exports.tcping = function (hostname, port) { /** * Ping the specified machine - * @param {string} dest_address Hostname / IP address of machine to ping + * @param {string} destAddr Hostname / IP address of machine to ping * @param {number} count Number of packets to send before stopping - * @param {string} source_address Source address for sending/receiving echo requests + * @param {string} sourceAddr Source address for sending/receiving echo requests * @param {boolean} numeric If true, IP addresses will be output instead of symbolic hostnames * @param {number} size Size (in bytes) of echo request to send * @param {number} deadline Maximum time in seconds before ping stops, regardless of packets sent @@ -132,23 +132,23 @@ exports.tcping = function (hostname, port) { * @returns {Promise} Time for ping in ms rounded to nearest integer */ exports.ping = async ( - dest_address, + destAddr, count = PING_COUNT_DEFAULT, - source_address = '', + sourceAddr = "", numeric = true, size = PING_PACKET_SIZE_DEFAULT, deadline = PING_DEADLINE_DEFAULT, timeout = PING_TIMEOUT_DEFAULT, ) => { try { - return await exports.pingAsync(dest_address, false, count, source_address, numeric, size, deadline, timeout); + return await exports.pingAsync(destAddr, false, count, sourceAddr, numeric, size, deadline, timeout); } catch (e) { // If the host cannot be resolved, try again with ipv6 log.debug("ping", "IPv6 error message: " + e.message); // As node-ping does not report a specific error for this, try again if it is an empty message with ipv6 no matter what. if (!e.message) { - return await exports.pingAsync(dest_address, true, count, source_address, numeric, size, deadline, timeout); + return await exports.pingAsync(destAddr, true, count, sourceAddr, numeric, size, deadline, timeout); } else { throw e; } @@ -157,10 +157,10 @@ exports.ping = async ( /** * Ping the specified machine - * @param {string} dest_address Hostname / IP address of machine to ping + * @param {string} destAddr Hostname / IP address of machine to ping * @param {boolean} ipv6 Should IPv6 be used? * @param {number} count Number of packets to send before stopping - * @param {string} source_address Source address for sending/receiving echo requests + * @param {string} sourceAddr Source address for sending/receiving echo requests * @param {boolean} numeric If true, IP addresses will be output instead of symbolic hostnames * @param {number} size Size (in bytes) of echo request to send * @param {number} deadline Maximum time in seconds before ping stops, regardless of packets sent @@ -168,20 +168,20 @@ exports.ping = async ( * @returns {Promise} Time for ping in ms rounded to nearest integer */ exports.pingAsync = function ( - dest_address, + destAddr, ipv6 = false, count = PING_COUNT_DEFAULT, - source_address = '', + sourceAddr = "", numeric = true, size = PING_PACKET_SIZE_DEFAULT, deadline = PING_DEADLINE_DEFAULT, timeout = PING_TIMEOUT_DEFAULT, ) { return new Promise((resolve, reject) => { - ping.promise.probe(dest_address, { + ping.promise.probe(destAddr, { v6: ipv6, min_reply: count, - sourceAddr: source_address, + sourceAddr: sourceAddr, packetSize: size, deadline: deadline, timeout: timeout diff --git a/src/util.js b/src/util.js index a116d16ee..644914472 100644 --- a/src/util.js +++ b/src/util.js @@ -32,7 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; var _a; Object.defineProperty(exports, "__esModule", { value: true }); -exports.CONSOLE_STYLE_FgPink = exports.CONSOLE_STYLE_FgBrown = exports.CONSOLE_STYLE_FgViolet = exports.CONSOLE_STYLE_FgLightBlue = exports.CONSOLE_STYLE_FgLightGreen = exports.CONSOLE_STYLE_FgOrange = exports.CONSOLE_STYLE_FgGray = exports.CONSOLE_STYLE_FgWhite = exports.CONSOLE_STYLE_FgCyan = exports.CONSOLE_STYLE_FgMagenta = exports.CONSOLE_STYLE_FgBlue = exports.CONSOLE_STYLE_FgYellow = exports.CONSOLE_STYLE_FgGreen = exports.CONSOLE_STYLE_FgRed = exports.CONSOLE_STYLE_FgBlack = exports.CONSOLE_STYLE_Hidden = exports.CONSOLE_STYLE_Reverse = exports.CONSOLE_STYLE_Blink = exports.CONSOLE_STYLE_Underscore = exports.CONSOLE_STYLE_Dim = exports.CONSOLE_STYLE_Bright = exports.CONSOLE_STYLE_Reset = exports.PING_TIMEOUT_DEFAULT = exports.PING_TIMEOUT_MAX = exports.PING_TIMEOUT_MIN = exports.PING_COUNT_DEFAULT = exports.PING_COUNT_MAX = exports.PING_COUNT_MIN = exports.PING_DEADLINE_DEFAULT = exports.PING_DEADLINE_MAX = exports.PING_DEADLINE_MIN = exports.PING_DEFAULT_PACKET_SIZE = exports.PING_MAX_PACKET_SIZE = exports.PING_MIN_PACKET_SIZE = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isNode = exports.isDev = void 0; +exports.CONSOLE_STYLE_FgPink = exports.CONSOLE_STYLE_FgBrown = exports.CONSOLE_STYLE_FgViolet = exports.CONSOLE_STYLE_FgLightBlue = exports.CONSOLE_STYLE_FgLightGreen = exports.CONSOLE_STYLE_FgOrange = exports.CONSOLE_STYLE_FgGray = exports.CONSOLE_STYLE_FgWhite = exports.CONSOLE_STYLE_FgCyan = exports.CONSOLE_STYLE_FgMagenta = exports.CONSOLE_STYLE_FgBlue = exports.CONSOLE_STYLE_FgYellow = exports.CONSOLE_STYLE_FgGreen = exports.CONSOLE_STYLE_FgRed = exports.CONSOLE_STYLE_FgBlack = exports.CONSOLE_STYLE_Hidden = exports.CONSOLE_STYLE_Reverse = exports.CONSOLE_STYLE_Blink = exports.CONSOLE_STYLE_Underscore = exports.CONSOLE_STYLE_Dim = exports.CONSOLE_STYLE_Bright = exports.CONSOLE_STYLE_Reset = exports.PING_TIMEOUT_DEFAULT = exports.PING_TIMEOUT_MAX = exports.PING_TIMEOUT_MIN = exports.PING_COUNT_DEFAULT = exports.PING_COUNT_MAX = exports.PING_COUNT_MIN = exports.PING_DEADLINE_DEFAULT = exports.PING_DEADLINE_MAX = exports.PING_DEADLINE_MIN = exports.PING_PACKET_SIZE_DEFAULT = exports.PING_PACKET_SIZE_MAX = exports.PING_PACKET_SIZE_MIN = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isNode = exports.isDev = void 0; exports.evaluateJsonQuery = exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.badgeConstants = exports.CONSOLE_STYLE_BgGray = exports.CONSOLE_STYLE_BgWhite = exports.CONSOLE_STYLE_BgCyan = exports.CONSOLE_STYLE_BgMagenta = exports.CONSOLE_STYLE_BgBlue = exports.CONSOLE_STYLE_BgYellow = exports.CONSOLE_STYLE_BgGreen = exports.CONSOLE_STYLE_BgRed = exports.CONSOLE_STYLE_BgBlack = void 0; const dayjs_1 = __importDefault(require("dayjs")); const jsonata = __importStar(require("jsonata")); @@ -52,16 +52,16 @@ exports.SQL_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss"; exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = "YYYY-MM-DD HH:mm"; exports.MAX_INTERVAL_SECOND = 2073600; exports.MIN_INTERVAL_SECOND = 20; -exports.PING_MIN_PACKET_SIZE = 1; -exports.PING_MAX_PACKET_SIZE = 65500; -exports.PING_DEFAULT_PACKET_SIZE = 56; +exports.PING_PACKET_SIZE_MIN = 1; +exports.PING_PACKET_SIZE_MAX = 65500; +exports.PING_PACKET_SIZE_DEFAULT = 56; exports.PING_DEADLINE_MIN = 0; exports.PING_DEADLINE_MAX = 300; exports.PING_DEADLINE_DEFAULT = 0; exports.PING_COUNT_MIN = 1; exports.PING_COUNT_MAX = 100; exports.PING_COUNT_DEFAULT = 3; -exports.PING_TIMEOUT_MIN = 0; +exports.PING_TIMEOUT_MIN_TIMEOU = 0; exports.PING_TIMEOUT_MAX = 60; exports.PING_TIMEOUT_DEFAULT = 0; exports.CONSOLE_STYLE_Reset = "\x1b[0m";