mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 23:04:04 +00: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
2 changed files with 11 additions and 5 deletions
|
@ -577,7 +577,7 @@
|
||||||
"notificationDescription": "Notifications must be assigned to a monitor to function.",
|
"notificationDescription": "Notifications must be assigned to a monitor to function.",
|
||||||
"keywordDescription": "Search keyword in plain HTML or JSON response. The search is case-sensitive.",
|
"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.",
|
"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.",
|
"backupDescription": "You can backup all monitors and notifications into a JSON file.",
|
||||||
"backupDescription2": "Note: history and event data is not included.",
|
"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.",
|
"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}`);
|
throw new Error(`Invalid condition ${jsonPathOperator}`);
|
||||||
}
|
}
|
||||||
const expression = jsonata(jsonQueryExpression);
|
const expression = jsonata(jsonQueryExpression);
|
||||||
const evaluation = await expression.evaluate({
|
let evaluation;
|
||||||
value: response,
|
if (jsonPathOperator === "custom") {
|
||||||
control: expected
|
evaluation = await expression.evaluate(response);
|
||||||
});
|
}
|
||||||
|
else {
|
||||||
|
evaluation = await expression.evaluate({
|
||||||
|
value: response,
|
||||||
|
control: expectedValue
|
||||||
|
});
|
||||||
|
}
|
||||||
if (evaluation === undefined) {
|
if (evaluation === undefined) {
|
||||||
throw new Error("Query evaluation returned undefined. Check your query syntax and the structure of the response data.");
|
throw new Error("Query evaluation returned undefined. Check your query syntax and the structure of the response data.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue