bluepill-nagios 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.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bundle
19
+ *.swp
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ ree-1.8.7-2011.03
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bluepill-nagios.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Vincent Hellot
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,51 @@
1
+ # Bluepill::Nagios
2
+
3
+ Send bluepill events to nagios via nsca
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bluepill-nagios'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bluepill-nagios
18
+
19
+ ## Usage
20
+
21
+ Require the bluepill-nagios gem and add a check named :nsca in your pill configuration file.
22
+
23
+ Available options are:
24
+ * nscahost: the host where you want to send your events
25
+ * port: the port where nsca daemon is listening (default: 5667)
26
+ * hostname: the host defined in your nagios configuration (default: hostname -f)
27
+ * service: the service name defined in the nagios configuration (default: bluepill configuration process name)
28
+
29
+ Example:
30
+
31
+ ```
32
+ require 'bluepill-nagios'
33
+ Bluepill.application("test") do |app|
34
+ app.process("test") do |process|
35
+ process.start_command = "bundle exec ./test.rb"
36
+ process.pid_file = "/var/run/test.pid"
37
+ process.daemonize = true
38
+ process.checks :nsca, :nscahost => 'my.nagios.host'
39
+ end
40
+ end
41
+ ```
42
+
43
+ Don't forget to set up the nsca daemon on the remote host.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 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,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bluepill-nagios/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Vincent Hellot"]
6
+ gem.email = ["hellvinz@gmail.com"]
7
+ gem.description = %q{send events to nagios when a bluepill process state changes}
8
+ gem.summary = %q{send events to nagios via the ncsa plugin when a bluepill monitored process triggers a state change}
9
+ gem.homepage = "http://github.com/hellvinz/bluepill-nagios"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bluepill-nagios"
15
+ gem.require_paths = ["lib"]
16
+ gem.add_dependency "bluepill"
17
+ gem.add_dependency "send_nsca"
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.test_files = Dir.glob('spec/*_spec.rb')
23
+ gem.version = Bluepill::Nagios::VERSION
24
+ end
@@ -0,0 +1,5 @@
1
+ module Bluepill
2
+ module Nagios
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require "bluepill-nagios/version"
2
+ require "send_nsca"
3
+ require "bluepill"
4
+
5
+ module Bluepill
6
+ module Nagios
7
+ class Nsca < Bluepill::Trigger
8
+ # Called by bluepill when a "checks :nsca" is declared in pill file
9
+ # @param [Bluepill::Process] process object from Bluepill see http://rdoc.info/github/arya/bluepill/master/Bluepill/Process
10
+ # @param [Hash] options available options:
11
+ # * nscahost: the host hosting the nsca daemon. mandatory
12
+ # * hostname: the host defined in nagios to be hosting the service (default: hostname -f)
13
+ # * service: the service declared in nagios (default: the bluepill process name)
14
+ # See checks https://github.com/arya/bluepill for the syntax to pass those options
15
+ def initialize(process, options={})
16
+ @default_args = {
17
+ :nscahost => options.delete(:nscahost),
18
+ :port => options.delete(:port) || 5667,
19
+ :hostname => options.delete(:host) || `hostname -f`.chomp,
20
+ :service => options.delete(:service) || process.name
21
+ }
22
+ super
23
+ end
24
+
25
+ # Called by bluepill when process states changes. Notifies the nagios when:
26
+ # * the process goes to :unmonitored notifies warning
27
+ # * the process goes to :down notifies critical
28
+ # * the process goes to :up notifies ok
29
+ def notify(transition)
30
+ _return_code, _status = case transition.to_name
31
+ when :down
32
+ [2, "Bluepill reported process down at #{Time.now}"]
33
+ when :unmonitored
34
+ [1 , "Bluepill stopped monitoring at #{Time.now}"]
35
+ when :up
36
+ [0 , "Running"]
37
+ else
38
+ [nil, nil]
39
+ end
40
+ if _status and _return_code
41
+ _args = @default_args.merge({:status => _status, :return_code => _return_code})
42
+ send_nsca(_args)
43
+ end
44
+ end
45
+
46
+ protected
47
+ def send_nsca(args)
48
+ begin
49
+ nsca_connection = SendNsca::NscaConnection.new(args)
50
+ nsca_connection.send_nsca
51
+ logger.debug("nsca server notified") if logger
52
+ rescue => e
53
+ logger.warning("failed to reach the nsca server: #{e}") if logger
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,38 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'mocha'
4
+ require './lib/bluepill-nagios'
5
+
6
+ describe Bluepill::Nagios::Nsca do
7
+ let(:process) { Minitest::Mock.new }
8
+ let(:notifier) {Bluepill::Nagios::Nsca.new(process, {:nscahost => 'remotehost', :host => 'localhost'})}
9
+
10
+ it "should create a default_args instance variable to store default connection parameters" do
11
+ process.expect(:name, 'my_process')
12
+ notifier.instance_variable_get(:@default_args).must_equal({:nscahost => 'remotehost', :port => 5667, :hostname => 'localhost', :service => 'my_process'})
13
+ end
14
+
15
+ it "should notify nagios of a critical error via send_nsca when a transition to down occurs" do
16
+ process.expect(:name, 'my_process')
17
+ transition = Minitest::Mock.new
18
+ transition.expect(:to_name,:down)
19
+ notifier.expects(:send_nsca).with({:nscahost => 'remotehost', :port => 5667, :hostname => 'localhost', :service => 'my_process', :return_code => 2, :status => "Bluepill reported process down at #{Time.now}"})
20
+ notifier.notify(transition)
21
+ end
22
+
23
+ it "should notify nagios of a warning error via send_nsca when a transition to unmonitored occurs" do
24
+ process.expect(:name, 'my_process')
25
+ transition = Minitest::Mock.new
26
+ transition.expect(:to_name,:unmonitored)
27
+ notifier.expects(:send_nsca).with({:nscahost => 'remotehost', :port => 5667, :hostname => 'localhost', :service => 'my_process', :return_code => 1, :status => "Bluepill stopped monitoring at #{Time.now}"})
28
+ notifier.notify(transition)
29
+ end
30
+
31
+ it "should notify nagios that everything is ok via send_nsca when a transition to up occurs" do
32
+ process.expect(:name, 'my_process')
33
+ transition = Minitest::Mock.new
34
+ transition.expect(:to_name,:up)
35
+ notifier.expects(:send_nsca).with({:nscahost => 'remotehost', :port => 5667, :hostname => 'localhost', :service => 'my_process', :return_code => 0, :status => "Running"})
36
+ notifier.notify(transition)
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bluepill-nagios
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Vincent Hellot
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-07-18 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bluepill
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: send_nsca
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirement: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: yard
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirement: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: redcarpet
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirement: *id006
105
+ description: send events to nagios when a bluepill process state changes
106
+ email:
107
+ - hellvinz@gmail.com
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files: []
113
+
114
+ files:
115
+ - .gitignore
116
+ - .rbenv-version
117
+ - Gemfile
118
+ - LICENSE
119
+ - README.md
120
+ - Rakefile
121
+ - bluepill-nagios.gemspec
122
+ - lib/bluepill-nagios.rb
123
+ - lib/bluepill-nagios/version.rb
124
+ - spec/bluepill-nagios_spec.rb
125
+ has_rdoc: true
126
+ homepage: http://github.com/hellvinz/bluepill-nagios
127
+ licenses: []
128
+
129
+ post_install_message:
130
+ rdoc_options: []
131
+
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
+ hash: 3
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ requirements: []
153
+
154
+ rubyforge_project:
155
+ rubygems_version: 1.6.2
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: send events to nagios via the ncsa plugin when a bluepill monitored process triggers a state change
159
+ test_files:
160
+ - spec/bluepill-nagios_spec.rb