【问题标题】:Create a project from command line从命令行创建项目
【发布时间】:2012-11-08 16:27:50
【问题描述】:

Sentry 捕获来自客户端应用程序的日志记录和错误。

我知道在 Sentry 中创建项目的唯一方法是在 Web 应用程序界面中手动提交表单。

我正在寻找一种以任何方式(选项、配置文件)从命令行将项目创建到 Sentry 中的方法?

这对于部署脚本非常有价值。否则无法实现自动化。

刚刚在谷歌搜索时发现了这个讨论,但没有答案:

https://groups.google.com/d/topic/getsentry/pWglAEHaPUk/discussion

有什么想法吗?

【问题讨论】:

  • 我认为这可能太具体了......甚至没有多少人知道哨兵是什么......你可能至少想提供一个到 getsentry.com 的链接,并且可能描述如何如果有办法在 python shell 中或仅在他们的管理页面或什么上执行此操作,通常会将项目添加到哨兵..
  • 嗯,这是一个很有价值的评论。问题已编辑。

标签: python django deployment sentry


【解决方案1】:

a django project,当然可以:

from sentry.models import Project
project = Project(...)
...
project.save()

编辑:您可以write a custom management command 获取命令行上的功能

由问题作者编辑:是的,它确实是一个 django 项目,所以就像 django 项目一样,我在以下三个步骤中自动化了我的部署:

  1. 从管理 Web 界面启动 Sentry,创建用户、团队和项目并调整设置
  2. 像处理任何 django 项目一样运行 dumpdata(sentry 将隐式调用 manage.py):

    sentry --config=sentry.conf.py dumpdata --indent=2 auth > auth_data.json

    sentry --config=sentry.conf.py dumpdata --indent=2 sentry > sentry_data.json

  3. 逐步部署:

    sentry --config=sentry.conf.py syncdb --noinput

    sentry --config=sentry.conf.py migrate

    sentry --config=sentry.conf.py loaddata auth_data.json

    sentry --config=sentry.conf.py loaddata sentry_data.json

效果很好。希望这对其他人有帮助。

【讨论】:

  • 嗯,这就是 B 计划。A 计划是看看命令行工具是否有更多选项,可能没有记录。我明天试试,非常感谢。
  • 用我的补充编辑了问题并接受了答案。谢谢@Timmy。
  • dumpdata -> loaddata 方法对我来说似乎有问题。想到的第一个想法是,您在不同的部署中使用相同的公钥/私钥组合。
【解决方案2】:

正如Sentry's docs官方所说:

# Bootstrap the Sentry environment
from sentry.utils.runner import configure
configure()

# Do something crazy
from sentry.models import Team, Project, User

user = User()
user.username = 'admin'
user.email = 'admin@localhost'
user.is_superuser = True
user.set_password('admin')
user.save()

team = Team()
team.name = 'Sentry'
team.owner = user
team.save()

project = Project()
project.team = team
project.owner = user
project.name = 'Default'
project.save()

key = ProjectKey.objects.filter(project=project)[0]
print 'SENTRY_DSN = "%s"' % (key.get_dsn(),)

https://docs.getsentry.com/on-premise/server/faq/

【讨论】:

  • configure() 使用默认的哨兵配置文件。如何指定 /home/me/path/to/my/project/sentry.conf.py ??
  • 快速查看code of the configure() method 建议改为调用 logan.runner.configure_app。另一种解决方案是坚持使用 configure() 并创建符号链接 ~/.sentry/sentry.conf.py -> /path/to/sentry.conf.py
  • 看起来链接已更改为:docs.getsentry.com/on-premise/server/faq
  • @abhishekmukherg 谢谢你,我已经编辑了我的答案
猜你喜欢
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-09
  • 1970-01-01
  • 2018-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多