向syslog、slack、email、{your_plugin}发送严重错误。
critbot的Python项目详细描述
安装:
pip install critbot
添加到“config.py”文件:
import critbot.plugins.syslog import critbot.plugins.slack import critbot.plugins.email from critbot import crit_defaults import logging crit_defaults.subject = 'MyService host:port CRIT' crit_defaults.plugins = [ critbot.plugins.syslog.plugin(), critbot.plugins.slack.plugin( token='Get it from https://my.slack.com/services/new/bot', channel='#general', # '@private' or '#channel' users='', # '@user1 @user2 @userN' ), critbot.plugins.email.plugin( to='Name1 <user1@example.com>, Name2 <user2@example.com>', user='critbot@example.com', # Add more config if not GMail. password='pa$$word', ), ] crit_defaults.crit_in_crit = logging.getLogger('critbot').critical
检查其他配置选项及其默认值,例如“seconds_per_notification=60”和“spam=false”:
- https://github.com/denis-ryzhkov/critbot/blob/master/critbot/core.py#L23-“临界值默认值”
- https://github.com/denis-ryzhkov/critbot/blob/master/critbot/core.py#L38-“临界值”
- https://github.com/denis-ryzhkov/critbot/blob/master/critbot/plugins/syslog.py#L17
- https://github.com/denis-ryzhkov/critbot/blob/master/critbot/plugins/slack.py#L14
- https://github.com/denis-ryzhkov/critbot/blob/master/critbot/plugins/email.py#L14
在项目的其他文件中使用“crit”:
from my_project import config from critbot import crit try: 1/0 except Exception: crit() # More processing if needed. try: 1/0 except Exception: crit(also='test2') if True: crit('test3')
如果您使用http://supervisord.org/ 然后,您可以使用以下命令监视stderr、exited和fatal状态:
[eventlistener:critvisor] command=critvisor /path/to/config.py events=PROCESS_LOG_STDERR,PROCESS_STATE_EXITED,PROCESS_STATE_FATAL [program:my_program] stderr_events_enabled=true Optional "crit_defaults.skip_stderrs" list allows to avoid some "safe" crits. Optional "crit_defaults.max_stderr_crit_length" allows to save e.g. Slack from being broken.
如果要将小脚本的stderr转换为crit:
stdcrit /path/to/config.py /path/to/script.py arg...
要阻止来自同一主机上多个进程的垃圾邮件:
crit_defaults.stop_spam_file.enabled = True # "crit_defaults.stop_spam_file.path" defaults to "/run/lock/critbot" - RAM, no disk IO.
要阻止来自多个主机的垃圾邮件:
apt-get install libmemcached-dev zlib1g-dev pip install pylibmc crit_defaults.mc.enabled = True And either "apt-get install memcached" or update "crit_defaults.mc.servers" list.
请叉https://github.com/denis-ryzhkov/critbot 并使用内部的新插件创建拉取请求。