No release in over 3 years
Low commit activity in last 3 years
qywechat exception notifier
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0

Runtime

 Project Readme

Qywechat::Notifier

为你的 Rails 应用添加企业微信异常监控。

Installation

Add this line to your Rails application's Gemfile:

gem 'qywechat-notifier'

or use the lastest version on Github:

gem 'qywechat-notifier', github: 'dao42/qywechat-notifier'

And then execute:

$ bundle

Usage

配置

创建配置文件,并修改配置项。

# config/initializers/qywechat_notifier.rb
Qywechat::Notifier.configure do |config|
  config.corpid = 'yourcorpid'
  config.corpsecret = 'yourcorpsecret'
  config.chatid = 'yourchatid'
end

各参数配置的含义:

CORPID: 参见说明

CORPSECRET: 参见说明

CHATID: 先配置为空,下面更新为 Rake 命令创建的群聊ID,参见说明

创建群聊会话

系统提供了 Rake 命令,帮助快速创建一个会话

$ rails create_groupchat

请按照引导创建群聊,创建成功后系统会发送一条消息,初始至少需要一位群主和一位群员。后续可手动去企业微信APP中添加其他成员。

别忘了更新第一步的配置中的 CHATID。

配置 exception_notification,启用插件

# config/initializers/exception_notification.rb
require 'exception_notification/rails'
require 'exception_notification/sidekiq'

ExceptionNotification.configure do |config|
  ...
  ...
  config.add_notifier :qy_wechat, { filter_exception: true }
end

选项 filter_exception 控制是否过滤Rails内部异常堆栈,只显示应用自身堆栈,默认为 true

完成

到此,所有 Rails 应用异常都可以发送到群聊之中了。

定制异常内容

额外异常内容,可写入 request.env['exception_notifier.exception_data'] 中,如:

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base

  # 增加以下内容
  before_action :prepare_exception_notifier

  private
  def prepare_exception_notifier
    request.env['exception_notifier.exception_data'] = {
      current_user: current_user&.id
    }
  end
end

版本记录

  • 0.4.0

支持 filter_exception 选项

  • 0.3.0

修复已知bug

  • 0.1.0

发布内测版

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dao42/qywechat-notifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Qywechat::Notifier project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.