diff --git a/README.md b/README.md index f07e707..f7f29d9 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,4 @@ Please refer to [Wiki](https://github.com/lyc8503/UptimeFlare/wiki) - [ ] Groups - [x] Remove old incidents - [ ] Known issue: `fetch` doesn't support non-standard port +- [ ] Update wiki and add docs for dev diff --git a/uptime.config.ts b/uptime.config.ts index acddf06..0d3edae 100644 --- a/uptime.config.ts +++ b/uptime.config.ts @@ -43,6 +43,8 @@ const workerConfig = { body: 'Hello, world!', // [OPTIONAL] if specified, the response must contains the keyword to be considered as operational. responseKeyword: 'success', + // [OPTIONAL] if specified, the response must NOT contains the keyword to be considered as operational. + responseForbiddenKeyword: 'bad gateway', // [OPTIONAL] if specified, the check will run in your specified region, // refer to docs https://github.com/lyc8503/UptimeFlare/wiki/Geo-specific-checks-setup before setting this value checkLocationWorkerRoute: 'https://xxx.example.com', diff --git a/uptime.types.ts b/uptime.types.ts index aa1748b..a4d56cd 100644 --- a/uptime.types.ts +++ b/uptime.types.ts @@ -43,6 +43,7 @@ type MonitorTarget = { headers?: Record body?: BodyInit responseKeyword?: string + responseForbiddenKeyword?: string } export type { MonitorState, MonitorTarget } diff --git a/worker/src/monitor.ts b/worker/src/monitor.ts index 216c06e..d235850 100644 --- a/worker/src/monitor.ts +++ b/worker/src/monitor.ts @@ -72,14 +72,25 @@ export async function getStatus( } } - if (monitor.responseKeyword) { + if (monitor.responseKeyword || monitor.responseForbiddenKeyword) { + // Only read response body if we have a keyword to check const responseBody = await response.text() - if (!responseBody.includes(monitor.responseKeyword)) { + + // MUST contain responseKeyword + if (monitor.responseKeyword && !responseBody.includes(monitor.responseKeyword)) { console.log(`${monitor.name} expected keyword ${monitor.responseKeyword}, not found in response (truncated to 100 chars): ${responseBody.slice(0, 100)}`) status.up = false status.err = "HTTP response doesn't contain the configured keyword" return status } + + // MUST NOT contain responseForbiddenKeyword + if (monitor.responseForbiddenKeyword && responseBody.includes(monitor.responseForbiddenKeyword)) { + console.log(`${monitor.name} forbidden keyword ${monitor.responseForbiddenKeyword}, found in response (truncated to 100 chars): ${responseBody.slice(0, 100)}`) + status.up = false + status.err = "HTTP response contains the configured forbidden keyword" + return status + } } status.up = true