nagios 0.0.2 → 0.0.3
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/README.md +8 -1
- data/lib/nagios/#plugin.rb# +83 -0
- data/lib/nagios/plugin.rb +7 -0
- data/lib/nagios/plugin.rb.x +82 -0
- data/lib/nagios/version.rb +1 -1
- metadata +6 -4
data/README.md
CHANGED
@@ -14,6 +14,14 @@ Subclass `Nagios::Plugin`, and define three methods:
|
|
14
14
|
|
15
15
|
* **warning** - for any given *n*, returns whether in warning state.
|
16
16
|
|
17
|
+
Optional methods:
|
18
|
+
|
19
|
+
* **critical_msg** - Message to be used during a critical state.
|
20
|
+
|
21
|
+
* **warning_msg** - Message to be used during a warning state.
|
22
|
+
|
23
|
+
* **ok_msg** - Message to be used during an OK state.
|
24
|
+
|
17
25
|
Example Plugin
|
18
26
|
==============
|
19
27
|
|
@@ -23,7 +31,6 @@ In this trivial example, the plugin always measures 2, which is below both the w
|
|
23
31
|
require 'nagios'
|
24
32
|
|
25
33
|
class FooPlugin < Nagios::Plugin
|
26
|
-
|
27
34
|
def critical(n)
|
28
35
|
n > 5
|
29
36
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Nagios
|
2
|
+
class Plugin
|
3
|
+
|
4
|
+
class << self
|
5
|
+
# Syntactic sugar for creating a new instance automagically
|
6
|
+
def run!
|
7
|
+
new.run!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Constructor
|
12
|
+
def initialize
|
13
|
+
@config = Nagios::Config.new
|
14
|
+
@status_used = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# Run the plugin
|
18
|
+
# Parse the config, take a measurement and pass to critical/warning
|
19
|
+
# If all else fails, exit with an unknown
|
20
|
+
def run!
|
21
|
+
@config.parse!
|
22
|
+
begin
|
23
|
+
@value = measure
|
24
|
+
if critical(@value)
|
25
|
+
exit_with :critical, get_msg(:critical, @value)
|
26
|
+
elsif warning(@value)
|
27
|
+
exit_with :warning, get_msg(:warning, @value)
|
28
|
+
else
|
29
|
+
exit_with :ok, get_msg(:ok, @value)
|
30
|
+
end
|
31
|
+
rescue => e
|
32
|
+
exit_unknown e
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
def threshold(level)
|
38
|
+
if level == :warning
|
39
|
+
@config[:warning] || -1
|
40
|
+
elsif level == :critical
|
41
|
+
@config[:critical] || -1
|
42
|
+
else
|
43
|
+
-1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s(value)
|
48
|
+
"#{value}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def status
|
52
|
+
@status_used = true
|
53
|
+
@status
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def get_msg(level, value)
|
58
|
+
msg_method = "#{level}_msg".to_sym
|
59
|
+
if self.respond_to?(msg_method)
|
60
|
+
self.send(msg_method, value)
|
61
|
+
else
|
62
|
+
value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def exit_with(level, value)
|
67
|
+
@status = level.to_s.upcase
|
68
|
+
msg = to_s(value)
|
69
|
+
if @status_used
|
70
|
+
puts msg
|
71
|
+
else
|
72
|
+
puts "#{@status}: #{msg}"
|
73
|
+
end
|
74
|
+
exit Nagios.const_get("EXIT_#{@status}")
|
75
|
+
end
|
76
|
+
|
77
|
+
def exit_unknown(exc_info)
|
78
|
+
puts "UNKNOWN (Exception): #{exc_info}"
|
79
|
+
exit Nagios::EXIT_UNKNOWN
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/nagios/plugin.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Nagios
|
2
|
+
class Plugin
|
3
|
+
|
4
|
+
class << self
|
5
|
+
# Syntactic sugar for creating a new instance automagically
|
6
|
+
def run!
|
7
|
+
new.run!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Constructor
|
12
|
+
def initialize
|
13
|
+
@config = Nagios::Config.new
|
14
|
+
@status_used = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# Run the plugin
|
18
|
+
# Parse the config, take a measurement and pass to critical/warning
|
19
|
+
# If all else fails, exit with an unknown
|
20
|
+
def run!
|
21
|
+
@config.parse!
|
22
|
+
begin
|
23
|
+
@value = measure
|
24
|
+
if critical(@value)
|
25
|
+
exit_with :critical, get_msg(:critical, @value)
|
26
|
+
elsif warning(@value)
|
27
|
+
exit_with :warning, get_msg(:warning, @value)
|
28
|
+
else
|
29
|
+
exit_with :ok, get_msg(:ok, @value)
|
30
|
+
end
|
31
|
+
rescue => e
|
32
|
+
exit_unknown e
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def threshold(level)
|
37
|
+
if level == :warning
|
38
|
+
@config[:warning] || -1
|
39
|
+
elsif level == :critical
|
40
|
+
@config[:critical] || -1
|
41
|
+
else
|
42
|
+
-1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s(value)
|
47
|
+
"#{value}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def status
|
51
|
+
@status_used = true
|
52
|
+
@status
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def get_msg(level, value)
|
57
|
+
msg_method = "#{level}_msg".to_sym
|
58
|
+
if self.respond_to?(msg_method)
|
59
|
+
self.send(msg_method, value)
|
60
|
+
else
|
61
|
+
value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def exit_with(level, value)
|
66
|
+
@status = level.to_s.upcase
|
67
|
+
msg = to_s(value)
|
68
|
+
if @status_used
|
69
|
+
puts msg
|
70
|
+
else
|
71
|
+
puts "#{@status}: #{msg}"
|
72
|
+
end
|
73
|
+
exit Nagios.const_get("EXIT_#{@status}")
|
74
|
+
end
|
75
|
+
|
76
|
+
def exit_unknown(exc_info)
|
77
|
+
puts "UNKNOWN (Exception): #{exc_info}"
|
78
|
+
exit Nagios::EXIT_UNKNOWN
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/nagios/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jerry Chen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-01 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: " Nagios-rb is a compact framework for writing Nagios plugins.\n"
|
@@ -29,9 +29,11 @@ extra_rdoc_files:
|
|
29
29
|
- README.md
|
30
30
|
files:
|
31
31
|
- README.md
|
32
|
+
- lib/nagios/#plugin.rb#
|
32
33
|
- lib/nagios/config.rb
|
33
34
|
- lib/nagios/exit_codes.rb
|
34
35
|
- lib/nagios/plugin.rb
|
36
|
+
- lib/nagios/plugin.rb.x
|
35
37
|
- lib/nagios/version.rb
|
36
38
|
- lib/nagios.rb
|
37
39
|
- LICENSE
|