This commit is contained in:
Казьмин Василий Васильевич 2020-05-11 13:14:41 +03:00
parent 1fe8045b31
commit 9780e5c2e8
16 changed files with 152 additions and 10 deletions

View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/Gemfile

1
Gemfile Normal file
View File

@ -0,0 +1 @@
gem "bunny", ">= 2.14.1"

View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/README.md

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# RabbitMQ Plugin for Redmine
This plugin is intended to provide basic integration with RabbitMQ , by sending notifications of updates to issues to a RabbitMQ.
Following actions will result in notifications to Jabber:
- Create and update issues
## Installation & Configuration
- The RabbitMQ Notifications Plugin depends on the [bunny](https://github.com/ruby-amqp/bunny). This can be installed with: $ gem install bunny
- Then install the Plugin following the general Redmine [plugin installation instructions](http://www.redmine.org/wiki/redmine/Plugins).
- Go to the Plugins section of the Administration page, select Configure.
- On this page fill out the Jabber ID and password for user who will sends messages, and the MUC room where to send messages to.
- Restart your Redmine web servers (e.g. mongrel, thin, mod_rails).

View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/README.rdoc

3
README.rdoc Normal file
View File

@ -0,0 +1,3 @@
= rabbitmq
Description goes here

1
app
View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/app

View File

@ -0,0 +1,27 @@
<fieldset>
<legend><%= l(:rabbitmq_label_settings) %></legend>
<p>
<label><%= l(:rabbitmq_label_username) %></label>
<%= text_field_tag "settings[username]", @settings["username"] %>
</p>
<p>
<label><%= l(:rabbitmq_label_password) %></label>
<%= password_field_tag "settings[password]", @settings["password"] %>
</p>
<p>
<label><%= l(:rabbitmq_label_exchange) %></label>
<%= text_field_tag "settings[exchange]", @settings["exchange"] %>
</p>
<p>
<label><%= l(:rabbitmq_label_server) %></label>
<%= text_field_tag "settings[server]", @settings["server"] %>
</p>
<p>
<label><%= l(:rabbitmq_label_port) %></label>
<%= number_field_tag "settings[port]", @settings["port"] %>
</p>
</fieldset>

1
assets
View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/assets/

1
config
View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/config

8
config/locales/en.yml Normal file
View File

@ -0,0 +1,8 @@
# English strings go here for Rails i18n
en:
rabbitmq_label_settings: RabbitMQ Notifications settings
rabbitmq_label_username: RabbitMQ username
rabbitmq_label_password: Password
rabbitmq_label_exchange: Exchange
rabbitmq_label_server: Server
rabbitmq_label_port: Port

8
config/locales/ru.yml Normal file
View File

@ -0,0 +1,8 @@
# Russian strings go here for Rails i18n
en:
rabbitmq_label_settings: RabbitMQ Настройки
rabbitmq_label_username: RabbitMQ имя пользователя
rabbitmq_label_password: Пароль
rabbitmq_label_exchange: Канал обмена
rabbitmq_label_server: Сервер
rabbitmq_label_port: Порт

2
config/routes.rb Normal file
View File

@ -0,0 +1,2 @@
# Plugin's routes
# See: http://guides.rubyonrails.org/routing.html

1
db
View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/db/

View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/init.rb

18
init.rb Normal file
View File

@ -0,0 +1,18 @@
require 'bunny'
require_dependency "notifier_hook"
Redmine::Plugin.register :rabbitmq do
name 'Rabbitmq plugin'
author 'Василий Казьмин'
description 'This is a plugin for Redmine'
version '0.0.1'
url 'http://example.com/path/to/plugin'
author_url 'http://example.com/about'
settings :default => {
"username" => "guest",
"password" => "guest",
"exchange" => "redmine",
"server" => "rabbitmq",
"port" => 5672
}, :partial => "settings/rabbitmq_settings"
end

1
lib
View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/lib/

68
lib/notifier_hook.rb Normal file
View File

@ -0,0 +1,68 @@
class NotifierHook < Redmine::Hook::Listener
def controller_issues_new_after_save(context = {})
deliver(make_msg(context[:issue]), make_key("issue", context[:issue].project.id, "new")) unless !validate_settings?
end
def controller_issues_edit_after_save(context = {})
deliver(make_msg(context[:issue]), make_key("issue", context[:issue].project.id, "update")) unless !validate_settings?
if context[:time_entry]
deliver(make_msg(context[:time_entry]), make_key("time_entry", context[:time_entry].issue.project.id, "update")) unless !validate_settings?
end
end
def controller_timelog_edit_before_save(context = {})
deliver(make_msg(context[:time_entry]), make_key("time_entry", context[:time_entry].issue.project.id, "update")) unless !validate_settings?
end
private
def logger
config.logger
end
def notify_error(e)
logger.error "RabbitMQ Hook error => exception #{e.class.name} : #{e.message}"
flash[:error] = "Exception caught while delivering notification to RabbitMQ channel"
end
def settings
@settings ||= Setting.plugin_rabbitmq
end
def validate_settings?
settings["username"].present? && settings["password"].present? && settings["exchange"].present? && settings["server"].present? && settings["port"].present?
end
def make_msg(issue)
message = issue.to_json
return message
end
def make_key(object, project, event)
message = "redmine.#{project}.#{object}.#{event}"
return message
end
def make_exchange()
connection = Bunny.new(:host => settings["server"],
:port => settings["port"],
:user => settings["username"],
:pass => settings["password"])
connection.start
channel = connection.create_channel
exchange = channel.fanout(settings["exchange"])
yield exchange
ensure
connection.close
end
def deliver(message, key)
make_exchange do |exchange|
exchange.publish(
message,
:routing_key => key,
:content_type => "application/json",
)
end
end
end

1
test
View File

@ -1 +0,0 @@
storage/docker_redmine-plugins/rabbitmq/test/

2
test/test_helper.rb Normal file
View File

@ -0,0 +1,2 @@
# Load the Redmine helper
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')