Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[home] support telegram alert notify help doc #597

Merged
merged 2 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@
<artifactId>snmp4j</artifactId>
<version>3.6.7</version>
</dependency>
<!-- k8s client -->
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>10.0.1</version>
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.usthe.collector.collect.http.promethus.ParseException;
import com.usthe.common.util.StrBuffer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.StringUtils;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -253,7 +253,7 @@ else if (label != null && this.isCount(label.getName())) {
summary.setCount(buffer.toLong());
}
// 处理 "xxx{quantile=\"0\"} 0" 的格式
else if (StringUtils.isNotEmpty(this.currentQuantile)) {
else if (StringUtils.hasText(this.currentQuantile)) {
List<MetricFamily.Quantile> quantileList = summary.getQuantileList();
MetricFamily.Quantile quantile = new MetricFamily.Quantile();
quantile.setXLabel(StrBuffer.parseDouble(this.currentQuantile));
Expand All @@ -273,7 +273,7 @@ else if (StringUtils.isNotEmpty(this.currentQuantile)) {
histogram.setCount(buffer.toLong());
}
// 处理 "xxx{quantile=\"0\"} 0" 的格式
else if (StringUtils.isNotEmpty(this.currentBucket)) {
else if (StringUtils.hasText(this.currentBucket)) {
List<MetricFamily.Bucket> bucketList = histogram.getBucketList();
MetricFamily.Bucket bucket = new MetricFamily.Bucket();
bucket.setUpperBound(StrBuffer.parseDouble(this.currentBucket));
Expand Down
64 changes: 64 additions & 0 deletions home/docs/help/alert_telegram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
id: alert_telegram
title: 告警Telegram机器人通知
sidebar_label: 告警Telegram机器人通知
---

> 阈值触发后发送告警信息,通过 Telegram 机器人通知到接收人。

### 操作步骤

#### 在 Telegram 创建机器人, 获取 Bot Token 和 UserId

1. 使用 [@BotFather](https://t.me/BotFather) 创建自己的机器人并获取访问令牌`Token`

![telegram-bot](/img/docs/help/telegram-bot-1.png)

2. 获取 `User ID`

**给刚创建 Bot 随便发送一个信息**
访问 ```https://api.telegram.org/bot<TOKEN>/getUpdates```, 响应`Json`数据中`result.message.from.id` 值即为 `User ID`

```json
{
"ok":true,
"result":[
{
"update_id":632299191,
"message":{
"from":{
"id": "User ID"
},
"chat":{
},
"date":1673858065,
"text":"111"
}
}
]
}
```

3. 记录保存我们获得的 `Token` 和 `User Id`

#### 在 HertzBeat 新增告警通知人,通知方式为 Telegram Bot

1. **【告警通知】->【新增接收人】 ->【选择 Telegram 机器人通知方式】->【设置机器人Token和UserId】-> 【确定】**

![email](/img/docs/help/telegram-bot-2.png)

4. **配置关联的告警通知策略⚠️ 【新增通知策略】-> 【将刚设置的接收人关联】-> 【确定】**

> **注意⚠️ 新增了接收人并不代表已经生效可以接收告警信息,还需配置关联的告警通知策略,即指定哪些消息发给哪些接收人**。

![email](/img/docs/help/telegram-bot-3.png)


### Telegram 机器人通知常见问题

1. Telegram 未收到机器人告警通知

> 请排查在告警中心是否已有触发的告警信息
> 请排查是否配置正确机器人Token, UserId,是否已配置告警策略关联

其它问题可以通过交流群ISSUE反馈哦!
1 change: 1 addition & 0 deletions home/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"items": [
"help/alert_email",
"help/alert_webhook",
"help/alert_telegram",
"help/alert_wework",
"help/alert_dingtalk",
"help/alert_feishu",
Expand Down
Binary file added home/static/img/docs/help/telegram-bot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added home/static/img/docs/help/telegram-bot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added home/static/img/docs/help/telegram-bot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions manager/src/main/resources/define/app/app-fullsite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
category: service
app: fullsite
name:
zh-CN: 全站监控
zh-CN: SiteMap全站
en-US: SITE MAP
configmap:
- key: host
Expand Down Expand Up @@ -62,4 +62,4 @@ metrics:
method: GET
# 是否启用ssl/tls,即是http还是https,默认false
ssl: ^_^ssl^_^
parseType: sitemap
parseType: sitemap
4 changes: 2 additions & 2 deletions manager/src/main/resources/define/app/app-mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
category: db
app: mongodb
name:
zh-CN: Mongodb数据库
en-US: Mongodb
zh-CN: MongoDB数据库
en-US: MongoDB
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ private void initTtl(String expireTime) {

@Override
void saveData(CollectRep.MetricsData metricsData) {
if (metricsData.getCode() != CollectRep.Code.SUCCESS) {
return;
}
if (metricsData.getValuesList().isEmpty()) {
log.info("[warehouse iotdb] flush metrics data {} is null, ignore.", metricsData.getId());
return;
}
// tablet的deviceId添加引号会导致数据插入失败
List<MeasurementSchema> schemaList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ private boolean initTdEngineDatasource(WarehouseProperties.StoreProperties.TdEng

@Override
public void saveData(CollectRep.MetricsData metricsData) {
if (metricsData == null || metricsData.getValuesList().isEmpty() || metricsData.getFieldsList().isEmpty()) {
if (metricsData.getCode() != CollectRep.Code.SUCCESS) {
return;
}
if (metricsData.getValuesList().isEmpty()) {
log.info("[warehouse tdengine] flush metrics data {} is null, ignore.", metricsData.getId());
return;
}
String monitorId = String.valueOf(metricsData.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ public CollectRep.MetricsData getCurrentMetricsData(@NonNull Long monitorId, @No
@Override
public void saveData(CollectRep.MetricsData metricsData) {
String hashKey = metricsData.getId() + metricsData.getMetrics();
if (metricsData.getCode() != CollectRep.Code.SUCCESS) {
return;
}
if (metricsData.getValuesList().isEmpty()) {
log.debug("[warehouse memory] redis flush metrics data {} is null, ignore.", hashKey);
log.info("[warehouse memory] memory flush metrics data {} is null, ignore.", metricsData.getId());
return;
}
metricsDataMap.put(hashKey, metricsData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public CollectRep.MetricsData getCurrentMetricsData(@NonNull Long monitorId, @No
public void saveData(CollectRep.MetricsData metricsData) {
String key = String.valueOf(metricsData.getId());
String hashKey = metricsData.getMetrics();
if (metricsData.getCode() != CollectRep.Code.SUCCESS) {
return;
}
if (metricsData.getValuesList().isEmpty()) {
log.info("[warehouse redis] redis flush metrics data {} - {} is null, ignore.", key, hashKey);
return;
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/app/layout/passport/passport.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<global-footer [links]="links">
<div style="margin-top: 0">
HertzBeat {{ version }}<br />
Copyright &copy; 2021-2023
Copyright &copy; 2021-{{ currentYear }}
<a href="https://hertzbeat.com" target="_blank">hertzbeat.com</a>
<br />
Licensed under the Apache License, Version 2.0
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/app/layout/passport/passport.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class LayoutPassportComponent implements OnInit {
}
];

currentYear = new Date().getFullYear();

constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, @Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService) {}

ngOnInit(): void {
Expand Down