nagios_check 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +75 -0
- data/lib/nagios_check.rb +11 -3
- data/lib/nagios_check/version.rb +1 -1
- data/spec/options_spec.rb +92 -0
- metadata +5 -3
- data/README.rdoc +0 -22
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
NagiosCheck
|
2
|
+
============
|
3
|
+
|
4
|
+
Description
|
5
|
+
-----------
|
6
|
+
|
7
|
+
NagiosCheck is a simple and efficient tool for building custom probes for the
|
8
|
+
Nagios monitoring system. It alleviates the pain of parsing command line
|
9
|
+
options, writing and formatting the check results according to the Nagios
|
10
|
+
plugin API.
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
``` bash
|
16
|
+
gem install nagios_check
|
17
|
+
```
|
18
|
+
|
19
|
+
Features
|
20
|
+
--------
|
21
|
+
|
22
|
+
* Provide a simple to use DSL for building your own probes.
|
23
|
+
* Parse command line options.
|
24
|
+
* Report status data to Nagios (handles exceptions as UNKNOWN status).
|
25
|
+
* Provide a Nagios like range description format for the WARNING and CRITICAL states.
|
26
|
+
* Provide a simple timeout functionality to be more Nagios friendly.
|
27
|
+
* Report performance data to Nagios.
|
28
|
+
|
29
|
+
Usage and documentation
|
30
|
+
-----------------------
|
31
|
+
|
32
|
+
NagiosCheck is a module. To use it simply include it in a class and declare
|
33
|
+
how the check should behave:
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
require "nagios_check"
|
37
|
+
|
38
|
+
class SimpleCheck
|
39
|
+
include NagiosCheck
|
40
|
+
|
41
|
+
on "-H HOST", :required, &store(:host)
|
42
|
+
on "-P PORT", &store(:port, default: 8080, transform: :to_i)
|
43
|
+
|
44
|
+
enable_warning
|
45
|
+
enable_critical
|
46
|
+
enable_timeout
|
47
|
+
|
48
|
+
def check
|
49
|
+
time = do_some_check(options.host, options.port)
|
50
|
+
store_value :duration, time
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
SimpleCheck.new.run
|
55
|
+
```
|
56
|
+
|
57
|
+
The command can then be used by Nagios:
|
58
|
+
|
59
|
+
``` bash
|
60
|
+
ruby simple_check.rb -H my_host -P my_port -w 4 -c 8 -t 10
|
61
|
+
```
|
62
|
+
|
63
|
+
If the value returned by `do_some_check` is between 0 and 4 inclusive the result is OK. If it is greater than 4 and less than 8 inclusive the result is WARNING. If it is greater than 8 the result is CRITICAL. See [Nagios Developer Guidelines][nagios-dev] for more details on how the arguments of `-w` and `-c` are interpreted.
|
64
|
+
|
65
|
+
If the check method lasts more than 10 seconds, it times out and the returned value is UNKNOWN.
|
66
|
+
|
67
|
+
License
|
68
|
+
-------
|
69
|
+
Released under the MIT License. See the [MIT-LICENSE][license] file for further details.
|
70
|
+
|
71
|
+
[license]: https://github.com/dbroeglin/nagios_check/blob/master/MIT-LICENSE
|
72
|
+
[nagios-dev]: http://nagiosplug.sourceforge.net/developer-guidelines.html
|
73
|
+
|
74
|
+
Copyright 2011 Dominique Broeglin
|
75
|
+
|
data/lib/nagios_check.rb
CHANGED
@@ -62,12 +62,14 @@ module NagiosCheck
|
|
62
62
|
|
63
63
|
module ClassMethods
|
64
64
|
def on(*args, &block)
|
65
|
-
@ons << [args, args.delete(:
|
65
|
+
@ons << [args, args.delete(:mandatory), block]
|
66
66
|
end
|
67
67
|
|
68
68
|
def store(name, opts = {})
|
69
69
|
@defaults[name] = opts[:default] if opts.has_key?(:default)
|
70
|
+
transform = opts[:transform]
|
70
71
|
Proc::new do |value|
|
72
|
+
value = value.send transform if transform
|
71
73
|
self.options.send "#{name}=", value
|
72
74
|
end
|
73
75
|
end
|
@@ -108,8 +110,10 @@ module NagiosCheck
|
|
108
110
|
def opt_parse
|
109
111
|
unless @opt_parse
|
110
112
|
opt_parse = OptionParser::new
|
111
|
-
self.class.instance_variable_get("@ons").each do |args,
|
112
|
-
opt_parse.on(*args)
|
113
|
+
self.class.instance_variable_get("@ons").each do |args, mand, block|
|
114
|
+
opt_parse.on(*args) do |value|
|
115
|
+
instance_exec(value, &block)
|
116
|
+
end
|
113
117
|
end
|
114
118
|
@opt_parse = opt_parse
|
115
119
|
end
|
@@ -121,7 +125,11 @@ module NagiosCheck
|
|
121
125
|
opt_parse.parse!(argv)
|
122
126
|
end
|
123
127
|
|
128
|
+
|
124
129
|
def check_with_timeout
|
125
130
|
Timeout.timeout(@timeout) { check }
|
126
131
|
end
|
132
|
+
|
133
|
+
class MissingOption < StandardError
|
134
|
+
end
|
127
135
|
end
|
data/lib/nagios_check/version.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
describe NagiosCheck do
|
2
|
+
context "when no options specified" do
|
3
|
+
subject do
|
4
|
+
Class::new do
|
5
|
+
include NagiosCheck
|
6
|
+
end.new
|
7
|
+
end
|
8
|
+
|
9
|
+
specify { subject.send :parse_options, [] }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when warning is specified" do
|
13
|
+
subject do
|
14
|
+
Class::new do
|
15
|
+
include NagiosCheck
|
16
|
+
enable_warning
|
17
|
+
end.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it("works with no arguments"){ subject.send :parse_options, %w{} }
|
21
|
+
specify { subject.send :parse_options, %w{-w 10} }
|
22
|
+
|
23
|
+
it "fails if -w has no argument" do
|
24
|
+
lambda {
|
25
|
+
subject.send :parse_options, %w{-w}
|
26
|
+
}.should raise_error(OptionParser::MissingArgument)
|
27
|
+
end
|
28
|
+
it "fails if -c is given" do
|
29
|
+
lambda {
|
30
|
+
subject.send :parse_options, %w{-c}
|
31
|
+
}.should raise_error(OptionParser::InvalidOption)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when critical is specified" do
|
36
|
+
subject do
|
37
|
+
Class::new do
|
38
|
+
include NagiosCheck
|
39
|
+
enable_critical
|
40
|
+
end.new
|
41
|
+
end
|
42
|
+
|
43
|
+
it("works with no arguments"){ subject.send :parse_options, %w{} }
|
44
|
+
specify { subject.send :parse_options, %w{-c 10} }
|
45
|
+
|
46
|
+
it "fails if -c has no argument" do
|
47
|
+
lambda {
|
48
|
+
subject.send :parse_options, %w{-c}
|
49
|
+
}.should raise_error(OptionParser::MissingArgument)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "fails if -w is given" do
|
53
|
+
lambda {
|
54
|
+
subject.send :parse_options, %w{-w}
|
55
|
+
}.should raise_error(OptionParser::InvalidOption)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when a non mandatory option is specified" do
|
60
|
+
subject do
|
61
|
+
Class::new do
|
62
|
+
include NagiosCheck
|
63
|
+
on "-a VALUE", &store(:a)
|
64
|
+
on "-b VALUE", &store(:b, transform: :to_i)
|
65
|
+
end.new
|
66
|
+
end
|
67
|
+
|
68
|
+
it("works with no arguments"){ subject.send :parse_options, %w{} }
|
69
|
+
|
70
|
+
it "works with '-a 10'" do
|
71
|
+
subject.send :parse_options, %w{-a 10}
|
72
|
+
subject.options.a.should == "10"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "works with '-b 20' and converts to int" do
|
76
|
+
subject.send :parse_options, %w{-b 20}
|
77
|
+
subject.options.b.should == 20
|
78
|
+
end
|
79
|
+
|
80
|
+
it "fails if -a has no argument" do
|
81
|
+
lambda {
|
82
|
+
subject.send :parse_options, %w{-a}
|
83
|
+
}.should raise_error(OptionParser::MissingArgument)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "fails if -w is given" do
|
87
|
+
lambda {
|
88
|
+
subject.send :parse_options, %w{-w}
|
89
|
+
}.should raise_error(OptionParser::InvalidOption)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagios_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-30 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: An easy to use DSL for building custom probes for the Nagios monitoring
|
15
15
|
system
|
@@ -22,13 +22,14 @@ files:
|
|
22
22
|
- .gitignore
|
23
23
|
- Gemfile
|
24
24
|
- MIT-LICENSE
|
25
|
-
- README.
|
25
|
+
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- lib/nagios_check.rb
|
28
28
|
- lib/nagios_check/range.rb
|
29
29
|
- lib/nagios_check/version.rb
|
30
30
|
- nagios_check.gemspec
|
31
31
|
- spec/finish_spec.rb
|
32
|
+
- spec/options_spec.rb
|
32
33
|
- spec/range_spec.rb
|
33
34
|
- spec/spec_helper.rb
|
34
35
|
homepage: https://github.com/dbroeglin/nagios_check
|
@@ -57,5 +58,6 @@ specification_version: 3
|
|
57
58
|
summary: Ruby Nagios Check Integration
|
58
59
|
test_files:
|
59
60
|
- spec/finish_spec.rb
|
61
|
+
- spec/options_spec.rb
|
60
62
|
- spec/range_spec.rb
|
61
63
|
- spec/spec_helper.rb
|
data/README.rdoc
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
= Nagios Check
|
2
|
-
|
3
|
-
License:: MIT license (see MIT-LICENSE file)
|
4
|
-
Copyright:: 2011 Dominique Broeglin
|
5
|
-
|
6
|
-
|
7
|
-
== DESCRIPTION
|
8
|
-
|
9
|
-
An easy to use DSL for building custom probes for the Nagios monitoring system.
|
10
|
-
|
11
|
-
== FEATURES
|
12
|
-
|
13
|
-
* Provide a simple to use DSL for building your own probes.
|
14
|
-
* Decode command line options.
|
15
|
-
* Report status data to Nagios.
|
16
|
-
* Report performance data to Nagios.
|
17
|
-
|
18
|
-
|
19
|
-
== RESOURCES
|
20
|
-
|
21
|
-
* {Website}[https://github.com/dbroeglin/nagios_check]
|
22
|
-
* {Source Code}[https://github.com/dbroeglin/nagios_check]
|