feat: forbidden keyword

This commit is contained in:
lyc8503 committed 2025-03-25 00:01:50 +08:00
1 parent e448e95909
commit fe9e2ae2e0
4 files changed
+17 -2

No files matched your search

+1
View File
@@ -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
+2
View File
@@ -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',
+1
View File
@@ -43,6 +43,7 @@ type MonitorTarget = {
headers?: Record<string, string | undefined>
body?: BodyInit
responseKeyword?: string
responseForbiddenKeyword?: string
}
export type { MonitorState, MonitorTarget }
+13 -2
View File
@@ -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