sentry
# 要求
23.6.0以后需要docker-compose 2
sudo rm /usr/local/bin/docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.19.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
1
2
3
4
5
6
7
2
3
4
5
6
7
# 下载
# 下载sentry源码包
git clone https://github.com/getsentry/self-hosted.git sentry
1
# 配置
# 编辑.env文件
SENTRY_EVENT_RETENTION_DAYS=7
SENTRY_BIND=9000
1
2
3
2
3
# 编辑sentry/config.example.yml
添加邮箱相关配置
vi sentry/config.example.yml
#邮箱配置
mail.host: 'smtp.qq.com'
mail.port: 587
mail.username: '2411776061@qq.com'
mail.password: 'rxxxxxxxxxxxxxd'
mail.use-tls: true
mail.use-ssl: false
mail.from: '2411776061@qq.com'
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 安装
执行安装命令 ,过程会提示你是否要上传到他们官方服务器,选n,然后按提示创建一个管理员账号,最后耐心等待安装完成
./install.sh
1
Hey, so ... we would love to automatically find out about issues with your
Sentry instance so that we can improve the product. Turns out there is an app
for that, called Sentry. Would you be willing to let us automatically send data
about your instance upstream to Sentry for development and debugging purposes?
y / yes / 1
n / no / 0
(Btw, we send this to our own self-hosted Sentry instance, not to Sentry SaaS,
so that we can be in this together.)
Here's the info we may collect:
- OS username
- IP address
- install log
- runtime errors
- performance data
Thirty (30) day retention. No marketing. Privacy policy at sentry.io/privacy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Would you like to create a user account now?
1
# 启动
按提示执行启动命令
docker-compose up -d
1
# 更新配置
如果需要更新配置(会删除容器重新创建)
docker-compose down
docker-compose up -d
1
2
2
# 代理
准备一个nginx,并配置https,将其转发到sentry主机的9000端口即可
# 钉钉
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import os
from flask import request, Flask # flask模块
from dingtalkchatbot.chatbot import DingtalkChatbot # 钉钉发送群消息模块
# 将数据写入到文件中
def open_file(data):
path = './temp.json'
# Delete the file if it exists
if os.path.exists(path):
os.remove(path)
# Write data to the file
with open(path, 'w') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
# 接收数据
def get_data():
post_data = request.get_data() # Get the raw POST data
data = json.loads(post_data) # Convert JSON data to a dictionary
return data
# Open函数和GetData函数用作获取数据,对数据进行分析使用
# Flask通用配置
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
@app.route('/webhook/test/', methods=['POST'])
def issue_create():
data = get_data()
project = data.get('project', '')
level = data.get('level', '')
url = data.get('url', '')
environment = data['event'].get('environment', '') if 'event' in data and 'environment' in data['event'] else ''
types = data['event'].get('title', '') if 'event' in data and 'title' in data['event'] else ''
messages = data.get('message', '')
culprit = data.get('culprit', '')
message = '## 项目:%s ##\n' \
'告警等级:%s\n' \
'错误地址:%s\n' \
'环境:%s\n' \
'类型:%s\n' \
'主要告警信息:%s\n' \
'主要原因:%s\n' % (project, level, url, environment, types, messages, culprit)
print(message)
send_message(message)
return "OK", 200
@app.route('/check', methods=['GET'])
def Check():
return "OK", 200
def send_message(message):
webhook = 'https://oapi.dingtalk.com/robot/send?access_token=5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb'
xiaoding = DingtalkChatbot(webhook)
xiaoding.send_text(msg=message, is_at_all=False) # is_at_all参数为True表示@所有人
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0', port=8866)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
services:
send_dingding_py:
image: python:3.10.4
working_dir: /var/www/data
ports:
- 8866:8866
volumes:
- ./data:/var/www/data
command: ["/var/www/data/venv/bin/python", "main.py"]
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
http://172.31.23.73:8866/webhook/test/
1
Last Updated: 2023/11/08, 14:45:54