-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhenjian.hu
committed
Apr 26, 2020
0 parents
commit 5b2c317
Showing
6 changed files
with
247 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.idea |
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,22 @@ | ||
# Sentry-DingDing | ||
|
||
Fork `https://github.com/anshengme/sentry-dingding` | ||
|
||
Fix `Sentry 10 or the same error` | ||
|
||
[sentry-dingding issues](https://github.com/anshengme/sentry-dingding/issues/22) | ||
|
||
``` | ||
'Event' object has no attribute 'id' | ||
``` | ||
|
||
## 安装 | ||
|
||
``` | ||
# requirement.txt | ||
sentry-10-dingding | ||
``` | ||
|
||
docker-compose 安装的直接改成这个插件包就好了,如果帮你解决了问题,麻烦给个小星星. | ||
|
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,35 @@ | ||
#!/usr/bin/env python | ||
from setuptools import setup, find_packages | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name="sentry-10-dingding", | ||
version='1.0.0', | ||
author='season', | ||
author_email='[email protected]', | ||
url='https://github.com/cench/sentry-10-dingding', | ||
description='A Sentry extension which send errors stats to DingDing', | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
license='MIT', | ||
keywords='sentry dingding', | ||
include_package_data=True, | ||
zip_safe=False, | ||
package_dir={'': 'src'}, | ||
packages=find_packages('src'), | ||
install_requires=[ | ||
'sentry>=9.0.0', | ||
'requests', | ||
], | ||
entry_points={ | ||
'sentry.plugins': [ | ||
'sentry_dingding = sentry_dingding.plugin:DingDingPlugin' | ||
] | ||
}, | ||
classifiers=[ | ||
'Programming Language :: Python :: 2.7', | ||
"License :: OSI Approved :: MIT License", | ||
] | ||
) |
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,3 @@ | ||
# coding: utf-8 | ||
|
||
VERSION = "1.0.0" |
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,10 @@ | ||
# coding: utf-8 | ||
|
||
from django import forms | ||
|
||
|
||
class DingDingOptionsForm(forms.Form): | ||
access_token = forms.CharField( | ||
max_length=255, | ||
help_text='DingTalk robot access_token' | ||
) |
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,72 @@ | ||
# coding: utf-8 | ||
|
||
import json | ||
|
||
import requests | ||
from sentry.plugins.bases.notify import NotificationPlugin | ||
|
||
import sentry_dingding | ||
from .forms import DingDingOptionsForm | ||
|
||
DingTalk_API = "https://oapi.dingtalk.com/robot/send?access_token={token}" | ||
|
||
|
||
class DingDingPlugin(NotificationPlugin): | ||
""" | ||
Sentry plugin to send error counts to DingDing. | ||
""" | ||
author = 'season' | ||
author_url = 'https://github.com/cench/sentry-10-dingding' | ||
version = sentry_dingding.VERSION | ||
description = 'Send error counts to DingDing.' | ||
resource_links = [ | ||
('Source', 'https://github.com/cench/sentry-10-dingding'), | ||
('Bug Tracker', 'https://github.com/cench/sentry-10-dingding/issues'), | ||
('README', 'https://github.com/cench/sentry-10-dingding/blob/master/README.md'), | ||
] | ||
|
||
slug = 'DingDing' | ||
title = 'DingDing' | ||
conf_key = slug | ||
conf_title = title | ||
project_conf_form = DingDingOptionsForm | ||
|
||
def is_configured(self, project): | ||
""" | ||
Check if plugin is configured. | ||
""" | ||
return bool(self.get_option('access_token', project)) | ||
|
||
def notify_users(self, group, event, *args, **kwargs): | ||
self.post_process(group, event, *args, **kwargs) | ||
|
||
def post_process(self, group, event, *args, **kwargs): | ||
""" | ||
Process error. | ||
""" | ||
if not self.is_configured(group.project): | ||
return | ||
|
||
if group.is_ignored(): | ||
return | ||
|
||
access_token = self.get_option('access_token', group.project) | ||
send_url = DingTalk_API.format(token=access_token) | ||
title = u'【%s】的项目异常' % event.project.slug | ||
|
||
data = { | ||
"msgtype": "markdown", | ||
"markdown": { | ||
"title": title, | ||
"text": u"#### {title} \n\n > {message} \n\n [详细信息]({url})".format( | ||
title=title, | ||
message=event.title or event.message, | ||
url=u"{}events/{}/".format(group.get_absolute_url(), event.event_id), | ||
) | ||
} | ||
} | ||
requests.post( | ||
url=send_url, | ||
headers={"Content-Type": "application/json"}, | ||
data=json.dumps(data).encode("utf-8") | ||
) |