-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hertzbeat] support sms alert notice (#503)
[hertzbeat] support sms alert notice [docs] support sms config docs [home] update doc [web-app] fix eslint
- Loading branch information
Showing
12 changed files
with
369 additions
and
15 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
88 changes: 88 additions & 0 deletions
88
common/src/main/java/com/usthe/common/service/TencentSmsClient.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,88 @@ | ||
package com.usthe.common.service; | ||
|
||
import com.tencentcloudapi.common.Credential; | ||
import com.tencentcloudapi.sms.v20210111.SmsClient; | ||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; | ||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; | ||
import com.tencentcloudapi.sms.v20210111.models.SendStatus; | ||
import com.usthe.common.config.CommonProperties; | ||
import com.usthe.common.support.exception.SendMessageException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* sms service client for tencent cloud | ||
* @author tom | ||
* @date 2022/12/17 17:41 | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty("common.sms.tencent.app-id") | ||
@Slf4j | ||
public class TencentSmsClient { | ||
|
||
private static final String RESPONSE_OK = "Ok"; | ||
private static final String REGION = "ap-guangzhou"; | ||
|
||
private SmsClient smsClient; | ||
private String appId; | ||
private String signName; | ||
private String templateId; | ||
|
||
public TencentSmsClient(CommonProperties properties) { | ||
if (properties == null || properties.getSms() == null || properties.getSms().getTencent() == null) { | ||
log.error("init error, please config TencentSmsClient props in application.yml"); | ||
throw new IllegalArgumentException("please config TencentSmsClient props"); | ||
} | ||
initSmsClient(properties.getSms().getTencent()); | ||
} | ||
|
||
private void initSmsClient(CommonProperties.TencentSmsProperties tencent) { | ||
this.appId = tencent.getAppId(); | ||
this.signName = tencent.getSignName(); | ||
this.templateId = tencent.getTemplateId(); | ||
Credential cred = new Credential(tencent.getSecretId(), tencent.getSecretKey()); | ||
smsClient = new SmsClient(cred, REGION); | ||
} | ||
|
||
/** | ||
* 发送短信 | ||
* @param appId appId | ||
* @param signName sign name | ||
* @param templateId template id | ||
* @param templateValues template values | ||
* @param phones phones num | ||
* @return true when send success | ||
*/ | ||
public void sendMessage(String appId, String signName, String templateId, | ||
String[] templateValues, String[] phones) { | ||
SendSmsRequest req = new SendSmsRequest(); | ||
req.setSmsSdkAppId(appId); | ||
req.setSignName(signName); | ||
req.setTemplateId(templateId); | ||
req.setTemplateParamSet(templateValues); | ||
req.setPhoneNumberSet(phones); | ||
try { | ||
SendSmsResponse smsResponse = this.smsClient.SendSms(req); | ||
SendStatus sendStatus = smsResponse.getSendStatusSet()[0]; | ||
if (!RESPONSE_OK.equals(sendStatus.getCode())) { | ||
throw new SendMessageException(sendStatus.getCode() + ":" + sendStatus.getMessage()); | ||
} | ||
} catch (Exception e) { | ||
log.warn(e.getMessage()); | ||
throw new SendMessageException(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* 发送短信 | ||
* @param templateValues template values | ||
* @param phones phones num | ||
* @return true when send success | ||
*/ | ||
public void sendMessage(String[] templateValues, String[] phones) { | ||
sendMessage(this.appId, this.signName, this.templateId, templateValues, phones); | ||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
common/src/main/java/com/usthe/common/support/exception/SendMessageException.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,12 @@ | ||
package com.usthe.common.support.exception; | ||
|
||
/** | ||
* send message exception | ||
* @author tom | ||
* @date 2022/5/8 17:59 | ||
*/ | ||
public class SendMessageException extends RuntimeException { | ||
public SendMessageException(String message) { | ||
super(message); | ||
} | ||
} |
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,64 @@ | ||
--- | ||
id: custom-config | ||
title: 常见参数配置 | ||
sidebar_label: 常见参数配置 | ||
--- | ||
|
||
这里描述了如果配置短信服务器,内置可用性告警触发次数等。 | ||
|
||
**`hertzbeat`的配置文件`application.yml`** | ||
|
||
### 配置HertzBeat的配置文件 | ||
修改位于 `hertzbeat/config/application.yml` 的配置文件 | ||
注意⚠️docker容器方式需要将application.yml文件挂载到主机本地 | ||
安装包方式解压修改位于 `hertzbeat/config/application.yml` 即可 | ||
|
||
1. 配置短信发送服务器 | ||
|
||
> 只有成功配置了您自己的短信服务器,监控系统内触发的告警短信才会正常发送。 | ||
在`application.yml`新增如下腾讯平台短信服务器配置(参数需替换为您的短信服务器配置) | ||
```yaml | ||
common: | ||
sms: | ||
tencent: | ||
secret-id: AKIDbQ4VhdMr89wDedFrIcgU2PaaMvOuBCzY | ||
secret-key: PaXGl0ziY9UcWFjUyiFlCPMr77rLkJYlyA | ||
app-id: 1435441637 | ||
sign-name: 赫兹跳动 | ||
template-id: 1343434 | ||
``` | ||
2. 配置告警自定义参数 | ||
> 如果您收到频繁的内置可用性告警,或在您所在网络抖动厉害,建议调整以下参数 | ||
```yaml | ||
alerter: | ||
# 自定义控制台地址 | ||
console-url: https://console.tancloud.cn | ||
# 告警触发评估间隔基础时间,相同重复告警在2倍此时间内不会被重复连续触发 单位毫秒 | ||
alert-eval-interval-base: 600000 | ||
# 告警触发评估间隔最大时间,相同重复告警最多在此时间段被抑制 单位毫秒 | ||
max-alert-eval-interval: 86400000 | ||
# 内置可用性告警连续触发几次才会真正发送告警 默认1次,当网络环境不好,不想频繁收到可用性告警时,可将此值调大(3) | ||
system-alert-trigger-times: 1 | ||
``` | ||
3. 使用外置redis代替内存存储实时指标数据 | ||
> 默认我们的指标实时数据存储在内存中,可以配置如下来使用redis代替内存存储。 | ||
注意⚠️ `memory.enabled: false, redis.enabled: true` | ||
```yaml | ||
warehouse: | ||
store: | ||
memory: | ||
enabled: false | ||
init-size: 1024 | ||
redis: | ||
enabled: true | ||
host: 127.0.0.1 | ||
port: 6379 | ||
password: 123456 | ||
``` |
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
65 changes: 65 additions & 0 deletions
65
home/i18n/en/docusaurus-plugin-content-docs/current/start/custom-config.md
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,65 @@ | ||
--- | ||
id: custom-config | ||
title: Advanced Config | ||
sidebar_label: Advanced Config | ||
--- | ||
|
||
This describes how to configure the SMS server, the number of built-in availability alarm triggers, etc. | ||
|
||
**Configuration file `application.yml` of `hertzbeat`** | ||
|
||
### Configure the configuration file of HertzBeat | ||
|
||
Modify the configuration file located at `hertzbeat/config/application.yml` | ||
Note ⚠️The docker container method needs to mount the application.yml file to the local host | ||
The installation package can be decompressed and modified in `hertzbeat/config/application.yml` | ||
|
||
1. Configure the SMS sending server | ||
|
||
> Only when your own SMS server is successfully configured, the alarm SMS triggered in the monitoring system will be sent normally. | ||
Add the following Tencent platform SMS server configuration in `application.yml` (parameters need to be replaced with your SMS server configuration) | ||
```yaml | ||
common: | ||
sms: | ||
tencent: | ||
secret-id: AKIDbQ4VhdMr89wDedFrIcgU2PaaMvOuBCzY | ||
secret-key: PaXGl0ziY9UcWFjUyiFlCPMr77rLkJYlyA | ||
app-id: 1435441637 | ||
sign-name: XX Technology | ||
template-id: 1343434 | ||
``` | ||
2. Configure alarm custom parameters | ||
> If you receive frequent built-in availability alarms, or the network jitter is severe in your area, it is recommended to adjust the following parameters | ||
```yaml | ||
alerter: | ||
# Custom console address | ||
console-url: https://console.tancloud.cn | ||
# Alarm trigger evaluation interval basic time, the same repeated alarm will not be repeatedly triggered continuously within 2 times this time, unit milliseconds | ||
alert-eval-interval-base: 600000 | ||
# The maximum time between alarm trigger evaluation intervals, the same repeated alarms can be suppressed at most during this time period, in milliseconds | ||
max-alert-eval-interval: 86400000 | ||
# The built-in availability alarm will be triggered several times in a row before the actual alarm is sent. The default is 1 time. When the network environment is not good and you don't want to receive availability alarms frequently, you can increase this value (3) | ||
system-alert-trigger-times: 1 | ||
``` | ||
3. Use external redis instead of memory to store real-time indicator data | ||
> By default, the real-time data of our indicators is stored in memory, which can be configured as follows to use redis instead of memory storage. | ||
Note ⚠️ `memory.enabled: false, redis.enabled: true` | ||
```yaml | ||
warehouse: | ||
store: | ||
memory: | ||
enabled: false | ||
init-size: 1024 | ||
redis: | ||
enabled: true | ||
host: 127.0.0.1 | ||
port: 6379 | ||
password: 123456 | ||
``` |
2 changes: 1 addition & 1 deletion
2
home/i18n/en/docusaurus-plugin-content-docs/current/start/mysql-change.md
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.