-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
325 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...va/io/github/smart/cloud/starter/monitor/autoconfigure/WeworkNoticeAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright © 2019 collin (1634753825@qq.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.github.smart.cloud.starter.monitor.autoconfigure; | ||
|
||
import io.github.smart.cloud.starter.monitor.component.GitLabComponent; | ||
import io.github.smart.cloud.starter.monitor.component.ReminderComponent; | ||
import io.github.smart.cloud.starter.monitor.component.RobotComponent; | ||
import io.github.smart.cloud.starter.monitor.listener.AppChangeWeworkNotice; | ||
import io.github.smart.cloud.starter.monitor.listener.wework.OfflineNotice; | ||
import io.github.smart.cloud.starter.monitor.listener.wework.ServiceNodeCountCheckNotice; | ||
import io.github.smart.cloud.starter.monitor.properties.MonitorProperties; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* 企业微信通知配置 | ||
* | ||
* @author collin | ||
* @date 2024-05-06 | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty(name = "smart.monitor.wework.enable", havingValue = "true", matchIfMissing = true) | ||
public class WeworkNoticeAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public RobotComponent robotComponent(final MonitorProperties monitorProperties) { | ||
return new RobotComponent(monitorProperties); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public ReminderComponent reminderComponent(final GitLabComponent gitLabComponent, final MonitorProperties monitorProperties) { | ||
return new ReminderComponent(gitLabComponent, monitorProperties); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public OfflineNotice offlineWeworkNotice(final RobotComponent robotComponent, final MonitorProperties monitorProperties, final ReminderComponent reminderComponent) { | ||
return new OfflineNotice(robotComponent, monitorProperties, reminderComponent); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public ServiceNodeCountCheckNotice serviceNodeCountCheckNotice(final RobotComponent robotComponent, final MonitorProperties monitorProperties, final ReminderComponent reminderComponent) { | ||
return new ServiceNodeCountCheckNotice(robotComponent, monitorProperties, reminderComponent); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public AppChangeWeworkNotice appChangeWeworkNotice(final MonitorProperties monitorProperties, final RobotComponent robotComponent, final ReminderComponent reminderComponent) { | ||
return new AppChangeWeworkNotice(monitorProperties, robotComponent, reminderComponent); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...main/java/io/github/smart/cloud/starter/monitor/listener/wework/AbstractWeworkNotice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.github.smart.cloud.starter.monitor.listener.wework; | ||
|
||
import io.github.smart.cloud.starter.monitor.component.ReminderComponent; | ||
import io.github.smart.cloud.starter.monitor.component.RobotComponent; | ||
import io.github.smart.cloud.starter.monitor.properties.MonitorProperties; | ||
import io.github.smart.cloud.starter.monitor.properties.ServiceInfoProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
import java.util.Set; | ||
|
||
@RequiredArgsConstructor | ||
public abstract class AbstractWeworkNotice<E extends ApplicationEvent> implements ApplicationListener<E> { | ||
|
||
protected final RobotComponent robotComponent; | ||
protected final MonitorProperties monitorProperties; | ||
protected final ReminderComponent reminderComponent; | ||
|
||
/** | ||
* 获取提醒人 | ||
* | ||
* @param serviceName | ||
* @return | ||
*/ | ||
protected String getReminderParams(String serviceName) { | ||
ServiceInfoProperties projectProperties = monitorProperties.getServiceInfos().get(serviceName); | ||
if (projectProperties == null) { | ||
return StringUtils.EMPTY; | ||
} | ||
Set<String> reminders = projectProperties.getReminders(); | ||
if (CollectionUtils.isEmpty(reminders)) { | ||
return StringUtils.EMPTY; | ||
} | ||
|
||
return reminderComponent.generateReminders(reminders); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...va/io/github/smart/cloud/starter/monitor/listener/wework/ServiceNodeCountCheckNotice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright © 2019 collin (1634753825@qq.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.github.smart.cloud.starter.monitor.listener.wework; | ||
|
||
import io.github.smart.cloud.starter.monitor.component.ReminderComponent; | ||
import io.github.smart.cloud.starter.monitor.component.RobotComponent; | ||
import io.github.smart.cloud.starter.monitor.event.notice.ServiceNodeCountCheckNoticeEvent; | ||
import io.github.smart.cloud.starter.monitor.properties.MonitorProperties; | ||
import io.github.smart.cloud.starter.monitor.properties.ServiceInfoProperties; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* 在线实例为0时,企业微信通知 | ||
* | ||
* @author collin | ||
* @date 2024-02-23 | ||
*/ | ||
public class ServiceNodeCountCheckNotice extends AbstractWeworkNotice<ServiceNodeCountCheckNoticeEvent> { | ||
|
||
public ServiceNodeCountCheckNotice(RobotComponent robotComponent, MonitorProperties monitorProperties, ReminderComponent reminderComponent) { | ||
super(robotComponent, monitorProperties, reminderComponent); | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ServiceNodeCountCheckNoticeEvent event) { | ||
String name = event.getName(); | ||
String reminders = getReminderParams(name); | ||
StringBuilder content = new StringBuilder(64); | ||
content.append("**服务**: ").append(name).append("\n"); | ||
|
||
ServiceInfoProperties serviceInfoProperties = monitorProperties.getServiceInfos().get(name); | ||
if (serviceInfoProperties != null) { | ||
Integer nodeCount = serviceInfoProperties.getNodeCount(); | ||
if (nodeCount != null) { | ||
content.append("**期望实例数**: ").append(nodeCount).append("\n"); | ||
} | ||
} | ||
content.append("**当前实例数**: <font color=\\\"warning\\\">").append(event.getNodeCount()).append("</font>\n"); | ||
if (StringUtils.isNotBlank(reminders)) { | ||
content.append(reminders); | ||
} | ||
robotComponent.sendWxworkNotice(robotComponent.getRobotKey(name), content.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.