bluepill-gearman 1.0.0
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.
- data/.gitignore +19 -0
- data/.rbenv-version +1 -0
- data/Changelog.md +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +56 -0
- data/Rakefile +14 -0
- data/bluepill-gearman.gemspec +23 -0
- data/lib/bluepill-gearman/version.rb +5 -0
- data/lib/bluepill-gearman.rb +108 -0
- data/spec/bluepill-gearman_spec.rb +40 -0
- metadata +154 -0
data/.gitignore
ADDED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p392
|
data/Changelog.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ami Mahloof
|
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,56 @@
|
|
1
|
+
# Bluepill::Gearman
|
2
|
+
|
3
|
+
Send bluepill events(passive checks) to gearman server via send gearman
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bluepill-gearman',
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bluepill-gearman
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Require the bluepill-gearman gem and add a check named :send_gearman in your pill configuration file.
|
22
|
+
|
23
|
+
Available options are:
|
24
|
+
* gearman_server: the Gearman Server. mandatory
|
25
|
+
* gearman_port: the gearman server port or default to 4730
|
26
|
+
* host: the host defined in nagios to be hosting the service (default: hostname -f)
|
27
|
+
* service: the service declared in nagios (default: the bluepill process name)
|
28
|
+
* queue: default queue is 'check_results'
|
29
|
+
* key: provide a key for encryption (minimum 8 bytes)
|
30
|
+
* encryption: default to false, set to true to enable - must provide a key
|
31
|
+
* every: how often the send_gearman will send the passive check (default to 1.minute)
|
32
|
+
|
33
|
+
add :notify_on => :unmonitored to make bluepill send notification when unmonitored
|
34
|
+
|
35
|
+
Example:
|
36
|
+
|
37
|
+
```
|
38
|
+
require 'bluepill-gearman'
|
39
|
+
Bluepill.application("test") do |app|
|
40
|
+
app.process("test") do |process|
|
41
|
+
process.start_command = "bundle exec ./test.rb"
|
42
|
+
process.pid_file = "/var/run/test.pid"
|
43
|
+
process.daemonize = true
|
44
|
+
process.checks :send_gearman, :gearman_server => 'my.gearman.server', :host => 'host_in_nagios', :service => 'passive check service name', :notify_on => :unmonitored, :every => 1.minute
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rake/testtask"
|
4
|
+
require "yard"
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs.push "lib"
|
8
|
+
t.test_files = FileList['spec/*_spec.rb']
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
YARD::Rake::YardocTask.new do |t|
|
13
|
+
t.files = ['lib/**/*.rb']
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bluepill-gearman/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ami Mahloof"]
|
6
|
+
gem.email = ["ami.mahloof@gmail.com"]
|
7
|
+
gem.description = %q{send events to gearman when a bluepill process state changes}
|
8
|
+
gem.summary = %q{send events to gearman via the send_gearman when a bluepill monitored process triggers a state change}
|
9
|
+
gem.homepage = "http://github.com/innovia/bluepill-gearman"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.name = "bluepill-gearman"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.add_dependency "bluepill"
|
16
|
+
gem.add_dependency "gearman-ruby"
|
17
|
+
#gem.add_dependency "crypt"
|
18
|
+
gem.add_development_dependency "minitest"
|
19
|
+
gem.add_development_dependency "mocha"
|
20
|
+
gem.add_development_dependency "yard"
|
21
|
+
gem.add_development_dependency "redcarpet"
|
22
|
+
gem.version = Bluepill::Gearman::VERSION
|
23
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "bluepill-gearman/version"
|
2
|
+
require 'gearman'
|
3
|
+
require "bluepill"
|
4
|
+
require 'base64'
|
5
|
+
require "openssl"
|
6
|
+
require "digest"
|
7
|
+
|
8
|
+
module Bluepill
|
9
|
+
module Gearman
|
10
|
+
class SendGearman < Bluepill::Trigger
|
11
|
+
<<-INFO
|
12
|
+
Called by bluepill when a "checks :send_gearman" is declared in pill file
|
13
|
+
@param [Bluepill::Process] process object from Bluepill see http://rdoc.info/github/arya/bluepill/master/Bluepill/Process
|
14
|
+
@param [Hash] options available options:
|
15
|
+
* gearman_server: the Gearman Server. mandatory
|
16
|
+
* gearman_port: the gearman server port or default to 4730
|
17
|
+
* host: the host defined in nagios to be hosting the service (default: hostname -f)
|
18
|
+
* service: the service declared in nagios (default: the bluepill process name)
|
19
|
+
* queue: default queue is 'check_results'
|
20
|
+
* key: provide a key for encryption (minimum 8 bytes)
|
21
|
+
* encryption: default to false set to true to enable
|
22
|
+
* every: how often the send_gearman will send the passive check
|
23
|
+
|
24
|
+
See checks https://github.com/arya/bluepill for the syntax to pass those options
|
25
|
+
encryption: https://gist.github.com/RiANOl/1077760
|
26
|
+
INFO
|
27
|
+
|
28
|
+
def initialize(process, options={})
|
29
|
+
@default_args = {
|
30
|
+
:gearman_job_server => ["#{options.delete(:gearman_server)}:#{options.delete(:gearman_port) || 4730}"],
|
31
|
+
:host => options.delete(:host) || `hostname -f`.chomp,
|
32
|
+
:service => options.delete(:service) || process.name,
|
33
|
+
:queue => options.delete(:queue) || 'check_results',
|
34
|
+
:key => options.delete(:key) || '',
|
35
|
+
:encryption => options.delete(:encryption) || false,
|
36
|
+
:every => options.delete(:every) || 1.minute
|
37
|
+
}
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
# Called by bluepill when process states changes. Notifies the nagios when:
|
42
|
+
# * the process goes to :unmonitored notifies warning
|
43
|
+
# * the process goes to :down notifies critical
|
44
|
+
# * the process goes to :up notifies ok
|
45
|
+
def notify(transition)
|
46
|
+
_return_code, _status = case transition.to_name
|
47
|
+
when :down
|
48
|
+
[2, "Bluepill reported process down at #{Time.now}"]
|
49
|
+
when :unmonitored
|
50
|
+
[1 , "Bluepill stopped monitoring at #{Time.now}"]
|
51
|
+
when :up
|
52
|
+
[0 , "Running"]
|
53
|
+
else
|
54
|
+
[nil, nil]
|
55
|
+
end
|
56
|
+
if _status and _return_code
|
57
|
+
_args = @default_args.merge({:status => _status, :return_code => _return_code})
|
58
|
+
send_gearman(_args)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
def aes256_encrypt(key, data)
|
64
|
+
key = null_padding(key)
|
65
|
+
aes = OpenSSL::Cipher.new('AES-256-ECB')
|
66
|
+
aes.encrypt
|
67
|
+
aes.key = key
|
68
|
+
aes.update(data) + aes.final
|
69
|
+
end
|
70
|
+
|
71
|
+
def null_padding(key)
|
72
|
+
padding = (32 - key.bytesize) if(key.kind_of?(String) && 32 != key.bytesize)
|
73
|
+
key += "\0" * padding
|
74
|
+
end
|
75
|
+
|
76
|
+
def send_gearman(args)
|
77
|
+
begin
|
78
|
+
client = ::Gearman::Client.new(args[:gearman_job_server])
|
79
|
+
job = <<-EOT
|
80
|
+
type=passive
|
81
|
+
host_name=#{args[:host]}
|
82
|
+
service_description=#{args[:service]}
|
83
|
+
start_time=#{Time.now.to_i}.0
|
84
|
+
finish_time=#{Time.now.to_i}.0
|
85
|
+
latency=0.0
|
86
|
+
return_code=#{args[:return_code]}
|
87
|
+
output=#{args[:status]}
|
88
|
+
EOT
|
89
|
+
if args[:encryption]
|
90
|
+
begin
|
91
|
+
job = aes256_encrypt(args[:key], job)
|
92
|
+
rescue Exception => e
|
93
|
+
logger.warn "unable to encrypt: #{e}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
encoded_job = Base64.encode64(job)
|
97
|
+
result = client.do_task(args[:queue], encoded_job)
|
98
|
+
|
99
|
+
logger.info "Sent Job to Gearman Server #{result}"
|
100
|
+
logger.info "Next job status passive check: #{args[:every]}"
|
101
|
+
sleep(args[:every])
|
102
|
+
rescue Exception => e
|
103
|
+
logger.warn "Failed to send job to the Gearman Server: #{e}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocha/test_unit'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'mocha'
|
6
|
+
require './lib/bluepill-gearman'
|
7
|
+
|
8
|
+
describe Bluepill::Gearman::SendGearman do
|
9
|
+
let(:process) { Minitest::Mock.new }
|
10
|
+
let(:notifier) {Bluepill::Gearman::SendGearman.new(process, {:gearman_server => 'remotehost', :host => 'localhost'})}
|
11
|
+
|
12
|
+
it "should create a default_args instance variable to store default connection parameters" do
|
13
|
+
process.expect(:name, 'my_process')
|
14
|
+
notifier.instance_variable_get(:@default_args).must_equal({:gearman_job_server => ['remotehost:4730'], :host => 'localhost', :service => 'my_process', :queue => 'check_results', :encryption => false, :key => '', :every => 1.minute})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should notify gearman_server of a critical error via send_gearman when a transition to down occurs" do
|
18
|
+
process.expect(:name, 'my_process')
|
19
|
+
transition = Minitest::Mock.new
|
20
|
+
transition.expect(:to_name,:down)
|
21
|
+
notifier.expects(:send_gearman).with({:gearman_server => ['remotehost:4730'], :host => 'localhost', :service => 'my_process', :return_code => 2, :status => "Bluepill reported process down at #{Time.now}"})
|
22
|
+
notifier.notify(transition)
|
23
|
+
end
|
24
|
+
|
25
|
+
# it "should notify gearman_server of a warning error via send_gearman when a transition to unmonitored occurs" do
|
26
|
+
# process.expect(:name, 'my_process')
|
27
|
+
# transition = Minitest::Mock.new
|
28
|
+
# transition.expect(:to_name,:unmonitored)
|
29
|
+
# notifier.expects(:send_gearman).with({:gearman_server => ['remotehost:4730'], :host => 'localhost', :service => 'my_process', :return_code => 1, :status => "Bluepill stopped monitoring at #{Time.now}"})
|
30
|
+
# notifier.notify(transition)
|
31
|
+
# end
|
32
|
+
|
33
|
+
# it "should notify gearman_server that everything is ok via send_gearman when a transition to up occurs" do
|
34
|
+
# process.expect(:name, 'my_process')
|
35
|
+
# transition = Minitest::Mock.new
|
36
|
+
# transition.expect(:to_name,:up)
|
37
|
+
# notifier.expects(:send_gearman).with({:gearman_server => ['remotehost:4730'], :host => 'localhost', :service => 'my_process', :return_code => 0, :status => "Running"})
|
38
|
+
# notifier.notify(transition)
|
39
|
+
# end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bluepill-gearman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ami Mahloof
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bluepill
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: gearman-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: minitest
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mocha
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: yard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: redcarpet
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: send events to gearman when a bluepill process state changes
|
111
|
+
email:
|
112
|
+
- ami.mahloof@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .rbenv-version
|
119
|
+
- Changelog.md
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bluepill-gearman.gemspec
|
125
|
+
- lib/bluepill-gearman.rb
|
126
|
+
- lib/bluepill-gearman/version.rb
|
127
|
+
- spec/bluepill-gearman_spec.rb
|
128
|
+
homepage: http://github.com/innovia/bluepill-gearman
|
129
|
+
licenses: []
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.8.25
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: send events to gearman via the send_gearman when a bluepill monitored process
|
152
|
+
triggers a state change
|
153
|
+
test_files: []
|
154
|
+
has_rdoc:
|