nagios-probe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Abdemoulaie
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.
@@ -0,0 +1,69 @@
1
+ = nagios-probe
2
+
3
+ Provides an easy to use API for generating custom probes and communicating probe success/failure to Nagios.
4
+
5
+ == Installation
6
+
7
+ # gem install nagios-probe
8
+
9
+ == Usage
10
+
11
+ Simply create a subclass of Nagios::Probe and define the following methods:
12
+
13
+ * check_crit
14
+ * check_warn
15
+ * check_ok (optional*)
16
+ * crit_message
17
+ * warn_message
18
+ * ok_message
19
+
20
+ *check_ok is defined in the base class to always return true.
21
+
22
+ class MyProbe < Nagios::Probe
23
+ def check_crit
24
+ true
25
+ end
26
+
27
+ def check_warn
28
+ false
29
+ end
30
+
31
+ def crit_message
32
+ "Things are bad"
33
+ end
34
+
35
+ def warn_message
36
+ "Things aren't going well"
37
+ end
38
+
39
+ def ok_message
40
+ "Nothing to see here"
41
+ end
42
+ end
43
+
44
+ To use your probe you *must* wrap it in a begin/rescue block to catch any exceptions and accurately report the status to Nagios.
45
+
46
+ begin
47
+ options = {} # Nagios::Probe constructor accepts a single optional param that is assigned to @opts
48
+ probe = MyProbe.new(options)
49
+ probe.run
50
+ rescue Exception => e
51
+ puts "Unknown: " + e
52
+ exit Nagios::UNKNOWN
53
+ end
54
+
55
+ puts probe.message
56
+ exit probe.retval
57
+ == Note on Patches/Pull Requests
58
+
59
+ * Fork the project.
60
+ * Make your feature addition or bug fix.
61
+ * Add tests for it. This is important so I don't break it in a
62
+ future version unintentionally.
63
+ * Commit, do not mess with rakefile, version, or history.
64
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
65
+ * Send me a pull request. Bonus points for topic branches.
66
+
67
+ == Copyright
68
+
69
+ Copyright (c) 2009 David Abdemoulaie. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "nagios-probe"
8
+ gem.summary = "A very simple tool to assist with creating custom nagios probes in Ruby"
9
+ gem.description = "Provides an easy to use API for generating custom probes and communicating probe success/failure to Nagios"
10
+ gem.email = "dave@hobodave.com"
11
+ gem.homepage = "http://github.com/hobodave/nagios-probe"
12
+ gem.authors = ["David Abdemoulaie"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "nagios-probe #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,80 @@
1
+ module Nagios
2
+ OK = 0
3
+ WARNING = 1
4
+ CRITICAL = 2
5
+ UNKNOWN = 3
6
+
7
+ def crit(message)
8
+ "Critical: #{message}"
9
+ end
10
+
11
+ def warn(message)
12
+ "Warning: #{message}"
13
+ end
14
+
15
+ def ok(message)
16
+ "OK: #{message}"
17
+ end
18
+
19
+ class Probe
20
+ include Nagios
21
+ attr_reader :retval, :message
22
+
23
+ def initialize(opts = {})
24
+ @opts = opts
25
+ @retval = OK
26
+ @message = ok(ok_message)
27
+ end
28
+
29
+ def crit?
30
+ is_crit = check_crit
31
+ return false unless is_crit
32
+ @retval = CRITICAL
33
+ @message = crit(crit_message)
34
+ true
35
+ end
36
+
37
+ def warn?
38
+ is_warn = check_warn
39
+ return false unless is_warn
40
+ @retval = WARNING
41
+ @message = warn(warn_message)
42
+ true
43
+ end
44
+
45
+ def ok?
46
+ is_ok = check_ok
47
+ return false unless is_ok
48
+ @retval = OK
49
+ @message = ok(ok_message)
50
+ true
51
+ end
52
+
53
+ def check_ok
54
+ true
55
+ end
56
+
57
+ def run
58
+ if !crit?
59
+ if !warn?
60
+ if !ok?
61
+ @retval = UNKNOWN
62
+ raise RuntimeError, "crit? warn? and ok? all returned false"
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def crit_message
69
+ "Default message - override crit_message."
70
+ end
71
+
72
+ def warn_message
73
+ "Default message - override warn_message."
74
+ end
75
+
76
+ def ok_message
77
+ "Default message - override ok_message."
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'nagios-probe'
8
+
9
+ class Test::Unit::TestCase
10
+ end
11
+
12
+ class CriticalProbe < Nagios::Probe
13
+ def check_crit
14
+ true
15
+ end
16
+ end
17
+
18
+ class WarnProbe < Nagios::Probe
19
+ def check_crit
20
+ false
21
+ end
22
+
23
+ def check_warn
24
+ true
25
+ end
26
+ end
27
+
28
+ class OKProbe < Nagios::Probe
29
+ def check_crit
30
+ false
31
+ end
32
+
33
+ def check_warn
34
+ false
35
+ end
36
+ end
37
+
38
+ class BadProbe < Nagios::Probe
39
+ def check_crit
40
+ false
41
+ end
42
+ alias :check_warn :check_crit
43
+ alias :check_ok :check_crit
44
+ end
45
+
46
+ class AllTrueProbe < Nagios::Probe
47
+ def check_crit
48
+ true
49
+ end
50
+ alias :check_warn :check_crit
51
+ alias :check_ok :check_crit
52
+ end
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ class TestNagiosProbe < Test::Unit::TestCase
4
+ context "A probe" do
5
+ setup do
6
+ @crit = CriticalProbe.new
7
+ @warn = WarnProbe.new
8
+ @ok = OKProbe.new
9
+ end
10
+
11
+ should "have retval of 2 when critical" do
12
+ @crit.run
13
+ assert_equal 2, @crit.retval
14
+ end
15
+
16
+ should "have retval of 1 when warn" do
17
+ @warn.run
18
+ assert_equal 1, @warn.retval
19
+ end
20
+
21
+ should "have retval of 0 when OK" do
22
+ @ok.run
23
+ assert_equal 0, @ok.retval
24
+ end
25
+
26
+ should "return default message when no user overrides are defined" do
27
+ @crit.run
28
+ @warn.run
29
+ @ok.run
30
+ assert_equal "Critical: Default message - override crit_message.", @crit.message
31
+ assert_equal "Warning: Default message - override warn_message.", @warn.message
32
+ assert_equal "OK: Default message - override ok_message.", @ok.message
33
+ end
34
+
35
+ should "throw exception when all valid statuses are false (Critical, Warning, OK)" do
36
+ @bad = BadProbe.new
37
+ assert_raise RuntimeError do
38
+ @bad.run
39
+ end
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nagios-probe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Abdemoulaie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Provides an easy to use API for generating custom probes and communicating probe success/failure to Nagios
26
+ email: dave@hobodave.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/nagios-probe.rb
42
+ - test/helper.rb
43
+ - test/test_nagios-probe.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/hobodave/nagios-probe
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: A very simple tool to assist with creating custom nagios probes in Ruby
72
+ test_files:
73
+ - test/helper.rb
74
+ - test/test_nagios-probe.rb