mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-09 23:24:07 -08:00
Query json directly rather than with $.value
-This is less abstract -Maximum compatibility with @chakflying's existing json-query monitor code.
This commit is contained in:
parent
36dc94b8f2
commit
10d3188dd3
|
@ -577,7 +577,7 @@
|
|||
"notificationDescription": "Notifications must be assigned to a monitor to function.",
|
||||
"keywordDescription": "Search keyword in plain HTML or JSON response. The search is case-sensitive.",
|
||||
"invertKeywordDescription": "Look for the keyword to be absent rather than present.",
|
||||
"jsonQueryDescription": "Use JSON query to parse and extract specific data from the server's JSON response. Compare the evaluated query against the expected value after converting it into a string. Access the response value using $.value and the expected value using $.control. Refer to {0} for detailed documentation on the query language or experiment with queries using the {1}.",
|
||||
"jsonQueryDescription": "Use JSON query to parse and extract specific data from the server's JSON response. Compare the evaluated query against the expected value after converting it into a string. Refer to {0} for detailed documentation on the query language or experiment with queries using the {1}.",
|
||||
"backupDescription": "You can backup all monitors and notifications into a JSON file.",
|
||||
"backupDescription2": "Note: history and event data is not included.",
|
||||
"backupDescription3": "Sensitive data such as notification tokens are included in the export file; please store export securely.",
|
||||
|
|
14
src/util.js
14
src/util.js
|
@ -427,10 +427,16 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue
|
|||
throw new Error(`Invalid condition ${jsonPathOperator}`);
|
||||
}
|
||||
const expression = jsonata(jsonQueryExpression);
|
||||
const evaluation = await expression.evaluate({
|
||||
value: response,
|
||||
control: expected
|
||||
});
|
||||
let evaluation;
|
||||
if (jsonPathOperator === "custom") {
|
||||
evaluation = await expression.evaluate(response);
|
||||
}
|
||||
else {
|
||||
evaluation = await expression.evaluate({
|
||||
value: response,
|
||||
control: expectedValue
|
||||
});
|
||||
}
|
||||
if (evaluation === undefined) {
|
||||
throw new Error("Query evaluation returned undefined. Check your query syntax and the structure of the response data.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue