浏览代码

Server: update service check config from db on every timer tick - also update notify/-Threshold params

Christian Kahlau 3 年之前
父节点
当前提交
c509509660
共有 1 个文件被更改,包括 10 次插入9 次删除
  1. 10 9
      server/src/ctrl/http-check-controller.class.ts

+ 10 - 9
server/src/ctrl/http-check-controller.class.ts

@@ -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;