|
@@ -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.machine.model.dto.KeepalivedState;
|
|
|
import cn.reghao.devops.manager.notification.NotifyService;
|
|
import cn.reghao.devops.manager.notification.NotifyService;
|
|
|
import cn.reghao.devops.manager.notification.notifier.ding.DingMsg;
|
|
import cn.reghao.devops.manager.notification.notifier.ding.DingMsg;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2024-01-05 09:09:46
|
|
* @date 2024-01-05 09:09:46
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class ClusterService {
|
|
public class ClusterService {
|
|
|
private final NotifyService notifyService;
|
|
private final NotifyService notifyService;
|
|
@@ -20,9 +22,19 @@ public class ClusterService {
|
|
|
public void stateNotify(KeepalivedState keepalivedState) {
|
|
public void stateNotify(KeepalivedState keepalivedState) {
|
|
|
String host = keepalivedState.getHost();
|
|
String host = keepalivedState.getHost();
|
|
|
String state = keepalivedState.getState();
|
|
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);
|
|
DingMsg dingMsg = new DingMsg(title, text);
|
|
|
notifyService.notify(dingMsg);
|
|
notifyService.notify(dingMsg);
|
|
|
}
|
|
}
|