Proposal: Make Keyword & Json-Query generic across monitor types #3919
+0
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma
Tick the checkbox if you understand [x]:
Description
Fixes #2439
Fixes #1851
Fixes #3336
Fixes #2342
Fixes #3844
Fixes #3140
After working on #3857, it became obvious to me that the use of Keyword or Json-Query result matching would benefit many other monitor types, e.g. SQL query results, DNS results. It is also obvious that implementing them individually for each monitor type would lead to a lot of code duplication and issues with maintainability.
Given that we are migrating the code base to where each monitor type is its own file and has a self-contained
check
function, I think we can take one step further by refactoring them such that:check
function performs the actions required for each heartbeat. This function should return astring
orobject
if successful. If it fails at any stage, it can throw an Error as it does currently.check
function is successful and returns a value, it can be passed to theverify
stage, which would be independent of monitor types. We can reuse the code forKeyword
andJson-Query
, and test for positive results accordingly. This function then also produce a success or fail message.check
andverify
functions, we can set the status of the heartbeat, while handlingretries
,upsideDown
, andresentNotification
. This part should be identical to the current implementation.By making the
verify
part generic, we can remove the need for the separate monitor typeHTTP - Keyword
, and expand the ability of checking for results to any monitor types that can produce a string or object.However, this would involve quite a big refactor of the
monitor.js
file, and possibly need to handle migrations for existing users of the Keyword monitor types.Type of change
Checklist
(including JSDoc for methods)
Screenshots (if any)