Просмотр исходного кода

更新 keepalived 通知接口

reghao 2 лет назад
Родитель
Сommit
0e5e160438

+ 0 - 2
manager/src/main/java/cn/reghao/devops/manager/machine/controller/ClusterController.java

@@ -5,7 +5,6 @@ import cn.reghao.devops.manager.machine.service.ClusterService;
 import cn.reghao.jutil.jdk.result.WebResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
  * @author reghao
  * @date 2024-01-04 15:34:39
  */
-@Slf4j
 @Api(tags = "机器接口")
 @RestController
 @RequestMapping("/api/cluster")

+ 1 - 0
manager/src/main/java/cn/reghao/devops/manager/machine/model/dto/KeepalivedState.java

@@ -16,4 +16,5 @@ public class KeepalivedState {
     private String host;
     @NotBlank
     private String state;
+    private String realServer;
 }

+ 14 - 2
manager/src/main/java/cn/reghao/devops/manager/machine/service/ClusterService.java

@@ -3,12 +3,14 @@ package cn.reghao.devops.manager.machine.service;
 import cn.reghao.devops.manager.machine.model.dto.KeepalivedState;
 import cn.reghao.devops.manager.notification.NotifyService;
 import cn.reghao.devops.manager.notification.notifier.ding.DingMsg;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 /**
  * @author reghao
  * @date 2024-01-05 09:09:46
  */
+@Slf4j
 @Service
 public class ClusterService {
     private final NotifyService notifyService;
@@ -20,9 +22,19 @@ public class ClusterService {
     public void stateNotify(KeepalivedState keepalivedState) {
         String host = keepalivedState.getHost();
         String state = keepalivedState.getState();
+        String realServer = keepalivedState.getRealServer();
 
-        String title = "keepalived 事件通知";
-        String text = String.format("keepalived 节点 %s 切换为 %s", host, state);
+        String title;
+        String text;
+        if (realServer == null) {
+            title = "keepalived 事件通知";
+            text = String.format("keepalived 节点 %s 切换为 %s", host, state);
+        } else {
+            title = "keepalived-realserver 事件通知";
+            text = String.format("keepalived 节点 %s 检测到 RealServer %s 状态为 %s", host, realServer, state);
+        }
+
+        log.info(text);
         DingMsg dingMsg = new DingMsg(title, text);
         notifyService.notify(dingMsg);
     }