nagiosplugin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@nagiosplugin --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nagiosplugin.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'cucumber' do
5
+ watch(%r{^lib/.+$}) { 'features' }
6
+ watch(%r{^features/.+\.feature$})
7
+ watch(%r{^features/support/.+$}) { 'features' }
8
+ watch(%r{^features/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Björn Albers
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,52 @@
1
+ # NagiosPlugin
2
+
3
+ NagiosPlugin is a simple framework for writing [Nagios](http://www.nagios.org/) Plugins.
4
+
5
+ ## Installation
6
+
7
+ `gem install nagiosplugin`
8
+
9
+ ## Usage
10
+
11
+ Create your executable plugin (which will be called by nagios), `require "nagiosplugin"` and subclass from `NagiosPlugin::Plugin`.
12
+ You must define the methods `critical?` and `warning?` which determine the plugin status during a check based on their boolean return value (`ok?` returns true by default but can be overwritten).
13
+ The optional method `measure` will be called *first* on every check to take samples.
14
+ Run `check!` on your *class* to ensure a proper plugin output (= stdout & exit status).
15
+
16
+ Here's a simple example plugin named `check_u2d`:
17
+
18
+ ````Ruby
19
+ #!/usr/bin/env ruby
20
+ require 'nagiosplugin'
21
+
22
+ class UnicornToDwarfRatio < NagiosPlugin::Plugin
23
+ def measure
24
+ @unicorns, @dwarves = ... # The algorithm is your homework.
25
+ end
26
+
27
+ def critical?
28
+ @unicorns < @dwarves
29
+ end
30
+
31
+ def warning?
32
+ @unicorns == @dwarves
33
+ end
34
+ end
35
+
36
+ UnicornToDwarfRatio.check!
37
+ ```
38
+
39
+ Please also take a look at features to see what's going on...
40
+
41
+ ## Note on Patches/Pull Requests
42
+
43
+ * Fork the project and run `bundle install` to resolve all development dependencies.
44
+ * Add specs and/or features for it. This is important so I don't break it in a future version unintentionally.
45
+ * Make your feature addition or bug fix.
46
+ * Commit, do not mess with the Rakefile or gemspec.
47
+ (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.)
48
+ * Send me a pull request. Bonus points for topic branches.
49
+
50
+ ## Copyright
51
+
52
+ Copyright (c) 2011 Björn Albers. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,72 @@
1
+ Feature: Plugin Output
2
+
3
+ In order to comply with official nagios plugin development guidelines
4
+ As a sysadmin building my own nagios plugins
5
+ I want to return a nagios compatible plugin output
6
+
7
+ Scenario Outline: CRITICAL, WARNING and OK
8
+ Given a file named "check_foo" with:
9
+ """
10
+ require 'nagiosplugin'
11
+ class Foo < NagiosPlugin::Plugin
12
+ def critical?; <crit> end
13
+ def warning?; <warn> end
14
+ end
15
+ Foo.check!
16
+ """
17
+ When I run `ruby check_foo`
18
+ Then the exit status should be <code>
19
+ And the stdout should contain:
20
+ """
21
+ FOO <status>
22
+
23
+ """
24
+ Examples:
25
+ | crit | warn | code | status |
26
+ | true | true | 2 | CRITICAL |
27
+ | true | false | 2 | CRITICAL |
28
+ | false | true | 1 | WARNING |
29
+ | false | false | 0 | OK |
30
+
31
+ Scenario Outline: UNKNOWN when all status checks return false
32
+ Given a file named "check_bar" with:
33
+ """
34
+ require 'nagiosplugin'
35
+ class Bar < NagiosPlugin::Plugin
36
+ def critical?; false end
37
+ def warning?; false end
38
+ def ok?; <ok> end
39
+ end
40
+ Bar.check!
41
+ """
42
+ When I run `ruby check_bar`
43
+ Then the exit status should be <code>
44
+ # And the stdout should contain exactly:
45
+ And the stdout should contain:
46
+ """
47
+ BAR <status>
48
+
49
+ """
50
+ Examples:
51
+ | ok | code | status |
52
+ | true | 0 | OK |
53
+ | false | 3 | UNKNOWN |
54
+ # | false | 3 | UNKNOWN: All status checks returned false! |
55
+
56
+ Scenario: UNKNOWN when an exception was raised
57
+ Given a file named "check_baz" with:
58
+ """
59
+ require 'nagiosplugin'
60
+ class Baz < NagiosPlugin::Plugin
61
+ def critical?
62
+ raise "OOPS!"
63
+ end
64
+ end
65
+ Baz.check!
66
+ """
67
+ When I run `ruby check_baz`
68
+ Then the exit status should be 3
69
+ And the stdout should contain:
70
+ """
71
+ BAZ UNKNOWN
72
+ """
@@ -0,0 +1 @@
1
+ require "aruba/cucumber"
@@ -0,0 +1,2 @@
1
+ require "nagiosplugin/version"
2
+ require "nagiosplugin/plugin"
@@ -0,0 +1,51 @@
1
+ module NagiosPlugin
2
+ EXIT_CODES = {
3
+ :ok => 0,
4
+ :warning => 1,
5
+ :critical => 2,
6
+ :unknown => 3,
7
+ }
8
+
9
+ class Plugin
10
+ def initialize
11
+ @status = :unknown
12
+ end
13
+
14
+ def self.check!
15
+ plugin = self.new
16
+ plugin.check
17
+ ensure
18
+ puts plugin.message
19
+ exit plugin.code
20
+ end
21
+
22
+ def check
23
+ measure if respond_to?(:measure)
24
+ @status = [:critical, :warning, :ok].select { |s| send("#{s}?") }.first
25
+ raise if @status.nil?
26
+ rescue
27
+ @status = :unknown
28
+ raise
29
+ end
30
+
31
+ def message
32
+ "#{service} #{status}"
33
+ end
34
+
35
+ def service
36
+ self.class.name.upcase
37
+ end
38
+
39
+ def status
40
+ @status.upcase
41
+ end
42
+
43
+ def code
44
+ EXIT_CODES[@status]
45
+ end
46
+
47
+ def ok?
48
+ true
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module NagiosPlugin
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nagiosplugin/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nagiosplugin"
7
+ s.version = NagiosPlugin::VERSION
8
+ s.authors = ["Björn Albers"]
9
+ s.email = ["bjoernalbers@googlemail.com"]
10
+ s.homepage = "https://github.com/bjoernalbers/nagiosplugin"
11
+ s.summary = "#{s.name}-#{s.version}"
12
+ s.description = "Yet another framework for writing Nagios Plugins"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_development_dependency "rake"
20
+ s.add_development_dependency "cucumber"
21
+ s.add_development_dependency "aruba"
22
+ s.add_development_dependency 'guard-cucumber'
23
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nagiosplugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Björn Albers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70231877033500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70231877033500
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ requirement: &70231877022080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70231877022080
36
+ - !ruby/object:Gem::Dependency
37
+ name: aruba
38
+ requirement: &70231877021460 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70231877021460
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-cucumber
49
+ requirement: &70231877020820 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70231877020820
58
+ description: Yet another framework for writing Nagios Plugins
59
+ email:
60
+ - bjoernalbers@googlemail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rvmrc
67
+ - Gemfile
68
+ - Guardfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - features/plugin_output.feature
73
+ - features/support/env.rb
74
+ - lib/nagiosplugin.rb
75
+ - lib/nagiosplugin/plugin.rb
76
+ - lib/nagiosplugin/version.rb
77
+ - nagiosplugin.gemspec
78
+ homepage: https://github.com/bjoernalbers/nagiosplugin
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.10
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: nagiosplugin-0.0.1
102
+ test_files:
103
+ - features/plugin_output.feature
104
+ - features/support/env.rb