Skip to content

Commit

Permalink
update enterprise wechat notify (#854)
Browse files Browse the repository at this point in the history
* update enterprise wechat notify

* add enterprise wechat app document and test unit for WeChatAppAlertNotifyHandlerImpl

---------

Co-authored-by: hudongdong <hudongdong9406@zto.com>
  • Loading branch information
tomsun28 and hudongdong authored Apr 8, 2023
1 parent 0747bf0 commit ca5935b
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 21 deletions.
34 changes: 34 additions & 0 deletions home/docs/help/alert_enterprise_wechat_app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: alert_enterprise_wechat_app
title: Alert Enterprise Wechat App notification
sidebar_label: Alert Enterprise Wechat App notification
keywords: [open source monitoring tool, open source alerter, open source Enterprise Wechat App notification]
---

> After the threshold is triggered send alarm information and notify the recipient by enterprise WeChat App.
### Operation steps

1. **【Enterprise Wechat backstage】-> 【App Management】-> 【Create an app】-> 【Set App message】->【Copy AgentId and Secret adding successfully】**

![email](/img/docs/help/alert-wechat-1.jpg)

2. **【Alarm notification】->【Add new recipient】 ->【Select Enterprise WeChat App notification method】->【Set Enterprise WeChat ID,Enterprise App ID and Enterprise App Secret 】-> 【Confirm】**

![email](/img/docs/help/alert-wechat-2.jpg)

3. **Configure the associated alarm notification strategy⚠️ 【Add new notification strategy】-> 【Associate the recipient just set】-> 【Confirm】**

> **Note⚠️ Adding a new recipient does not mean that it is effective to receive alarm information. It is also necessary to configure the associated alarm notification strategy, that is, to specify which messages are sent to which recipients.**
![email](/img/docs/help/alert-wechat-3.jpg)


### Enterprise WeChat App common issues

1. Enterprise WeChat App did not receive the alarm notification.
> Please check if the user has application permissions.
> Please check if the enterprise application callback address settings are normal.
> Please check if the server IP is on the enterprise application whitelist.
Other issues can be fed back through the communication group ISSUE!
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: alert_enterprise_wechat_app
title: 企业微信应用告警通知
sidebar_label: 企业微信应用告警通知
keywords: [开源告警系统, 开源监控告警系统, 企业微信应用告警通知]
---

> 阈值触发后发送告警信息,通过企业微信应用通知到接收人.
### Operation steps

1. **【企业微信后台管理】-> 【App管理】-> 【创建一个新的应用】-> 【设置应用信息】->【添加成功后复制应用的AgentId和Secret】**

![email](/img/docs/help/alert-wechat-1.jpg)

2. **【告警通知】->【新增接收人】 ->【选择企业微信应用通知方式】->【设置企业ID,企业应用id和应用的secret 】-> 【确定】**

![email](/img/docs/help/alert-wechat-2.jpg)

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

> **注意⚠️ 新增了接收人并不代表已经生效可以接收告警信息,还需配置关联的告警通知策略,即指定哪些消息发给哪些接收人。**
![email](/img/docs/help/alert-wechat-3.jpg)


### 企业微信应用通知常见问题

1. 企业微信应用未收到告警通知.
> 请检查用户是否具有应用程序权限.
> 请检查企业应用程序回调地址设置是否正常.
> 请检查服务器IP是否在企业应用程序白名单上.
其它问题可以通过交流群ISSUE反馈哦!
3 changes: 2 additions & 1 deletion home/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
"help/alert_wework",
"help/alert_dingtalk",
"help/alert_feishu",
"help/alert_console"
"help/alert_console",
"help/alert_enterprise_wechat_app"
]
},
"help/issue"
Expand Down
Binary file added home/static/img/docs/help/alert-wechat-1.jpg
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/alert-wechat-2.jpg
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/alert-wechat-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import java.util.Objects;

/**
* @description:
* @author: hdd
* @create: 2023/04/04
* WeChat app alert notify impl
* @author hdd
* @create 2023/04/04
*/
@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -72,7 +72,7 @@ public void send(NoticeReceiver receiver, Alert alert) throws AlertNoticeExcepti
}
}
} catch (Exception e) {
throw new AlertNoticeException("[WebHook Notify Error] " + e.getMessage());
throw new AlertNoticeException("[Enterprise WeChat Notify Error] " + e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import lombok.NoArgsConstructor;

/**
* @description:
* @author: hdd
* @create: 2023/04/05
* WeChatAppDTO
* @author hdd
* @create 2023/04/05
*/
@Data
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import lombok.NoArgsConstructor;

/**
* @description:
* @author: hdd
* @create: 2023/04/05
* WeChatAppReq
* @author hdd
* @create 2023/04/05
*/
@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
package org.dromara.hertzbeat.manager.component.alerter.impl;

import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.web.client.RestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hertzbeat.common.entity.alerter.Alert;
import org.dromara.hertzbeat.common.entity.manager.NoticeReceiver;
import org.dromara.hertzbeat.common.util.CommonConstants;
import org.dromara.hertzbeat.manager.AbstractSpringIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
* @description:
* @author: hdd
* @create: 2023/04/05
* unit test case for WeChatAppAlertNotifyHandlerImpl
*
* @author hdd
* @create 2023/04/05
*/
public class WeChatAppAlertNotifyHandlerImplTest {
@Slf4j
public class WeChatAppAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest {


@InjectMocks
@Resource
private WeChatAppAlertNotifyHandlerImpl weChatAppAlertNotifyHandler;

@Mock
private RestTemplate restTemplate;

@Test
public void send() {
String corpId = System.getenv("CORP_ID");
String agentId = System.getenv("AGENT_ID");
String appSecret = System.getenv("APP_SECRET");
if (!StringUtils.hasText(corpId) || !StringUtils.hasText(agentId) || !StringUtils.hasText(appSecret)) {
log.warn("Please provide environment variables CORP_ID, TG_USER_ID APP_SECRET");
return;
}
NoticeReceiver receiver = new NoticeReceiver();
receiver.setId(1L);
receiver.setName("WeChat App 告警");
receiver.setCorpId(corpId);
receiver.setAgentId(Integer.valueOf(agentId));
receiver.setAppSecret(appSecret);
Alert alert = new Alert();
alert.setId(1L);
alert.setTarget("Mock Target");
Map<String, String> map = new HashMap<>();
map.put(CommonConstants.TAG_MONITOR_ID, "Mock monitor id");
map.put(CommonConstants.TAG_MONITOR_NAME, "Mock monitor name");
alert.setTags(map);
alert.setContent("mock content");
alert.setPriority((byte) 0);
alert.setLastTriggerTime(System.currentTimeMillis());

weChatAppAlertNotifyHandler.send(receiver, alert);
}


}
8 changes: 8 additions & 0 deletions script/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ CREATE TABLE hzb_notice_receiver
hook_url varchar(255) comment 'URL地址, 通知方式为webhook有效',
wechat_id varchar(255) comment 'openId, 通知方式为微信公众号或企业微信机器人有效',
access_token varchar(255) comment '访问token, 通知方式为钉钉机器人有效',
tg_bot_token varchar(255) comment 'Telegram bot token, 通知方式为Telegram机器人有效',
tg_user_id varchar(255) comment 'Telegram user id, 通知方式为Telegram机器人有效',
slack_web_hook_url varchar(255) comment 'URL地址 : 通知方式为Slack有效',
corp_id varchar(255) comment '企业信息 : 通知方式为Enterprise WeChat app message有效',
agent_id varchar(255) comment '企业微信应用id : 通知方式为Enterprise WeChat app message有效',
app_secret varchar(255) comment '企业微信应用secret : 通知方式为Enterprise WeChat app message有效',
discord_channel_id varchar(255) comment 'Discord 频道id: 通知方式为Discord有效',
discord_bot_token varchar(255) comment 'Discord 机器人Token: 通知方式为Discord有效',
creator varchar(100) comment '创建者',
modifier varchar(100) comment '最新修改者',
gmt_create timestamp default current_timestamp comment 'create time',
Expand Down

0 comments on commit ca5935b

Please sign in to comment.