nagios 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +29 -0
- data/README.md +41 -0
- data/lib/nagios.rb +4 -0
- data/lib/nagios/config.rb +41 -0
- data/lib/nagios/exit_codes.rb +6 -0
- data/lib/nagios/plugin.rb +62 -0
- data/lib/nagios/version.rb +3 -0
- metadata +74 -0
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Copyright 2010 Jerry Chen. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are
|
5
|
+
met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above
|
11
|
+
copyright notice, this list of conditions and the following
|
12
|
+
disclaimer in the documentation and/or other materials provided
|
13
|
+
with the distribution.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY JERRY CHEN ``AS IS'' AND ANY EXPRESS OR
|
16
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL JERRY CHEN OR CONTRIBUTORS BE LIABLE FOR
|
19
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
21
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
22
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
23
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
24
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
25
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
|
27
|
+
The views and conclusions contained in the software and documentation
|
28
|
+
are those of the authors and should not be interpreted as representing
|
29
|
+
official policies, either expressed or implied, of Jerry Chen.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
nagios-rb
|
2
|
+
=========
|
3
|
+
|
4
|
+
A compact framework for writing [Nagios](http://www.nagios.org/) plugins.
|
5
|
+
|
6
|
+
Quick Start
|
7
|
+
===========
|
8
|
+
|
9
|
+
Subclass `Nagios::Plugin`, and define three methods:
|
10
|
+
|
11
|
+
* **measure** - returns the measured value, and optionally sets `@stats` for later usage.
|
12
|
+
|
13
|
+
* **critical** - for any given *n*, returns whether in critical state.
|
14
|
+
|
15
|
+
* **warning** - for any given *n*, returns whether in warning state.
|
16
|
+
|
17
|
+
Example Plugin
|
18
|
+
==============
|
19
|
+
|
20
|
+
In this trivial example, the plugin always measures 2, which is below both the warning and critical thresholds.
|
21
|
+
|
22
|
+
require 'nagios'
|
23
|
+
|
24
|
+
class FooPlugin < Nagios::Plugin
|
25
|
+
def critical(n)
|
26
|
+
n > 5
|
27
|
+
end
|
28
|
+
def warning(n)
|
29
|
+
n > 3
|
30
|
+
end
|
31
|
+
def measure
|
32
|
+
2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
FooPlugin.new.run!
|
37
|
+
|
38
|
+
Future Work
|
39
|
+
===========
|
40
|
+
|
41
|
+
Lots.
|
data/lib/nagios.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Nagios
|
4
|
+
class Config
|
5
|
+
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@settings = {}
|
10
|
+
@options = OptionParser.new do |options|
|
11
|
+
options.on("-wWARNING",
|
12
|
+
"--warning=WARNING",
|
13
|
+
"Warning Threshold") do |x|
|
14
|
+
@settings[:warning] = int_if_possible(x)
|
15
|
+
end
|
16
|
+
options.on("-cCRITICAL",
|
17
|
+
"--critical=CRITICAL",
|
18
|
+
"Critical Threshold") do |x|
|
19
|
+
@settings[:critical] = int_if_possible(x)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](setting)
|
25
|
+
@settings[setting]
|
26
|
+
end
|
27
|
+
|
28
|
+
def []=(field, value)
|
29
|
+
@settings[field] = vaule
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse!
|
33
|
+
@options.parse!
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def int_if_possible(x)
|
38
|
+
(x.to_i > 0 || x == '0') ? x.to_i : x
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Nagios
|
2
|
+
class Plugin
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@config = Nagios::Config.new
|
6
|
+
@status_used = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def run!
|
10
|
+
@config.parse!
|
11
|
+
begin
|
12
|
+
@value = measure
|
13
|
+
if critical(@value)
|
14
|
+
exit_with :critical, @value
|
15
|
+
elsif warning(@value)
|
16
|
+
exit_with :warning, @value
|
17
|
+
else
|
18
|
+
exit_with :ok, @value
|
19
|
+
end
|
20
|
+
rescue => e
|
21
|
+
exit_unknown e
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def threshold(level)
|
26
|
+
if level == :warning
|
27
|
+
@config[:warning] || -1
|
28
|
+
elsif level == :critical
|
29
|
+
@config[:critical] || -1
|
30
|
+
else
|
31
|
+
-1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s(value)
|
36
|
+
"#{value}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def status
|
40
|
+
@status_used = true
|
41
|
+
@status
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def exit_with(level, value)
|
46
|
+
@status = level.to_s.upcase
|
47
|
+
msg = to_s(@value)
|
48
|
+
if @status_used
|
49
|
+
puts msg
|
50
|
+
else
|
51
|
+
puts "#{@status}: #{msg}"
|
52
|
+
end
|
53
|
+
exit Nagios.const_get("EXIT_#{@status}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def exit_unknown(exc_info)
|
57
|
+
puts "UNKNOWN (Exception): #{exc_info}"
|
58
|
+
exit Nagios::EXIT_UNKNOWN
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nagios
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jerry Chen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-03 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: " Nagios-rb is a compact framework for writing Nagios plugins.\n"
|
23
|
+
email: jerry@apache.org
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.md
|
31
|
+
files:
|
32
|
+
- README.md
|
33
|
+
- lib/nagios/config.rb
|
34
|
+
- lib/nagios/exit_codes.rb
|
35
|
+
- lib/nagios/plugin.rb
|
36
|
+
- lib/nagios/version.rb
|
37
|
+
- lib/nagios.rb
|
38
|
+
- LICENSE
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/jcsalterego/nagios-rb
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: nagios-rb is a compact framework for writing Nagios plugins.
|
73
|
+
test_files: []
|
74
|
+
|