|
|
@@ -95,29 +95,30 @@ export class HttpCheckController {
|
|
|
};
|
|
|
let success = true;
|
|
|
try {
|
|
|
- const current = await this.db.getHttpCheckConfigByID(conf.serverId ?? 0, conf.id);
|
|
|
+ const id = conf.id;
|
|
|
+ conf = (await this.db.getHttpCheckConfigByID(conf.serverId ?? 0, id)) as HttpCheckConfig;
|
|
|
|
|
|
- if (!current) {
|
|
|
- Logger.warn(`[WARN] HealthCheckConfig(${conf.id}) not found in Database but still scheduled in Timer!`);
|
|
|
+ if (!conf) {
|
|
|
+ Logger.warn(`[WARN] HealthCheckConfig(${id}) not found in Database but still scheduled in Timer!`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- options.timeout = current.timeout;
|
|
|
- let response = await axios.get(current.url, options);
|
|
|
+ options.timeout = conf.timeout;
|
|
|
+ let response = await axios.get(conf.url, options);
|
|
|
const responseText = new String(response.data).toString();
|
|
|
|
|
|
- for (const check of current.checks) {
|
|
|
+ for (const check of conf.checks) {
|
|
|
const reg = new RegExp(check, 'i');
|
|
|
if (!reg.test(responseText)) {
|
|
|
Logger.debug(`[DEBUG] Regular expression /${check}/i not found in response`);
|
|
|
- await this.db.insertHealthCheckData(current.id, now, HttpCheckStatus.CheckFailed, `Regular expression /${check}/i not found in response`);
|
|
|
+ await this.db.insertHealthCheckData(conf.id, now, HttpCheckStatus.CheckFailed, `Regular expression /${check}/i not found in response`);
|
|
|
success = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (success) {
|
|
|
- Logger.debug(`[DEBUG] HTTP Service Check "${current.title}": OK.`);
|
|
|
- await this.db.insertHealthCheckData(current.id, now, HttpCheckStatus.OK, 'OK');
|
|
|
+ Logger.debug(`[DEBUG] HTTP Service Check "${conf.title}": OK.`);
|
|
|
+ await this.db.insertHealthCheckData(conf.id, now, HttpCheckStatus.OK, 'OK');
|
|
|
}
|
|
|
} catch (err) {
|
|
|
let log = false;
|