feat: forbidden keyword
parent
e448e95909
commit
fe9e2ae2e0
|
|
@ -55,3 +55,4 @@ Please refer to [Wiki](https://github.com/lyc8503/UptimeFlare/wiki)
|
||||||
- [ ] Groups
|
- [ ] Groups
|
||||||
- [x] Remove old incidents
|
- [x] Remove old incidents
|
||||||
- [ ] Known issue: `fetch` doesn't support non-standard port
|
- [ ] Known issue: `fetch` doesn't support non-standard port
|
||||||
|
- [ ] Update wiki and add docs for dev
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ const workerConfig = {
|
||||||
body: 'Hello, world!',
|
body: 'Hello, world!',
|
||||||
// [OPTIONAL] if specified, the response must contains the keyword to be considered as operational.
|
// [OPTIONAL] if specified, the response must contains the keyword to be considered as operational.
|
||||||
responseKeyword: 'success',
|
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,
|
// [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
|
// refer to docs https://github.com/lyc8503/UptimeFlare/wiki/Geo-specific-checks-setup before setting this value
|
||||||
checkLocationWorkerRoute: 'https://xxx.example.com',
|
checkLocationWorkerRoute: 'https://xxx.example.com',
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ type MonitorTarget = {
|
||||||
headers?: Record<string, string | undefined>
|
headers?: Record<string, string | undefined>
|
||||||
body?: BodyInit
|
body?: BodyInit
|
||||||
responseKeyword?: string
|
responseKeyword?: string
|
||||||
|
responseForbiddenKeyword?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { MonitorState, MonitorTarget }
|
export type { MonitorState, MonitorTarget }
|
||||||
|
|
|
||||||
|
|
@ -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()
|
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)}`)
|
console.log(`${monitor.name} expected keyword ${monitor.responseKeyword}, not found in response (truncated to 100 chars): ${responseBody.slice(0, 100)}`)
|
||||||
status.up = false
|
status.up = false
|
||||||
status.err = "HTTP response doesn't contain the configured keyword"
|
status.err = "HTTP response doesn't contain the configured keyword"
|
||||||
return status
|
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
|
status.up = true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue