×
Community Blog Best Practices for Configuring Alert Rules to Send Notifications to DingTalk, Slack, and Telegram for ApsaraDB for MongoDB

Best Practices for Configuring Alert Rules to Send Notifications to DingTalk, Slack, and Telegram for ApsaraDB for MongoDB

This article provides best practices for configuring alert rules in ApsaraDB for MongoDB to send notifications to DingTalk, Slack, and Telegram.

By Decai Xu

1. Configure a disk usage alert rule for your ApsaraDB for MongoDB instance

1.1. Add an alert rule in the ApsaraDB for MongoDB console

1
2
3

1.2. Configure an alert policy

4

1.3. Add an alert contact group

5

1.4. The alert rule is added

6

2. Add Robot to the DingTalk group and obtain the webhook URL

2.1. Add Robot to a DingTalk group

7
8
9
10
11

2.2. Add a Robot name and multiple alert keywords

12

2.3. Obtain the webhook URL

13

2.4. Check whether Robot is successfully added to the DingTalk group

14
15

2.5. Add a DingTalk alert contact, configure a webhook URL, and test the alert rule in the CloudMonitor console

16
17
18
19

2.6. The DingTalk alert contact is added

20
21

3. Add an alert application to a Slack channel and obtain the webhook URL

3.1. Create a channel

22
23

3.2. Add Incoming webhook to the channel

24
25
26

3.3. Obtain the webhook URL

27
28
29

3.4. Check whether the webhook is successfully added to the channel

30

3.5. Add a Slack alert contact, configure the webhook URL, and test the alert rule in the CloudMonitor console

31
32
33

3.6. The Slack alert contact is added

34
35

3.7. Add the DingTalk alert contact and Slack alert contact to the alert contact group

36
37
38

4. Receive an alert notification in the DingTalk group and Slack channel after the alert rule is triggered

4.1. Alert notification in the DingTalk group

39
40
41

4.2. Alert notification in the Slack channel

42
43
44

5. Integrate alerts into Telegram

5.1. Add BotFather to Telegram

45

5.2. Talk with BotFather to create a bot and get the bot API token

46
47

5.3. Disable the bot group private mode

48

5.4. Log on to the Telegram Bot service platform from www.teleme.io

49
50
51

5.5. Add the bot token to manage robots

52
53

5.6. Add a bot to a Telegram group

54
55
56

5.7. Test messages to be sent with the Bot in the Telegram Bot service platform

57
58
59

5.8 Deployment PrometheusAlert on your ECS instance

5.8.1. Purchase an ECS instance that runs the CentOS 7 operating system in the ECS Console

5.8.2. Deploy the PrometheusAlert on the ECS instance

https://github.com/feiyu563/PrometheusAlert#Prometheusalert%E5%85%A8%E5%AE%B6%E6%A1%B6%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8

5.8.2.1 Download and decompress the installation package of PrometheusAlert
wget https://github.com/feiyu563/PrometheusAlert/releases/download/v4.8.1/linux.zip && unzip linux.zip && cd linux/
5.8.2.2. Replace the related information in the configuration file
sed -i '/^open-tg=/c\open-tg=1' /root/linux/conf/app.conf                 # open telegram channel
sed -i '/^TG_TOKEN=/c\TG_TOKEN=xxxxxx' /root/linux/conf/app.conf          # replaced by your telegram bot token
sed -i '/^TG_MODE_CHAN=/c\TG_MODE_CHAN=1' /root/linux/conf/app.conf       # send alert to group or channel
sed -i '/^TG_USERID=/c\TG_USERID=xxxx' /root/linux/conf/app.conf          # replaced by your telegram user id
sed -i '/^TG_CHANNAME/c\TG_CHANNAME=xxxx' /root/linux/conf/app.conf       # replaced by your telegram group or channel id

You can call the getUpdates API to obtain TG_TOKEN, TG_USERID, and TG_CHANNAME.

https://api.telegram.org/bot<token>/getUpdates

60

5.8.2.3. Run PrometheusAlert in the background
nohup ./PrometheusAlert &

5.9. Log on to the PrometheusAlert panel from the port of your ECS instance 8080. The default logon account and password are configured in the app.conf file

5.9.1. Add Alibaba Cloud alerts to a custom template of Telegram

61
62

Template content:

Alibaba Cloud {{.AlertState}}INFO
>**{{.AlertName}}**
>ALERT LEVEL: {{.TriggerLevel}}
START TIME: {{GetTime .Timestamp}}
HOST: {{.InstanceName}}
------------DETAILS--------------
metricName: {{.MetricName}}
expression: {{.Expression}}
signature: {{.Signature}}
metricProject: {{.MetricProject}}
userId: {{.UserId}}
namespace: {{.Namespace}}
preTriggerLevel: {{.PreTriggerLevel}}
ruleId: {{.RuleId}}
dimensions: {{.Dimensions}}
**CURRENT VALUE:{{.CurValue}}**

63

5.9.2. Test the alert channel

64
65

A alert test message is received.

66

5.10. Add the PrometheusAlert webhook URL to the alert rule and test the rule

5.10.1 Obtain the PrometheusAlert webhook URL

67

5.10.2. Add the webhook URL to the alert rule

68

69

5.10.3. Test alerts to be sent

70
71

5.10.4. Check whether the webhook URL is added to the alert rule

72

5.11. Normal alert sending and receiving

73
74
75

0 1 0
Share on

ApsaraDB

504 posts | 155 followers

You may also like

Comments