diff --git a/db/knex_migrations/2026-01-15-0000-add-json-query-retry-only-status-code.js b/db/knex_migrations/2026-01-15-0000-add-json-query-retry-only-status-code.js index 9d5cff4a9..825f543c2 100644 --- a/db/knex_migrations/2026-01-15-0000-add-json-query-retry-only-status-code.js +++ b/db/knex_migrations/2026-01-15-0000-add-json-query-retry-only-status-code.js @@ -13,4 +13,3 @@ exports.down = function (knex) { table.dropColumn("retry_only_on_status_code_failure"); }); }; - diff --git a/server/model/monitor.js b/server/model/monitor.js index 1c9abfdf4..60914a58b 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -683,11 +683,15 @@ class Monitor extends BeanModel { if (status) { bean.status = UP; bean.msg = `JSON query passes (comparing ${response} ${this.jsonPathOperator} ${this.expectedValue})`; - + // Store numeric value if response is numeric (will be stored after heartbeat is saved) // Store it in a temporary variable, not on the bean, to avoid database column errors - if (typeof response === "number" || (typeof response === "string" && !isNaN(parseFloat(response)))) { - this._pendingNumericValue = typeof response === "number" ? response : parseFloat(response); + if ( + typeof response === "number" || + (typeof response === "string" && !isNaN(parseFloat(response))) + ) { + this._pendingNumericValue = + typeof response === "number" ? response : parseFloat(response); } } else { throw new Error( @@ -945,12 +949,13 @@ class Monitor extends BeanModel { // For json-query monitors with retry_only_on_status_code_failure enabled, // only retry if the error is NOT from JSON query evaluation // JSON query errors have the message "JSON query does not pass..." - const isJsonQueryError = this.type === "json-query" && - typeof error.message === "string" && + const isJsonQueryError = + this.type === "json-query" && + typeof error.message === "string" && error.message.includes("JSON query does not pass"); - + const shouldSkipRetry = isJsonQueryError && this.retry_only_on_status_code_failure; - + if (shouldSkipRetry) { // Don't retry on JSON query failures, mark as DOWN immediately retries = 0; @@ -1063,7 +1068,7 @@ class Monitor extends BeanModel { // Store to database log.debug("monitor", `[${this.name}] Store`); await R.store(bean); - + // Store numeric value if available (stored by monitor types like SNMP and JSON-query) // Check for pending numeric value stored during the check (not on bean to avoid DB column errors) if (this._pendingNumericValue !== undefined && this._pendingNumericValue !== null) {