Browse Source
Merge branch 'master' of
Merge branch 'master' of
http://82.156.111.58:3000/maojian/appliction_manager.gitmaster
13 changed files with 483 additions and 1 deletions
-
43.classpath
-
6.gitignore
-
26.project
-
8.settings/org.eclipse.core.resources.prefs
-
12.settings/org.eclipse.jdt.core.prefs
-
7.settings/org.eclipse.m2e.core.prefs
-
10README.md
-
147pom.xml
-
26src/main/java/com/bfd/manager/Application.java
-
108src/main/java/com/bfd/manager/alter/AdminNotifier.java
-
32src/main/resources/application.yml
-
39src/main/resources/logback-spring.xml
-
20src/test/java/com/bfd/AppTest.java
@ -1,2 +1,6 @@ |
|||
/target/ |
|||
/logs/ |
|||
<<<<<<< HEAD |
|||
/logs/ |
|||
======= |
|||
/logs/ |
|||
>>>>>>> branch 'master' of http://82.156.111.58:3000/maojian/appliction_manager.git |
@ -1,5 +1,13 @@ |
|||
<<<<<<< HEAD |
|||
eclipse.preferences.version=1 |
|||
encoding//src/main/java=UTF-8 |
|||
encoding//src/main/resources=UTF-8 |
|||
encoding//src/test/java=UTF-8 |
|||
encoding/<project>=UTF-8 |
|||
======= |
|||
eclipse.preferences.version=1 |
|||
encoding//src/main/java=UTF-8 |
|||
encoding//src/main/resources=UTF-8 |
|||
encoding//src/test/java=UTF-8 |
|||
encoding/<project>=UTF-8 |
|||
>>>>>>> branch 'master' of http://82.156.111.58:3000/maojian/appliction_manager.git |
@ -1,4 +1,11 @@ |
|||
<<<<<<< HEAD |
|||
activeProfiles= |
|||
eclipse.preferences.version=1 |
|||
resolveWorkspaceProjects=true |
|||
version=1 |
|||
======= |
|||
activeProfiles= |
|||
eclipse.preferences.version=1 |
|||
resolveWorkspaceProjects=true |
|||
version=1 |
|||
>>>>>>> branch 'master' of http://82.156.111.58:3000/maojian/appliction_manager.git |
@ -1 +1,11 @@ |
|||
<<<<<<< HEAD |
|||
智谱大模型应用 |
|||
======= |
|||
<<<<<<< HEAD |
|||
应用管理中心 |
|||
======= |
|||
# appliction_manager |
|||
|
|||
sba应用管理 |
|||
>>>>>>> branch 'master' of http://82.156.111.58:3000/maojian/appliction_manager.git |
|||
>>>>>>> branch 'master' of http://82.156.111.58:3000/maojian/appliction_manager.git |
@ -0,0 +1,26 @@ |
|||
package com.bfd.manager; |
|||
|
|||
|
|||
|
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
|
|||
import de.codecentric.boot.admin.server.config.EnableAdminServer; |
|||
|
|||
/** |
|||
* 主入口 |
|||
* |
|||
* @author jian.mao |
|||
* @date 2023年7月4日 |
|||
* @description |
|||
*/ |
|||
@SpringBootApplication |
|||
@EnableAdminServer |
|||
public class Application { |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(Application.class, args); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,108 @@ |
|||
package com.bfd.manager.alter; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
import reactor.core.publisher.Mono; |
|||
import de.codecentric.boot.admin.server.domain.entities.Instance; |
|||
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; |
|||
import de.codecentric.boot.admin.server.domain.events.InstanceEvent; |
|||
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent; |
|||
import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class AdminNotifier extends AbstractStatusChangeNotifier { |
|||
|
|||
/** |
|||
* 消息模板 |
|||
*/ |
|||
private static final String template = "<<<%s>>> \n 【服务名】: %s(%s) \n 【状态】: %s(%s) \n 【服务ip】: %s \n 【详情】: %s"; |
|||
|
|||
private String titleAlarm = "系统告警"; |
|||
|
|||
private String titleNotice = "系统通知"; |
|||
|
|||
private String[] ignoreChanges = new String[]{"UNKNOWN:UP","DOWN:UP","OFFLINE:UP"}; |
|||
|
|||
public AdminNotifier(InstanceRepository repository) { |
|||
super(repository); |
|||
} |
|||
|
|||
@Override |
|||
protected boolean shouldNotify(InstanceEvent event, Instance instance) { |
|||
if (!(event instanceof InstanceStatusChangedEvent)) { |
|||
return false; |
|||
} else { |
|||
InstanceStatusChangedEvent statusChange = (InstanceStatusChangedEvent)event; |
|||
String from = this.getLastStatus(event.getInstance()); |
|||
String to = statusChange.getStatusInfo().getStatus(); |
|||
return Arrays.binarySearch(this.ignoreChanges, from + ":" + to) < 0 && Arrays.binarySearch(this.ignoreChanges, "*:" + to) < 0 && Arrays.binarySearch(this.ignoreChanges, from + ":*") < 0; |
|||
} |
|||
} |
|||
|
|||
|
|||
@Override |
|||
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) { |
|||
|
|||
return Mono.fromRunnable(() -> { |
|||
|
|||
if (event instanceof InstanceStatusChangedEvent) { |
|||
log.info("Instance {} ({}) is {}", instance.getRegistration().getName(), |
|||
event.getInstance(), |
|||
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus()); |
|||
|
|||
String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(); |
|||
String messageText = null; |
|||
switch (status) { |
|||
// 健康检查没通过 |
|||
case "DOWN": |
|||
log.info("发送 健康检查没通过 的通知!"); |
|||
messageText = String |
|||
.format(template,titleAlarm, instance.getRegistration().getName(), event.getInstance(), |
|||
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "健康检查没通过通知", |
|||
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
|||
log.info(messageText); |
|||
break; |
|||
// 服务离线 |
|||
case "OFFLINE": |
|||
log.info("发送 服务离线 的通知!"); |
|||
messageText = String |
|||
.format(template,titleAlarm, instance.getRegistration().getName(), event.getInstance(), |
|||
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务离线通知", |
|||
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
|||
log.info(messageText); |
|||
break; |
|||
//服务上线 |
|||
case "UP": |
|||
log.info("发送 服务上线 的通知!"); |
|||
messageText = String |
|||
.format(template,titleNotice, instance.getRegistration().getName(), event.getInstance(), |
|||
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务上线通知", |
|||
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
|||
log.info(messageText); |
|||
break; |
|||
// 服务未知异常 |
|||
case "UNKNOWN": |
|||
log.info("发送 服务未知异常 的通知!"); |
|||
messageText = String |
|||
.format(template,titleAlarm, instance.getRegistration().getName(), event.getInstance(), |
|||
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务未知异常通知", |
|||
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
|||
log.info(messageText); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
} else { |
|||
log.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(), |
|||
event.getType()); |
|||
} |
|||
}); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue