nagioscheck 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/nagioscheck/version.rb +3 -0
- data/lib/nagioscheck.rb +146 -0
- data/nagioscheck.gemspec +23 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Aaron Brown
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Nagioscheck
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'nagioscheck'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install nagioscheck
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/nagioscheck.rb
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require "nagioscheck/version"
|
|
2
|
+
|
|
3
|
+
module NagiosCheck
|
|
4
|
+
class Check
|
|
5
|
+
OK,WARN,CRIT,UNKNOWN = 0,1,2,3
|
|
6
|
+
OK_STR = "OK"
|
|
7
|
+
WARN_STR = "WARNING"
|
|
8
|
+
CRIT_STR = "CRITICAL"
|
|
9
|
+
UNKNOWN_STR = "UNKNOWN"
|
|
10
|
+
|
|
11
|
+
attr_reader :exit_code
|
|
12
|
+
attr_writer :exit_str, :perfdata
|
|
13
|
+
attr_accessor :outputdata
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
@exit_code = OK
|
|
17
|
+
@exit_str = ""
|
|
18
|
+
@perfdata = nil
|
|
19
|
+
@outputdata = ""
|
|
20
|
+
@perfdata_objs = []
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def exit
|
|
24
|
+
puts exit_str
|
|
25
|
+
return @exit_code
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def exit!
|
|
29
|
+
Process.exit exit
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def exit_str
|
|
33
|
+
str = case @exit_code
|
|
34
|
+
when OK then OK_STR
|
|
35
|
+
when WARN then WARN_STR
|
|
36
|
+
when CRIT then CRIT_STR
|
|
37
|
+
else UNKNOWN_STR
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
str += " - #{@outputdata}" unless @outputdata == ""
|
|
41
|
+
str += perfdata
|
|
42
|
+
return str
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def perfdata
|
|
46
|
+
str = ""
|
|
47
|
+
if @perfdata_objs && @perfdata_objs.size > 0
|
|
48
|
+
str = " |"
|
|
49
|
+
@perfdata_objs.each do |p|
|
|
50
|
+
str += " '#{p.label}'=#{p.value}#{p.uom}"
|
|
51
|
+
str += ";#{p.warn}" if p.warn
|
|
52
|
+
str += ";#{p.crit}" if p.crit
|
|
53
|
+
str += ";#{p.min}" if p.min
|
|
54
|
+
str += ";#{p.max}" if p.max
|
|
55
|
+
end
|
|
56
|
+
elsif @perfdata && @perfdata != ""
|
|
57
|
+
str = " |" + @perfdata
|
|
58
|
+
end
|
|
59
|
+
return str
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# set the exit code based on the warn_range and crit_range
|
|
63
|
+
def set_exit_code ( value, warn_range, crit_range )
|
|
64
|
+
result = OK
|
|
65
|
+
if value.is_a?(Numeric) || value =~ /^\d+$/
|
|
66
|
+
result = WARN if warn_range && range_match(value.to_i, warn_range)
|
|
67
|
+
result = CRIT if crit_range && range_match(value.to_i, crit_range)
|
|
68
|
+
else
|
|
69
|
+
result = WARN if value == warn_range
|
|
70
|
+
result = CRIT if value == crit_range
|
|
71
|
+
end
|
|
72
|
+
self.exit_code = result
|
|
73
|
+
return result
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# only sets the exit code if it is worse than the current exit code
|
|
77
|
+
def exit_code=(exit_code)
|
|
78
|
+
if exit_code > @exit_code
|
|
79
|
+
if exit_code == UNKNOWN && @exit_code != OK
|
|
80
|
+
# WARN and CRIT are higher priority than UNKNOWN
|
|
81
|
+
return
|
|
82
|
+
end
|
|
83
|
+
@exit_code = exit_code
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def add_perfdata ( perfdata_obj )
|
|
88
|
+
perfdata_obj = PerfData.new(perfdata_obj) if perfdata_obj.is_a? Hash
|
|
89
|
+
perfdata_obj.warn = nil if perfdata_obj.warn == "nil"
|
|
90
|
+
perfdata_obj.crit = nil if perfdata_obj.crit == "nil"
|
|
91
|
+
@perfdata_objs << perfdata_obj
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
protected
|
|
95
|
+
def is_range ( value )
|
|
96
|
+
if value =~ /^(\d+)$/ ||
|
|
97
|
+
value =~ /^(\d+):[~]?$/ ||
|
|
98
|
+
value =~ /^~:(\d+)$/ ||
|
|
99
|
+
value =~ /^(\d+):(\d+)$/
|
|
100
|
+
return true
|
|
101
|
+
end
|
|
102
|
+
return false
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# returns true if value is within range
|
|
106
|
+
#10 < 0 or > 10, (outside the range of {0 .. 10})
|
|
107
|
+
#10: < 10, (outside {10 .. ∞})
|
|
108
|
+
#~:10 > 10, (outside the range of {-∞ .. 10})
|
|
109
|
+
# 10:20 < 10 or > 20, (outside the range of {10 .. 20})
|
|
110
|
+
# @10:20 ≥ 10 and ≤ 20, (inside the range of {10 .. 20})
|
|
111
|
+
def range_match ( value, range )
|
|
112
|
+
return (value < 0 || value > range) if range.class != String
|
|
113
|
+
|
|
114
|
+
result = false
|
|
115
|
+
negate = (range =~ /^@(.*)/)
|
|
116
|
+
range = $1 if negate
|
|
117
|
+
result = case range
|
|
118
|
+
when /^(\d+)$/ then (value < 0 || value > $1.to_i)
|
|
119
|
+
# untested from here to the end of the function
|
|
120
|
+
when /^(\d+):[~]?$/ then (value < $1.to_i)
|
|
121
|
+
when /^~:(\d+)$/ then (value > $1.to_i)
|
|
122
|
+
when /^(\d+):(\d+)$/ then (value > $1.to_i && value < $2.to_i)
|
|
123
|
+
when "nil" then false
|
|
124
|
+
end
|
|
125
|
+
return negate ? !result : result
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
class PerfData
|
|
130
|
+
attr_accessor :label, :value, :uom, :warn, :crit, :min, :max
|
|
131
|
+
|
|
132
|
+
def initialize (h={})
|
|
133
|
+
@label, @value, @uom, @warn, @crit, @min, @max = nil, nil,nil,nil,nil,nil,nil
|
|
134
|
+
unless h.empty?
|
|
135
|
+
# weak sauce, but it gets the job done
|
|
136
|
+
@label = h["label"] if h["label"]
|
|
137
|
+
@value = h["value"] if h["value"]
|
|
138
|
+
@uom = h["uom"] if h["uom"]
|
|
139
|
+
@warn = h["warn"] if h["warn"]
|
|
140
|
+
@crit = h["crit"] if h["crit"]
|
|
141
|
+
@min = h["min"] if h["min"]
|
|
142
|
+
@max = h["max"] if h["max"]
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
data/nagioscheck.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'nagioscheck/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "nagioscheck"
|
|
8
|
+
spec.version = NagiosCheck::VERSION
|
|
9
|
+
spec.authors = ["Aaron Brown"]
|
|
10
|
+
spec.email = ["aaron@9minutesnooze.com"]
|
|
11
|
+
spec.description = %q{Makes writing Nagios checks easier}
|
|
12
|
+
spec.summary = %q{Makes writing Nagios checks easier}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nagioscheck
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Aaron Brown
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: bundler
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.3'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.3'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rake
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
description: Makes writing Nagios checks easier
|
|
47
|
+
email:
|
|
48
|
+
- aaron@9minutesnooze.com
|
|
49
|
+
executables: []
|
|
50
|
+
extensions: []
|
|
51
|
+
extra_rdoc_files: []
|
|
52
|
+
files:
|
|
53
|
+
- .gitignore
|
|
54
|
+
- Gemfile
|
|
55
|
+
- LICENSE.txt
|
|
56
|
+
- README.md
|
|
57
|
+
- Rakefile
|
|
58
|
+
- lib/nagioscheck.rb
|
|
59
|
+
- lib/nagioscheck/version.rb
|
|
60
|
+
- nagioscheck.gemspec
|
|
61
|
+
homepage: ''
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
post_install_message:
|
|
65
|
+
rdoc_options: []
|
|
66
|
+
require_paths:
|
|
67
|
+
- lib
|
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
|
+
none: false
|
|
70
|
+
requirements:
|
|
71
|
+
- - ! '>='
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ! '>='
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
requirements: []
|
|
81
|
+
rubyforge_project:
|
|
82
|
+
rubygems_version: 1.8.25
|
|
83
|
+
signing_key:
|
|
84
|
+
specification_version: 3
|
|
85
|
+
summary: Makes writing Nagios checks easier
|
|
86
|
+
test_files: []
|