mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-04 08:25:57 +00:00
tls: server: Rewrite and document the success check
This commit is contained in:
parent
1ca0896b53
commit
38a252d0d8
1 changed files with 20 additions and 11 deletions
|
@ -60,17 +60,7 @@ class TlsMonitorType extends MonitorType {
|
||||||
throw response;
|
throw response;
|
||||||
}
|
}
|
||||||
|
|
||||||
let success = false;
|
const [ success, message ] = this.checkResponseSuccess(response, monitor);
|
||||||
let message = undefined;
|
|
||||||
if (monitor.keyword) {
|
|
||||||
const keywordContained = response.includes(monitor.keyword);
|
|
||||||
success = (keywordContained === !monitor.invertKeyword);
|
|
||||||
message = keywordContained ? "Data contains keyword" : "Data does not contain keyword";
|
|
||||||
} else {
|
|
||||||
success = true;
|
|
||||||
message = "Connection successful";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
this.log("check successful: " + message);
|
this.log("check successful: " + message);
|
||||||
heartbeat.msg = message;
|
heartbeat.msg = message;
|
||||||
|
@ -81,6 +71,25 @@ class TlsMonitorType extends MonitorType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the server response should be considered a success or not.
|
||||||
|
* @param {string} response Server response string
|
||||||
|
* @param {Monitor} monitor Monitor to check
|
||||||
|
* @returns {[boolean, string]} Tuple with a boolean success indicator and a message string
|
||||||
|
*/
|
||||||
|
checkResponseSuccess(response, monitor) {
|
||||||
|
if (monitor.keyword) {
|
||||||
|
// Monitor keyword present => Check if keyword is present/absent in response, depending
|
||||||
|
// on whether the 'Invert Keyword' option is enabled.
|
||||||
|
const keywordContained = response.includes(monitor.keyword);
|
||||||
|
const message = keywordContained ? "Data contains keyword" : "Data does not contain keyword";
|
||||||
|
return [ keywordContained === !monitor.invertKeyword, message ];
|
||||||
|
} else {
|
||||||
|
// No monitor keyword => Any response is considered a success.
|
||||||
|
return [ true, "Connection successful" ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the request over the given TLS socket and returns the response.
|
* Sends the request over the given TLS socket and returns the response.
|
||||||
* @param {AbortController} aborter Abort controller used to abort the request
|
* @param {AbortController} aborter Abort controller used to abort the request
|
||||||
|
|
Loading…
Add table
Reference in a new issue