acheron 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +104 -0
- data/Rakefile +1 -0
- data/acheron.gemspec +28 -0
- data/bin/acheron +102 -0
- data/lib/acheron.rb +5 -0
- data/lib/acheron/exec.rb +77 -0
- data/lib/acheron/version.rb +3 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2adad651fde061e01d6285a8c56017ed97bbd11c
|
4
|
+
data.tar.gz: 1d19e21ae4a8ccf8dfc91625a931e56213616ae2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80613627d218fc5a452ce465032aada02233836ba77825611ad0ce18fe86972f065fbd2c04ccec47d92d7d78ca95cf5add1e2b553b03937a7dea0283a9dd7021
|
7
|
+
data.tar.gz: 5172fdde61976127d6e3f5166e71c02e626282d9bc9b9d84b1947cfeb5ff9f18fa760b56a41e2d6db254d47dfd6802675c6b9accd2a0a9bed06235dfea04463e
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Phil Hofmann <phil@branch14.org>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
_
|
2
|
+
__ _ ___| |__ ___ _ __ ___ _ __
|
3
|
+
/ _` |/ __| '_ \ / _ \ '__/ _ \| '_ \
|
4
|
+
| (_| | (__| | | | __/ | | (_) | | | |
|
5
|
+
\__,_|\___|_| |_|\___|_| \___/|_| |_|
|
6
|
+
|
7
|
+
# Welcome to acheron
|
8
|
+
|
9
|
+
Acheron listens to an exchange[1] on RabbitMQ[2] and forwards messages
|
10
|
+
to a channel on Slack[3].
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'acheron'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install acheron
|
26
|
+
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Run
|
31
|
+
|
32
|
+
acheron
|
33
|
+
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
Acheron reads configuration options from multiple locations. The
|
38
|
+
following sections list all of those locations, later superseeds the
|
39
|
+
prior ones.
|
40
|
+
|
41
|
+
|
42
|
+
### Defaults
|
43
|
+
|
44
|
+
Acheron comes with reasonable defaults
|
45
|
+
|
46
|
+
slack:
|
47
|
+
channel: '#acheron'
|
48
|
+
username: Acheron
|
49
|
+
icon_emoji: ':squirrel:'
|
50
|
+
rabbitmq:
|
51
|
+
exchange: acheron
|
52
|
+
|
53
|
+
|
54
|
+
### Config file
|
55
|
+
|
56
|
+
The defaults above are given in YAML, which is also the format of the
|
57
|
+
config file. By default Acheron The Salcker attempts to read a config
|
58
|
+
file named `acheron.yml` from the current working
|
59
|
+
directory. You can provide an alternate location either via
|
60
|
+
environment variable or with a command line argument.
|
61
|
+
|
62
|
+
|
63
|
+
### Environment
|
64
|
+
|
65
|
+
All environment variables are prefixed with `ACHERON` and the nesting is
|
66
|
+
reflected by an underscore separated list of names. E.g.
|
67
|
+
|
68
|
+
export ACHERON_SLACK_CHANNEL='#set_by_env'
|
69
|
+
|
70
|
+
|
71
|
+
### Command line arguments
|
72
|
+
|
73
|
+
Run the following command to get a list of all arguments:
|
74
|
+
|
75
|
+
acheron --help
|
76
|
+
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
1. Fork it
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
82
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
5. Create new Pull Request
|
85
|
+
|
86
|
+
|
87
|
+
## Trivia
|
88
|
+
|
89
|
+
In ancient Greek mythology, Acheron was known as the "river of woe",
|
90
|
+
and was one of the five rivers of the Greek underworld. In the Homeric
|
91
|
+
poems the Acheron was described as a river of Hades, into which
|
92
|
+
Cocytus and [Phlegethon](http://github.com/branch14/phlegethon) both
|
93
|
+
flowed.
|
94
|
+
|
95
|
+
The Roman poet Virgil called it the principal river of Tartarus, from
|
96
|
+
which the Styx and Cocytus both sprang. The newly dead would be
|
97
|
+
ferried across the Acheron by Charon in order to enter the Underworld.
|
98
|
+
|
99
|
+
|
100
|
+
## References
|
101
|
+
|
102
|
+
[1] https://www.rabbitmq.com/tutorials/tutorial-three-python.html
|
103
|
+
[2] https://www.rabbitmq.com/
|
104
|
+
[3] http://slack.com/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/acheron.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acheron/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acheron"
|
8
|
+
spec.version = Acheron::VERSION
|
9
|
+
spec.authors = ["phil"]
|
10
|
+
spec.email = ["phil@branch14.org"]
|
11
|
+
spec.description = %q{Listens to RabbitMQ and spams Slack.}
|
12
|
+
spec.summary = %q{Listens to RabbitMQ and spams Slack.}
|
13
|
+
spec.homepage = "http://github.com/branch14/acheron"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "trickery", "~> 0.0.4"
|
22
|
+
spec.add_dependency "daemons"
|
23
|
+
spec.add_dependency "bunny"
|
24
|
+
spec.add_dependency "faraday"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
data/bin/acheron
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#/
|
3
|
+
#/ Usage: acheron <cmd> [options]
|
4
|
+
#/
|
5
|
+
#/ Options:
|
6
|
+
#/
|
7
|
+
#/ -x, --exchange <rabbitmq-exchange> (default: 'acheron')
|
8
|
+
#/
|
9
|
+
#/ -c, --channel <slack-channel> (default: '#acheron')
|
10
|
+
#/
|
11
|
+
#/ -t, --token <slack-token> (no default)
|
12
|
+
#/
|
13
|
+
#/ -u, --username <slack-username (default: 'Acheron'>
|
14
|
+
#/
|
15
|
+
#/ -i, --icon_emoji <slack-icon-emoji> (default: ':space_invader:')
|
16
|
+
#/
|
17
|
+
#/ -f, --configfile <config-file> (default: './acheron.yml')
|
18
|
+
#/
|
19
|
+
#/ -p, --piddir <pid-directory> (default: '/var/run')
|
20
|
+
#/
|
21
|
+
#/
|
22
|
+
#/ Configuration:
|
23
|
+
#/
|
24
|
+
#/ Defaults <- Config file <- ENV <- CLI
|
25
|
+
#/
|
26
|
+
|
27
|
+
$stderr.sync = true
|
28
|
+
|
29
|
+
require 'optparse'
|
30
|
+
require 'yaml'
|
31
|
+
|
32
|
+
require 'trickery/hash/deep_merge'
|
33
|
+
require 'trickery/hash/deep_ostruct'
|
34
|
+
|
35
|
+
require 'daemons'
|
36
|
+
|
37
|
+
require File.expand_path(File.join(%w(.. .. lib acheron)), __FILE__)
|
38
|
+
|
39
|
+
# default options
|
40
|
+
default_opts = {
|
41
|
+
configfile: File.expand_path('acheron.yml', Dir.pwd),
|
42
|
+
piddir: '/var/run',
|
43
|
+
slack: {
|
44
|
+
channel: '#acheron',
|
45
|
+
username: 'Acheron',
|
46
|
+
icon_emoji: ':space_invader:'
|
47
|
+
},
|
48
|
+
rabbitmq: {
|
49
|
+
exchange: 'acheron'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
# parse options from cli
|
54
|
+
cli_opts = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
|
55
|
+
ARGV.options do |o|
|
56
|
+
o.on("-f", "--configfile=val", String) { |val| cli_opts[:configfile] = val }
|
57
|
+
o.on("-p", "--piddir=val", String) { |val| cli_opts[:piddir] = val }
|
58
|
+
o.on("-c", "--channel=val", String) { |val| cli_opts[:slack][:channel] = val }
|
59
|
+
o.on("-u", "--username=val", String) { |val| cli_opts[:slack][:username] = val }
|
60
|
+
o.on("-i", "--icon_emoji=val", String) { |val| cli_opts[:slack][:icon_emoji] = val }
|
61
|
+
o.on("-t", "--token=val", String) { |val| cli_opts[:slack][:token] = val }
|
62
|
+
o.on("-x", "--exchange=val", String) { |val| cli_opts[:rabbitmq][:exchange] = val }
|
63
|
+
|
64
|
+
o.on_tail("-h", "--help") { exec "grep ^#/<'#{__FILE__}'|cut -c4-" }
|
65
|
+
o.parse!
|
66
|
+
end
|
67
|
+
|
68
|
+
# load options from env
|
69
|
+
env_opts = {
|
70
|
+
configfile: ENV['ACHERON_CONFIGFILE'],
|
71
|
+
piddir: ENV['ACHERON_PIDDIR'],
|
72
|
+
slack: {
|
73
|
+
channel: ENV['ACHERON_SLACK_CHANNEL'],
|
74
|
+
username: ENV['ACHERON_SLACK_USERNAME'],
|
75
|
+
icon_emoji: ENV['ACHERON_SLACK_ICON_EMOJI'],
|
76
|
+
token: ENV['ACHERON_SLACK_TOKEN']
|
77
|
+
},
|
78
|
+
rabbitmq: {
|
79
|
+
exchange: ENV['ACHERON_RABBITMQ_EXCHANGE']
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
# merge config i
|
84
|
+
config = default_opts.deep_merge(env_opts, cli_opts)
|
85
|
+
|
86
|
+
# load options from file
|
87
|
+
file_opts = {}
|
88
|
+
if File.exist?(config[:configfile])
|
89
|
+
file_opts = YAML.load(File.read(config[:configfile]))
|
90
|
+
else
|
91
|
+
warn "Unable to read config file at #{config[:configfile]}"
|
92
|
+
end
|
93
|
+
|
94
|
+
# merge config ii
|
95
|
+
config = default_opts.deep_merge(file_opts, env_opts, cli_opts)
|
96
|
+
|
97
|
+
# daemonize
|
98
|
+
Daemons.run_proc(File.basename(__FILE__), dir: config[:piddir]) do
|
99
|
+
sts = Acheron::Exec.new(config.deep_ostruct)
|
100
|
+
puts 'Acheron is ready to slack.'
|
101
|
+
sts.run
|
102
|
+
end
|
data/lib/acheron.rb
ADDED
data/lib/acheron/exec.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require 'daemons'
|
5
|
+
require 'bunny'
|
6
|
+
require 'faraday'
|
7
|
+
|
8
|
+
module Acheron
|
9
|
+
|
10
|
+
class Exec < Struct.new(:config)
|
11
|
+
|
12
|
+
def run
|
13
|
+
check
|
14
|
+
reconnect
|
15
|
+
x_name = config.rabbitmq.exchange
|
16
|
+
exchange = @channel.fanout(x_name)
|
17
|
+
queue = @channel.queue('', exclusive: true)
|
18
|
+
queue.bind(exchange)
|
19
|
+
|
20
|
+
queue.subscribe(block: true) do |info, prop, body|
|
21
|
+
slack JSON.parse(body)['msg']
|
22
|
+
end
|
23
|
+
rescue Bunny::ConnectionClosedError => e
|
24
|
+
# if the connection is closed make it reconnect and try again
|
25
|
+
reconnect
|
26
|
+
retry
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def reconnect
|
32
|
+
bunny = Bunny.new read_timeout: 10, heartbeat: 10
|
33
|
+
bunny.start
|
34
|
+
@channel = bunny.create_channel
|
35
|
+
end
|
36
|
+
|
37
|
+
def slack(message, opts={})
|
38
|
+
unless config.slack.channel
|
39
|
+
puts message
|
40
|
+
return
|
41
|
+
end
|
42
|
+
opts[:text] = message
|
43
|
+
payload = defaults.merge(opts)
|
44
|
+
faraday.post slack_url, payload: JSON.unparse(payload)
|
45
|
+
end
|
46
|
+
|
47
|
+
def defaults
|
48
|
+
{
|
49
|
+
channel: config.slack.channel,
|
50
|
+
username: config.slack.username,
|
51
|
+
icon_emoji: config.slack.icon_emoji
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def faraday
|
56
|
+
@faraday ||= Faraday.new(url: slack_url) do |f|
|
57
|
+
f.request :url_encoded
|
58
|
+
f.adapter Faraday.default_adapter
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def slack_url
|
63
|
+
@slack_url ||=
|
64
|
+
"https://voicerepublic.slack.com" +
|
65
|
+
"/services/hooks/incoming-webhook" +
|
66
|
+
"?token=" + config.slack.token
|
67
|
+
end
|
68
|
+
|
69
|
+
def check
|
70
|
+
if config.slack.token.nil?
|
71
|
+
warn 'Slack token is missing.'
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acheron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- phil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: trickery
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: daemons
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bunny
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Listens to RabbitMQ and spams Slack.
|
98
|
+
email:
|
99
|
+
- phil@branch14.org
|
100
|
+
executables:
|
101
|
+
- acheron
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".ruby-version"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- acheron.gemspec
|
112
|
+
- bin/acheron
|
113
|
+
- lib/acheron.rb
|
114
|
+
- lib/acheron/exec.rb
|
115
|
+
- lib/acheron/version.rb
|
116
|
+
homepage: http://github.com/branch14/acheron
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.2.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Listens to RabbitMQ and spams Slack.
|
140
|
+
test_files: []
|