nagios_helper 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +72 -0
- data/Rakefile +8 -0
- data/bin/nagios_check +35 -0
- data/lib/generators/nagios/check_em_generator.rb +15 -0
- data/lib/generators/nagios/check_generator.rb +15 -0
- data/lib/generators/nagios/nagios_em_generator.rb +14 -0
- data/lib/generators/nagios/nagios_generator.rb +14 -0
- data/lib/generators/nagios/templates/script_class.rb +11 -0
- data/lib/generators/nagios/templates/script_class_em.rb +17 -0
- data/lib/generators/nagios/templates/spec.rb +10 -0
- data/lib/nagios_helper/boot.rb +5 -0
- data/lib/nagios_helper/check.rb +100 -0
- data/lib/nagios_helper/check_em.rb +41 -0
- data/lib/nagios_helper/runner.rb +78 -0
- data/lib/nagios_helper/runner_async.rb +43 -0
- data/lib/nagios_helper/spec_helper.rb +9 -0
- data/lib/nagios_helper.rb +61 -0
- data/nagios_helper.gemspec +27 -0
- data/spec/nagios_spec.rb +106 -0
- data/spec/nagios_support.rb +30 -0
- data/spec/spec_helper.rb +13 -0
- metadata +145 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Makarchev K
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
NagiosHelper
|
2
|
+
============
|
3
|
+
|
4
|
+
Rails gem for writing, testing, executing Nagios checks inside Rails application.
|
5
|
+
Checks running throught http or binary(nrpe).
|
6
|
+
|
7
|
+
```
|
8
|
+
gem 'nagios_helper'
|
9
|
+
```
|
10
|
+
|
11
|
+
$ rails generate nagios:check some
|
12
|
+
|
13
|
+
Check example:
|
14
|
+
--------------
|
15
|
+
|
16
|
+
app/nagios/some.rb
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class Nagios::Some < Nagios::Check
|
20
|
+
params :x
|
21
|
+
|
22
|
+
def execute
|
23
|
+
count = User.count + x.to_i
|
24
|
+
|
25
|
+
warn "hmmm" if count < 10
|
26
|
+
crit "ouch" if count < 5
|
27
|
+
|
28
|
+
ok "good #{count}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Run:
|
35
|
+
|
36
|
+
$ RAILS_ENV=production bundle exec nagios_check some x 1
|
37
|
+
|
38
|
+
### Nagios Check Initilizers:
|
39
|
+
All files in app/nagios/initializers will auto loads.
|
40
|
+
|
41
|
+
Server:
|
42
|
+
-------
|
43
|
+
|
44
|
+
### Inside rails server
|
45
|
+
|
46
|
+
Create controller: app/controllers/nagios_controller.rb
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class NagiosController < ApplicationController
|
50
|
+
|
51
|
+
def check
|
52
|
+
status, message = Nagios::Runner.check(params)
|
53
|
+
|
54
|
+
respond_to do |f|
|
55
|
+
f.html{ status + "," + message }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
$ curl localhost:3000/nagios/check?method=some&x=1
|
63
|
+
|
64
|
+
### Outside rails server
|
65
|
+
|
66
|
+
With using nonblocking EM-server [nagios_rails_server](http://github.com/kostya/nagios_rails_server)
|
67
|
+
|
68
|
+
AR connections should be configured with pool: 100.
|
69
|
+
|
70
|
+
$ RAILS_ENV=production bundle exec nagios_server
|
71
|
+
$ curl localhost:9292/check/some?x=1
|
72
|
+
|
data/Rakefile
ADDED
data/bin/nagios_check
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), %w{.. lib})))
|
3
|
+
require 'nagios_helper/boot'
|
4
|
+
|
5
|
+
raise "RAILS_ROOT not found" unless defined?(RAILS_ROOT)
|
6
|
+
require File.expand_path(File.join(RAILS_ROOT, %w{config environment}))
|
7
|
+
|
8
|
+
require 'nagios_helper/runner_async'
|
9
|
+
|
10
|
+
class Array
|
11
|
+
# define an iterator over each pair of indexes in an array
|
12
|
+
def each_pair_index
|
13
|
+
(0..(self.length-1)).each do |i|
|
14
|
+
((i+1)..(self.length-1 )).each do |j|
|
15
|
+
yield i, j
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# define an iterator over each pair of values in an array for easy reuse
|
21
|
+
def each_pair
|
22
|
+
self.each_pair_index do |i, j|
|
23
|
+
yield self[i], self[j]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
method = ARGV.shift
|
29
|
+
params = {}
|
30
|
+
ARGV.each_pair{|a, b| params[a.to_s.gsub('-', '')] = b }
|
31
|
+
|
32
|
+
status, message = Nagios::RunnerAsync.check(params.merge(:method => method))
|
33
|
+
|
34
|
+
puts message
|
35
|
+
exit status
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# for Rails 3
|
2
|
+
if Rails::VERSION::MAJOR >= 3
|
3
|
+
|
4
|
+
module Nagios
|
5
|
+
class CheckEmGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def add_files
|
9
|
+
template "script_class_em.rb", "app/nagios/#{file_path}.rb"
|
10
|
+
template "spec.rb", "spec/nagios/#{file_path}_spec.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# for Rails 3
|
2
|
+
if Rails::VERSION::MAJOR >= 3
|
3
|
+
|
4
|
+
module Nagios
|
5
|
+
class CheckGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def add_files
|
9
|
+
template "script_class.rb", "app/nagios/#{file_path}.rb"
|
10
|
+
template "spec.rb", "spec/nagios/#{file_path}_spec.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# for Rails 2.3
|
2
|
+
if Rails::VERSION::MAJOR == 2
|
3
|
+
|
4
|
+
class NagiosEmGenerator < Rails::Generator::NamedBase
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
m.template "script_class_em.rb", "app/nagios/#{file_path}.rb"
|
8
|
+
m.directory "spec/nagios"
|
9
|
+
m.template "spec.rb", "spec/nagios/#{file_path}_spec.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# for Rails 2.3
|
2
|
+
if Rails::VERSION::MAJOR == 2
|
3
|
+
|
4
|
+
class NagiosGenerator < Rails::Generator::NamedBase
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
m.template "script_class.rb", "app/nagios/#{file_path}.rb"
|
8
|
+
m.directory "spec/nagios"
|
9
|
+
m.template "spec.rb", "spec/nagios/#{file_path}_spec.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Nagios::<%= class_name %> < Nagios::CheckEM
|
2
|
+
# You can define script parameters this way:
|
3
|
+
params :x # and can use further just x
|
4
|
+
|
5
|
+
def execute
|
6
|
+
EM.next_tick do
|
7
|
+
safe do
|
8
|
+
warn "hmmm" if x == 'w'
|
9
|
+
crit "ouch" if x == 'c'
|
10
|
+
ok "good"
|
11
|
+
|
12
|
+
send_result # should be!, for sending results
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'nagios_check/spec_helper'
|
3
|
+
|
4
|
+
describe Nagios::<%= class_name %> do
|
5
|
+
it 'should be ok' do
|
6
|
+
status, message = Nagios::<%= class_name %>.check({:x => 'some'})
|
7
|
+
status.should == Nagios::OK
|
8
|
+
message.should include('good')
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
class Nagios::Check
|
2
|
+
|
3
|
+
TYPES = %w{ok crit other warn} unless defined?(TYPES)
|
4
|
+
|
5
|
+
def initialize(params, &callback)
|
6
|
+
@params = params.with_indifferent_access
|
7
|
+
@callback = callback
|
8
|
+
@started_at = Time.now
|
9
|
+
@tag = "#{self.class.name}/#{params.inspect}"
|
10
|
+
|
11
|
+
logger.info "=> #{@tag}"
|
12
|
+
|
13
|
+
@ok = []
|
14
|
+
@crit = []
|
15
|
+
@warn = []
|
16
|
+
@other = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def result
|
20
|
+
errors = [@crit, @warn, @other].flatten * '; '
|
21
|
+
|
22
|
+
if @crit.present?
|
23
|
+
[Nagios::CRIT, "CRIT: " + errors]
|
24
|
+
elsif @warn.present?
|
25
|
+
[Nagios::WARN, "WARN: " + errors]
|
26
|
+
elsif @other.present?
|
27
|
+
[Nagios::OTHER, errors]
|
28
|
+
else
|
29
|
+
[Nagios::OK, "OK: " + @ok * '; ']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
safe do
|
35
|
+
execute
|
36
|
+
send_result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# synchrony check, for manually calls
|
41
|
+
def self.check(params = {})
|
42
|
+
result = nil
|
43
|
+
|
44
|
+
inst = self.new(params) do |res|
|
45
|
+
result = res
|
46
|
+
end
|
47
|
+
|
48
|
+
inst.run
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.default_error(mes)
|
52
|
+
[Nagios::OTHER, mes]
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
def send_result
|
58
|
+
st, mes = res = self.result
|
59
|
+
|
60
|
+
logger.info "<= #{@tag} = [#{Nagios.status_name(st)}, #{mes}], time: (#{Time.now - @started_at})"
|
61
|
+
@callback[ res ]
|
62
|
+
|
63
|
+
res
|
64
|
+
end
|
65
|
+
|
66
|
+
def execute
|
67
|
+
raise "realize me"
|
68
|
+
end
|
69
|
+
|
70
|
+
TYPES.each do |m|
|
71
|
+
define_method(m) do |mes|
|
72
|
+
instance_variable_get("@#{m}") << mes
|
73
|
+
end
|
74
|
+
end
|
75
|
+
alias :critical :crit
|
76
|
+
alias :error :crit
|
77
|
+
alias :warning :warn
|
78
|
+
|
79
|
+
def self.logger
|
80
|
+
Nagios.logger
|
81
|
+
end
|
82
|
+
|
83
|
+
def logger
|
84
|
+
Nagios.logger
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.params(*syms)
|
88
|
+
syms.each { |s| define_method(s) { @params[s] } }
|
89
|
+
end
|
90
|
+
|
91
|
+
def safe
|
92
|
+
yield
|
93
|
+
rescue Exception, NameError, Timeout::Error => ex
|
94
|
+
logger.info "X= #{@tag} #{ex.message} (#{ex.backtrace.inspect})"
|
95
|
+
|
96
|
+
other "Exception: " + ex.message
|
97
|
+
send_result
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class Nagios::CheckEM < Nagios::Check
|
2
|
+
|
3
|
+
def run
|
4
|
+
safe do
|
5
|
+
execute
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute
|
10
|
+
send_result
|
11
|
+
end
|
12
|
+
|
13
|
+
def safe_defer
|
14
|
+
EM.defer do
|
15
|
+
safe do
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# synchrony check, for manually calls
|
22
|
+
# do not call in thin!!!
|
23
|
+
def self.check(params = {})
|
24
|
+
result = nil
|
25
|
+
|
26
|
+
EM.run do
|
27
|
+
inst = self.new(params) do |res|
|
28
|
+
begin
|
29
|
+
result = res
|
30
|
+
ensure
|
31
|
+
EM.stop
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
inst.run
|
36
|
+
end
|
37
|
+
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class Nagios::Runner
|
2
|
+
|
3
|
+
def initialize(params, &callback)
|
4
|
+
@params = params.with_indifferent_access
|
5
|
+
@callback = callback
|
6
|
+
@method = @params.delete(:method).to_s
|
7
|
+
@method = @method.gsub(/[^_\.\-a-z0-9]/i, '')
|
8
|
+
@klass_name = "Nagios::#{@method.camelize}"
|
9
|
+
|
10
|
+
raise "method should be" if @method.blank?
|
11
|
+
|
12
|
+
Nagios.mutex.synchronize{ load_initializers }
|
13
|
+
load_class
|
14
|
+
|
15
|
+
run
|
16
|
+
rescue Exception, Timeout::Error => ex
|
17
|
+
Nagios.logger.info "T= #{params.inspect} #{ex.message} (#{ex.backtrace.inspect})"
|
18
|
+
callback[ Nagios::Check.default_error(ex.message) ]
|
19
|
+
end
|
20
|
+
|
21
|
+
# synchrony check, for manual call
|
22
|
+
def self.check(params = {})
|
23
|
+
result = nil
|
24
|
+
|
25
|
+
self.new(params) do |res|
|
26
|
+
result = res
|
27
|
+
end
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def constantize
|
35
|
+
@klass_name.constantize
|
36
|
+
rescue LoadError, NameError
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_initializers
|
41
|
+
unless Nagios.project_initializer_loaded
|
42
|
+
Dir[Nagios.rails_root + "/app/nagios/initializers/*.rb"].each do |file|
|
43
|
+
require File.expand_path(file)
|
44
|
+
end
|
45
|
+
|
46
|
+
Nagios.project_initializer_loaded = true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_class
|
51
|
+
klass = constantize
|
52
|
+
|
53
|
+
unless klass
|
54
|
+
Dir[Nagios.rails_root + "/app/nagios/**/#{@method}.rb"].each do |file|
|
55
|
+
require File.expand_path(file)
|
56
|
+
end
|
57
|
+
|
58
|
+
klass = constantize
|
59
|
+
end
|
60
|
+
|
61
|
+
raise "unknown klass #{@klass_name}" unless klass
|
62
|
+
|
63
|
+
@klass = klass
|
64
|
+
@ancestor = klass.ancestors.detect{|an| an == Nagios::Check || an == Nagios::CheckEM }
|
65
|
+
end
|
66
|
+
|
67
|
+
def run
|
68
|
+
if @ancestor == Nagios::Check
|
69
|
+
script = @klass.new(@params, &@callback)
|
70
|
+
script.run
|
71
|
+
elsif @ancestor == Nagios::CheckEM
|
72
|
+
raise "cant run EM check in Sync Runner"
|
73
|
+
else
|
74
|
+
raise "unknown klass #{@klass.inspect}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
class Nagios::RunnerAsync < Nagios::Runner
|
4
|
+
|
5
|
+
# synchrony check, for manual call
|
6
|
+
# do not run in EM
|
7
|
+
def self.check(params = {})
|
8
|
+
raise "cant check sync in running EM" if EM.reactor_running?
|
9
|
+
|
10
|
+
result = nil
|
11
|
+
EM.run do
|
12
|
+
self.new(params) do |res|
|
13
|
+
begin
|
14
|
+
result = res
|
15
|
+
ensure
|
16
|
+
EM.stop
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def run
|
27
|
+
if @ancestor == Nagios::Check
|
28
|
+
# to thread pool
|
29
|
+
EM.defer do
|
30
|
+
script = @klass.new(@params, &@callback)
|
31
|
+
script.run
|
32
|
+
end
|
33
|
+
|
34
|
+
elsif @ancestor == Nagios::CheckEM
|
35
|
+
script = @klass.new(@params, &@callback)
|
36
|
+
script.run
|
37
|
+
|
38
|
+
else
|
39
|
+
raise "unknown klass #{klass.inspect}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
begin
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
8
|
+
require 'logger'
|
9
|
+
require 'timeout'
|
10
|
+
|
11
|
+
module Nagios
|
12
|
+
OK = 0
|
13
|
+
WARN = 1
|
14
|
+
CRIT = 2
|
15
|
+
OTHER = 3
|
16
|
+
|
17
|
+
CONCURRENCY_LEVEL = 100 # for server
|
18
|
+
|
19
|
+
STATUS_NAMES = {
|
20
|
+
OK => 'ok',
|
21
|
+
WARN => 'warn',
|
22
|
+
CRIT => 'crit',
|
23
|
+
OTHER => 'other'
|
24
|
+
}
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def logger
|
28
|
+
@logger ||= Logger.new(File.join(rails_root, "/log/nagios.log")).tap do |logger|
|
29
|
+
logger.formatter = lambda { |s, d, p, m| "#{d.strftime("%d.%m.%Y %H:%M:%S")} #{m}\n" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :project_initializer_loaded
|
34
|
+
|
35
|
+
def concurrency_level
|
36
|
+
@concurrency_level
|
37
|
+
end
|
38
|
+
|
39
|
+
def mutex
|
40
|
+
@mutex ||= Mutex.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def concurrency_level=(cl)
|
44
|
+
@concurrency_level = cl
|
45
|
+
EM.threadpool_size = cl
|
46
|
+
end
|
47
|
+
|
48
|
+
def status_name(status)
|
49
|
+
':' + STATUS_NAMES[status] || 'unknown'
|
50
|
+
end
|
51
|
+
|
52
|
+
def rails_root
|
53
|
+
defined?(RAILS_ROOT) ? RAILS_ROOT : (defined?(Rails) ? Rails.root : nil)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
autoload :Check, 'nagios_helper/check'
|
58
|
+
autoload :CheckEM, 'nagios_helper/check_em'
|
59
|
+
autoload :Runner, 'nagios_helper/runner'
|
60
|
+
autoload :RunnerAsync, 'nagios_helper/runner_async'
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#require File.dirname(__FILE__) + "/lib/bin_script/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{nagios_helper}
|
6
|
+
s.version = "0.1.1"
|
7
|
+
|
8
|
+
s.authors = ["Makarchev Konstantin"]
|
9
|
+
|
10
|
+
s.description = %q{Rails gem for writing, testing, executing nagios checks inside Rails application. Checks running throught http or binary(nrpe).}
|
11
|
+
s.summary = %q{Rails gem for writing, testing, executing nagios checks inside Rails application. Checks running throught http or binary(nrpe).}
|
12
|
+
|
13
|
+
s.email = %q{kostya27@gmail.com}
|
14
|
+
s.homepage = %q{http://github.com/kostya/nagios_helper}
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'activesupport'
|
22
|
+
s.add_dependency 'eventmachine'
|
23
|
+
|
24
|
+
s.add_development_dependency "rspec"
|
25
|
+
s.add_development_dependency "rake"
|
26
|
+
|
27
|
+
end
|
data/spec/nagios_spec.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Nagios::Runner" do
|
4
|
+
it "run ok" do
|
5
|
+
@status, @message = Nagios::Runner.check({'method' => "bla"})
|
6
|
+
@status.should == Nagios::OK
|
7
|
+
@message.should include('a5')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "run ok method with indefferent access" do
|
11
|
+
@status, @message = Nagios::Runner.check({:method => "bla"})
|
12
|
+
@status.should == Nagios::OK
|
13
|
+
@message.should include('a5')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "undefined klass" do
|
17
|
+
@status, @message = Nagios::Runner.check({'method' => "blah"})
|
18
|
+
@status.should == Nagios::OTHER
|
19
|
+
@message.should include('Nagios::Blah')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "empty class" do
|
23
|
+
@status, @message = Nagios::Runner.check({})
|
24
|
+
@status.should == Nagios::OTHER
|
25
|
+
@message.should include('method should')
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "check" do
|
29
|
+
it "crit" do
|
30
|
+
@status, @message = Nagios::Runner.check({'method' => "bla", 's' => 'crit'})
|
31
|
+
@status.should == Nagios::CRIT
|
32
|
+
@message.should include('a1')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "warn" do
|
36
|
+
@status, @message = Nagios::Runner.check({'method' => "bla", 's' => 'warn'})
|
37
|
+
@status.should == Nagios::WARN
|
38
|
+
@message.should include('a2')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raise" do
|
42
|
+
@status, @message = Nagios::Runner.check({'method' => "bla", 's' => 'raise'})
|
43
|
+
@status.should == Nagios::OTHER
|
44
|
+
@message.should include('a3')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "other" do
|
48
|
+
@status, @message = Nagios::Runner.check({'method' => "bla", 's' => 'other'})
|
49
|
+
@status.should == Nagios::OTHER
|
50
|
+
@message.should include('a4')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "ok" do
|
54
|
+
@status, @message = Nagios::Runner.check({'method' => "bla", 's' => 'ok'})
|
55
|
+
@status.should == Nagios::OK
|
56
|
+
@message.should include('a5')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "crit_warn" do
|
60
|
+
@status, @message = Nagios::Runner.check({'method' => "bla", 's' => 'crit_warn'})
|
61
|
+
@status.should == Nagios::CRIT
|
62
|
+
@message.should include('a1')
|
63
|
+
@message.should include('a2')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "check_em" do
|
68
|
+
it "crit" do
|
69
|
+
@status, @message = Nagios::RunnerAsync.check({'method' => "bla_em", 's' => 'crit'})
|
70
|
+
@status.should == Nagios::CRIT
|
71
|
+
@message.should include('b1')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "warn" do
|
75
|
+
@status, @message = Nagios::RunnerAsync.check({'method' => "bla_em", 's' => 'warn'})
|
76
|
+
@status.should == Nagios::WARN
|
77
|
+
@message.should include('b2')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "raise" do
|
81
|
+
@status, @message = Nagios::RunnerAsync.check({'method' => "bla_em", 's' => 'raise'})
|
82
|
+
@status.should == Nagios::OTHER
|
83
|
+
@message.should include('b3')
|
84
|
+
end
|
85
|
+
|
86
|
+
it "other" do
|
87
|
+
@status, @message = Nagios::RunnerAsync.check({'method' => "bla_em", 's' => 'other'})
|
88
|
+
@status.should == Nagios::OTHER
|
89
|
+
@message.should include('b4')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "ok" do
|
93
|
+
@status, @message = Nagios::RunnerAsync.check({'method' => "bla_em", 's' => 'ok'})
|
94
|
+
@status.should == Nagios::OK
|
95
|
+
@message.should include('b5')
|
96
|
+
end
|
97
|
+
|
98
|
+
it "crit_warn" do
|
99
|
+
@status, @message = Nagios::RunnerAsync.check({'method' => "bla_em", 's' => 'crit_warn'})
|
100
|
+
@status.should == Nagios::CRIT
|
101
|
+
@message.should include('b1')
|
102
|
+
@message.should include('b2')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Nagios::Bla < Nagios::Check
|
4
|
+
params :s
|
5
|
+
|
6
|
+
def execute
|
7
|
+
crit 'a1' if s == 'crit' || s == 'crit_warn'
|
8
|
+
warn 'a2' if s == 'warn' || s == 'crit_warn'
|
9
|
+
raise 'a3' if s == 'raise'
|
10
|
+
other 'a4' if s == 'other'
|
11
|
+
ok 'a5'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class Nagios::BlaEm < Nagios::CheckEM
|
17
|
+
|
18
|
+
params :s
|
19
|
+
|
20
|
+
def execute
|
21
|
+
crit 'b1' if s == 'crit' || s == 'crit_warn'
|
22
|
+
warn 'b2' if s == 'warn' || s == 'crit_warn'
|
23
|
+
raise 'b3' if s == 'raise'
|
24
|
+
other 'b4' if s == 'other'
|
25
|
+
ok 'b5'
|
26
|
+
|
27
|
+
send_result
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
|
6
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
7
|
+
require 'nagios_check'
|
8
|
+
|
9
|
+
require 'nagios_support'
|
10
|
+
|
11
|
+
def Nagios.rails_root
|
12
|
+
File.join(File.dirname(__FILE__), %w{ .. })
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nagios_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Makarchev Konstantin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-09-15 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
|
+
requirement: *id001
|
34
|
+
name: activesupport
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
prerelease: false
|
46
|
+
type: :runtime
|
47
|
+
requirement: *id002
|
48
|
+
name: eventmachine
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
prerelease: false
|
60
|
+
type: :development
|
61
|
+
requirement: *id003
|
62
|
+
name: rspec
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
prerelease: false
|
74
|
+
type: :development
|
75
|
+
requirement: *id004
|
76
|
+
name: rake
|
77
|
+
description: Rails gem for writing, testing, executing nagios checks inside Rails application. Checks running throught http or binary(nrpe).
|
78
|
+
email: kostya27@gmail.com
|
79
|
+
executables:
|
80
|
+
- nagios_check
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files: []
|
84
|
+
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/nagios_check
|
92
|
+
- lib/generators/nagios/check_em_generator.rb
|
93
|
+
- lib/generators/nagios/check_generator.rb
|
94
|
+
- lib/generators/nagios/nagios_em_generator.rb
|
95
|
+
- lib/generators/nagios/nagios_generator.rb
|
96
|
+
- lib/generators/nagios/templates/script_class.rb
|
97
|
+
- lib/generators/nagios/templates/script_class_em.rb
|
98
|
+
- lib/generators/nagios/templates/spec.rb
|
99
|
+
- lib/nagios_helper.rb
|
100
|
+
- lib/nagios_helper/boot.rb
|
101
|
+
- lib/nagios_helper/check.rb
|
102
|
+
- lib/nagios_helper/check_em.rb
|
103
|
+
- lib/nagios_helper/runner.rb
|
104
|
+
- lib/nagios_helper/runner_async.rb
|
105
|
+
- lib/nagios_helper/spec_helper.rb
|
106
|
+
- nagios_helper.gemspec
|
107
|
+
- spec/nagios_spec.rb
|
108
|
+
- spec/nagios_support.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: http://github.com/kostya/nagios_helper
|
112
|
+
licenses: []
|
113
|
+
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.4.2
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: Rails gem for writing, testing, executing nagios checks inside Rails application. Checks running throught http or binary(nrpe).
|
144
|
+
test_files: []
|
145
|
+
|