-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[manager, web-app] Notification type supports slack webhook, upgrade …
…jdk version to JDK11 (#591) * [web-app] fix history echarts chart tooltip only show one instance (#365) * [workflow] upgrade issues-translator version 2.7 (#367) * [manger] add mockito unit test * [manger] add globalExceptionHandler mockito unit test (#368) * [manager] impl appController unit test case (#370) * 英文注释的补充 * Supplement of English notes * Supplementary English notes * Supplement of English notes * AppControllerTest Implementation of unit tests Co-authored-by: gaoxingcun <gxc01514416@alibaba-inc.com> * [warehouse] support Iotdb metrics data storage (#372) * add iotdb storage (saveData part) * implement getHistoryMetricData * save multiple instances at the same time implement getHistoryIntervalMetricData * [warehouse] reformat code * [warehouse] refactor code * [warehouse] refactor code * [warehouse] refactor code * [warehouse] fix insert node path container " ' parsed error * [warehouse] fix insert node path container " ' * parsed error * [warehouse] support iotdb rpc-port * support iotdb version 0.12 fix save data and select bug * replace Session with SessionPool * rule fix, 修复魔法值问题 Co-authored-by: tomsun28 <tomsun28@outlook.com> Co-authored-by: hujiaofen <hujiaofen@2dfire.com> * [webapp,warehouse] support historical interval aggregate data chart (#373) * [manger] add mockito unit test * [manger] impl unit test ParamDaoTest #360 * [manager] fix NoticeRuleDaoTest * [manger] impl unit test ParamDefineDaoTest #361 * [manger] impl unit test TagDaoTest #362 * [manger] add manger sql dao mockito unit test (#375) * [manger] add mockito unit test * [manger] add mockito unit test * [manger] impl unit test ParamDaoTest #360 * [manager] fix NoticeRuleDaoTest * [manger] impl unit test ParamDefineDaoTest #361 * [manger] impl unit test TagDaoTest #362 * [manager] I18nControllerTest and MonitorControllerTest Unit tests are written (#376) * I18ControllerTest Completion of the test class * MonitorControllerTest Unit tests are written * [manger] impl unit test AppServiceTest #355 * [hertzbeat] update use PromQL to collect metrics from promethues server (#456) * [manager] enhancement manager-monitors-page added gmtUpdate desc (#455) * [manager-monitors](增强)应用服务检测-网站检测-分页:添加默认name升序 (enhancement)manager-monitors-page added name asc * [manager-monitors](增强)应用服务检测-网站检测-分页:添加默认gmtUpdate降序 (enhancement)manager-monitors-page added gmtUpdate desc * [webapp] support monitors list sort by name, date (#458) * [manager] bugfix the gmtUpdate time not change when update monitor params (#459) * [alerter,collector,common,warehouse] refactor auto import component * [manager] Notification type supports telegram * [web-app] Notification type supports telegram * fix PMD Failure LowerCamelCaseVariableNamingRule * fix PMD check * fix ESLint Error * [manager] remove useless judgment * [manager] use thymeleaf to render notify content * [alerter, manager] use thymeleaf to render notify content * [manager] refactor rename method name renderContext to renderContent * [script, doc] upgrade jdk version to JDK11 * upgrade pmd plugin to support jdk11 * [common] fix pmd check * [manager, web-app] Notification type supports slack webhook Co-authored-by: tomsun28 <tomsun28@outlook.com> Co-authored-by: 铁甲小宝 <85919258+TJxiaobao@users.noreply.github.com> Co-authored-by: gaoxingcun <gxc01514416@alibaba-inc.com> Co-authored-by: zcx <48920254+Ceilzcx@users.noreply.github.com> Co-authored-by: hujiaofen <hujiaofen@2dfire.com> Co-authored-by: luxx <58515565+luxx-lq@users.noreply.github.com>
- Loading branch information
1 parent
ffd4b7a
commit f77d2b8
Showing
17 changed files
with
176 additions
and
18 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
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
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
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
72 changes: 72 additions & 0 deletions
72
...r/src/main/java/com/usthe/manager/component/alerter/impl/SlackAlertNotifyHandlerImpl.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,72 @@ | ||
package com.usthe.manager.component.alerter.impl; | ||
|
||
import com.usthe.common.entity.alerter.Alert; | ||
import com.usthe.common.entity.manager.NoticeReceiver; | ||
import com.usthe.manager.support.exception.AlertNoticeException; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Send alarm information by Slack Webhook | ||
* 通过Slack Webhook发送告警信息 | ||
* | ||
* @author <a href="mailto:gcwm99@gmail.com">gcdd1993</a> | ||
* @version 2.1 | ||
* Created by Musk.Chen on 2023/1/17 | ||
*/ | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
final class SlackAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl { | ||
private static final String SUCCESS = "ok"; | ||
private final RestTemplate restTemplate; | ||
|
||
@Override | ||
public void send(NoticeReceiver receiver, Alert alert) throws AlertNoticeException { | ||
try { | ||
var slackNotify = SlackNotifyDTO.builder() | ||
.text(renderContent(alert)) | ||
.build(); | ||
|
||
var entity = restTemplate.postForEntity(receiver.getSlackWebHookUrl(), slackNotify, String.class); | ||
if (entity.getStatusCode() == HttpStatus.OK && entity.getBody() != null) { | ||
var body = entity.getBody(); | ||
if (Objects.equals(SUCCESS, body)) { | ||
log.debug("Send Slack Success"); | ||
} else { | ||
log.warn("Send Slack Failed: {}", body); | ||
throw new AlertNoticeException(body); | ||
} | ||
} else { | ||
log.warn("Send Slack Failed {}", entity.getBody()); | ||
throw new AlertNoticeException("Http StatusCode " + entity.getStatusCode()); | ||
} | ||
} catch (Exception e) { | ||
throw new AlertNoticeException("[Slack Notify Error] " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public byte type() { | ||
return 8; | ||
} | ||
|
||
@Override | ||
protected String templateName() { | ||
return "alertNotifySlack"; | ||
} | ||
|
||
@Data | ||
@Builder | ||
private static class SlackNotifyDTO { | ||
private String text; | ||
} | ||
|
||
} |
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
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,7 @@ | ||
*[(${title})]* | ||
[(${targetLabel})] : [(${target})] | ||
[# th:if="${monitorId != null}"][(${monitorIdLabel})] : `[(${monitorId})]`[/] | ||
[# th:if="${monitorName != null}"][(${monitorNameLabel})] : [(${monitorName})][/] | ||
[(${priorityLabel})] : [(${priority})] | ||
[(${triggerTimeLabel})] : [(${triggerTime})] | ||
[(${contentLabel})] : [(${content})] |
52 changes: 52 additions & 0 deletions
52
...c/test/java/com/usthe/manager/component/alerter/impl/SlackAlertNotifyHandlerImplTest.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,52 @@ | ||
package com.usthe.manager.component.alerter.impl; | ||
|
||
import com.usthe.common.entity.alerter.Alert; | ||
import com.usthe.common.entity.manager.NoticeReceiver; | ||
import com.usthe.common.util.CommonConstants; | ||
import com.usthe.manager.AbstractSpringIntegrationTest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.util.StringUtils; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Map; | ||
|
||
/** | ||
* Test case for {@link SlackAlertNotifyHandlerImpl} | ||
* | ||
* @author <a href="mailto:gcwm99@gmail.com">gcdd1993</a> | ||
* @version 2.1 | ||
* Created by Musk.Chen on 2023/1/17 | ||
*/ | ||
@Slf4j | ||
class SlackAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest { | ||
|
||
@Resource | ||
private SlackAlertNotifyHandlerImpl slackAlertNotifyHandler; | ||
|
||
@Test | ||
void send() { | ||
var slackWebHook = System.getenv("SLACK_WEB_HOOK"); | ||
if (!StringUtils.hasText(slackWebHook)) { | ||
log.warn("Please provide environment variables SLACK_WEB_HOOK"); | ||
return; | ||
} | ||
var receiver = new NoticeReceiver(); | ||
receiver.setId(1L); | ||
receiver.setName("Mock 告警"); | ||
receiver.setSlackWebHookUrl(slackWebHook); | ||
var alert = new Alert(); | ||
alert.setId(1L); | ||
alert.setTarget("Mock Target"); | ||
var map = Map.of( | ||
CommonConstants.TAG_MONITOR_ID, "Mock monitor id", | ||
CommonConstants.TAG_MONITOR_NAME, "Mock monitor name" | ||
); | ||
alert.setTags(map); | ||
alert.setContent("mock content"); | ||
alert.setPriority((byte) 0); | ||
alert.setLastTriggerTime(System.currentTimeMillis()); | ||
|
||
slackAlertNotifyHandler.send(receiver, alert); | ||
} | ||
} |
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
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
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