ruby-nagios 0.2.2 → 0.3.0
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/bin/check_check +58 -30
- data/bin/nagsrv +14 -3
- data/lib/nagios/external_commands.rb +1 -1
- data/lib/nagios/external_commands/list.rb +1 -2
- data/lib/nagios/status.rb +21 -3
- data/ruby-nagios.gemspec +2 -1
- data/spec/00_configuration_spec.rb +11 -11
- metadata +49 -55
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c2a8bf32d0a1965466db4026791ec2b66d51278
|
4
|
+
data.tar.gz: fd274333c72f6e806aaa90adaf4c523316b535b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bcdf9200cdea805212da1d108d8ccf08281028cba5711738d46d16ca1cdf0504d6153f4b307a9e6ab503a3593799c591a6048dd871df065a33097494e3bb4db
|
7
|
+
data.tar.gz: dd10c49df03ad0df88dabe8995e65b72803c8e3038bc58ab8de4ef1e9365f0fb8f5c765963f9d24fa904ab51a0156fab83914d30ac4a7bb20b80af7630079288
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/bin/check_check
CHANGED
@@ -58,8 +58,8 @@ class Nagios::Status::Model
|
|
58
58
|
# in a soft state transition.
|
59
59
|
end
|
60
60
|
|
61
|
-
#
|
62
|
-
matches << status
|
61
|
+
# Add status but not if the checks have been 'acknowledged'
|
62
|
+
matches << status if status["problem_has_been_acknowledged"] == "0"
|
63
63
|
end
|
64
64
|
end # hosts().each
|
65
65
|
return matches
|
@@ -78,7 +78,7 @@ class Nagios::Status::Model
|
|
78
78
|
|
79
79
|
end # class Nagios::Status::Model
|
80
80
|
|
81
|
-
Settings = Struct.new(:nagios_cfg, :status_path, :service_pattern, :host_pattern, :percent_critical, :percent_warning, :percent_unknown, :show_ok)
|
81
|
+
Settings = Struct.new(:nagios_cfg, :status_path, :service_pattern, :host_pattern, :percent_critical, :percent_warning, :percent_unknown, :show_ok, :quiet, :aggr)
|
82
82
|
def main(args)
|
83
83
|
progname = File.basename($0)
|
84
84
|
settings = Settings.new
|
@@ -120,6 +120,12 @@ def main(args)
|
|
120
120
|
opts.on( "--show-ok", "Show details for checks in OK state too") do
|
121
121
|
settings.show_ok = true
|
122
122
|
end
|
123
|
+
opts.on( "--quiet", "Quiet output") do
|
124
|
+
settings.quiet = true
|
125
|
+
end
|
126
|
+
opts.on( "--aggr", "Aggregate states") do
|
127
|
+
settings.aggr = true
|
128
|
+
end
|
123
129
|
end # OptionParser.new
|
124
130
|
|
125
131
|
opts.parse!(args)
|
@@ -154,30 +160,34 @@ def main(args)
|
|
154
160
|
results[state] << service_status
|
155
161
|
end
|
156
162
|
|
163
|
+
total_results = ["OK", "WARNING", "CRITICAL", "UNKNOWN"].inject(0) {|aggr,state| aggr += results[state].length}
|
157
164
|
# Output a summary line
|
158
165
|
["OK", "WARNING", "CRITICAL", "UNKNOWN"].each do | state|
|
159
166
|
print "#{state}=#{results[state].length} "
|
160
167
|
end
|
161
168
|
print "services=/#{settings.service_pattern}/ "
|
162
169
|
print "hosts=/#{settings.host_pattern}/ "
|
170
|
+
if settings.aggr
|
171
|
+
print "Problems: #{((results["UNKNOWN"].length + results["WARNING"].length + results["CRITICAL"].length).to_f / total_results) * 100}% "
|
172
|
+
end
|
163
173
|
puts
|
164
174
|
|
165
|
-
total_results = ["OK", "WARNING", "CRITICAL", "UNKNOWN"].inject(0) {|aggr,state| aggr += results[state].length}
|
166
|
-
|
167
175
|
# More data output
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
176
|
+
if !settings.quiet
|
177
|
+
["WARNING", "CRITICAL", "UNKNOWN"].each do |state|
|
178
|
+
if results[state] && results[state].size > 0
|
179
|
+
puts "Services in #{state}:"
|
180
|
+
results[state].sort { |a,b| a["host_name"] <=> b["host_name"] }.each do |service|
|
181
|
+
if service["long_plugin_output"] and !service["long_plugin_output"].empty?
|
182
|
+
puts " #{service["host_name"]} => #{service["service_description"]} (#{service["plugin_output"]})"
|
183
|
+
puts " #{service["long_plugin_output"]}"
|
184
|
+
else
|
185
|
+
puts " #{service["host_name"]} => #{service["service_description"]} (#{service["plugin_output"]})"
|
186
|
+
end
|
177
187
|
end
|
178
|
-
end
|
179
|
-
end #
|
180
|
-
end # for
|
188
|
+
end # if results[state]
|
189
|
+
end # for each non-OK state
|
190
|
+
end # for !quiet
|
181
191
|
|
182
192
|
if settings.show_ok and results["OK"].size > 0
|
183
193
|
puts "OK Services:"
|
@@ -188,22 +198,40 @@ def main(args)
|
|
188
198
|
|
189
199
|
exitcode = 0
|
190
200
|
|
191
|
-
if settings.
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
201
|
+
if !settings.aggr
|
202
|
+
if settings.percent_unknown
|
203
|
+
exitcode = 3 if results["UNKNOWN"].length > 0 && (results["UNKNOWN"].length.to_f / total_results) * 100 >= settings.percent_unknown
|
204
|
+
else
|
205
|
+
exitcode = 3 if results["UNKNOWN"].length > 0
|
206
|
+
end
|
196
207
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
208
|
+
if settings.percent_warning
|
209
|
+
exitcode = 1 if results["WARNING"].length > 0 && ((results["WARNING"].length.to_f + results["CRITICAL"].length.to_f) / total_results) * 100 >= settings.percent_warning
|
210
|
+
else
|
211
|
+
exitcode = 1 if results["WARNING"].length > 0
|
212
|
+
end
|
202
213
|
|
203
|
-
|
204
|
-
|
214
|
+
if settings.percent_critical
|
215
|
+
exitcode = 2 if results["CRITICAL"].length > 0 && (results["CRITICAL"].length.to_f / total_results) * 100 >= settings.percent_critical
|
216
|
+
else
|
217
|
+
exitcode = 2 if results["CRITICAL"].length > 0
|
218
|
+
end
|
205
219
|
else
|
206
|
-
|
220
|
+
if settings.percent_unknown
|
221
|
+
exitcode = 3 if results["UNKNOWN"].length > 0 && (results["UNKNOWN"].length.to_f / total_results) * 100 >= settings.percent_unknown
|
222
|
+
else
|
223
|
+
exitcode = 3 if results["UNKNOWN"].length > 0
|
224
|
+
end
|
225
|
+
if settings.percent_warning
|
226
|
+
exitcode = 1 if ((results["UNKNOWN"].length + results["WARNING"].length + results["CRITICAL"].length).to_f / total_results) * 100 >= settings.percent_warning
|
227
|
+
else
|
228
|
+
exitcode = 1 if results["WARNING"].length > 0
|
229
|
+
end
|
230
|
+
if settings.percent_critical
|
231
|
+
exitcode = 2 if ((results["UNKNOWN"].length + results["WARNING"].length + results["CRITICAL"].length).to_f / total_results) * 100 >= settings.percent_critical
|
232
|
+
else
|
233
|
+
exitcode = 2 if results["CRITICAL"].length > 0
|
234
|
+
end
|
207
235
|
end
|
208
236
|
|
209
237
|
return exitcode
|
data/bin/nagsrv
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
# Force checks for selected services
|
45
45
|
#
|
46
46
|
# --acknowledge
|
47
|
-
#
|
47
|
+
# Acknowledge services without sending notifies
|
48
48
|
#
|
49
49
|
# --delete-comments
|
50
50
|
# Delete the comments for selected services
|
@@ -67,6 +67,8 @@ notify = nil
|
|
67
67
|
action = nil
|
68
68
|
options = nil
|
69
69
|
current_state = nil
|
70
|
+
json = nil
|
71
|
+
details = nil
|
70
72
|
|
71
73
|
OptionParser.new do |opts|
|
72
74
|
opts.separator "General Options"
|
@@ -84,6 +86,15 @@ OptionParser.new do |opts|
|
|
84
86
|
listservices = true
|
85
87
|
end
|
86
88
|
|
89
|
+
opts.on("--json", "Returns complete json data instead of service names only") do
|
90
|
+
json = true
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.on("--details", "Include additional serivce details in output") do
|
94
|
+
details = true
|
95
|
+
raise("Cannot use --details wirh --json") unless json.nil?
|
96
|
+
end
|
97
|
+
|
87
98
|
opts.separator ""
|
88
99
|
opts.separator "Service and Host Selectors"
|
89
100
|
|
@@ -140,7 +151,7 @@ OptionParser.new do |opts|
|
|
140
151
|
action = "[${tstamp}] SCHEDULE_FORCED_SVC_CHECK;${host};${service};${tstamp}"
|
141
152
|
end
|
142
153
|
|
143
|
-
opts.on("--
|
154
|
+
opts.on("--acknowledge", "Acknowledge services without sending notifies") do
|
144
155
|
action = "[${tstamp}] ACKNOWLEDGE_SVC_PROBLEM;${host};${service};1;0;1;#{ENV['USER']};Acknowledged from CLI"
|
145
156
|
end
|
146
157
|
|
@@ -170,7 +181,7 @@ if listservices && action == nil
|
|
170
181
|
action = "${service}"
|
171
182
|
end
|
172
183
|
|
173
|
-
options = {:forhost => forhost, :notifyenabled => notify, :action => action, :withservice => withservice, :current_state => current_state}
|
184
|
+
options = {:forhost => forhost, :notifyenabled => notify, :action => action, :withservice => withservice, :current_state => current_state, :json => json, :details => details}
|
174
185
|
services = nagios.find_services(options)
|
175
186
|
|
176
187
|
puts services.join("\n")
|
@@ -65,7 +65,7 @@ module Nagios
|
|
65
65
|
:hostgroup_name, :servicegroup_name, :file_name, :delete,
|
66
66
|
:status_code, :plugin_output, :return_code, :start_time,
|
67
67
|
:end_time, :fixed, :trigger_id, :duration, :check_time,
|
68
|
-
:
|
68
|
+
:service_description, :start_time, :options, :notification_number
|
69
69
|
|
70
70
|
# Get private binding to use with ERB bindings.
|
71
71
|
def get_binding
|
@@ -38,7 +38,6 @@ module Nagios
|
|
38
38
|
:CHANGE_GLOBAL_HOST_EVENT_HANDLER => %w{event_handler_command},
|
39
39
|
:CHANGE_GLOBAL_SVC_EVENT_HANDLER => %w{event_handler_command},
|
40
40
|
:CHANGE_HOST_CHECK_COMMAND => %w{host_name check_command},
|
41
|
-
:CHANGE_HOST_CHECK_TIMEPERIOD => %w{host_name check_timeperod},
|
42
41
|
:CHANGE_HOST_CHECK_TIMEPERIOD => %w{host_name timeperiod},
|
43
42
|
:CHANGE_HOST_EVENT_HANDLER => %w{host_name event_handler_command},
|
44
43
|
:CHANGE_HOST_MODATTR => %w{host_name value},
|
@@ -158,7 +157,7 @@ module Nagios
|
|
158
157
|
:SCHEDULE_SERVICEGROUP_HOST_DOWNTIME => %w{servicegroup_name start_time end_time fixed trigger_id duration author comment},
|
159
158
|
:SCHEDULE_SERVICEGROUP_SVC_DOWNTIME => %w{servicegroup_name start_time end_time fixed trigger_id duration author comment},
|
160
159
|
:SCHEDULE_SVC_CHECK => %w{host_name service_description check_time},
|
161
|
-
:SCHEDULE_SVC_DOWNTIME => %w{host_name
|
160
|
+
:SCHEDULE_SVC_DOWNTIME => %w{host_name service_description start_time end_time fixed trigger_id duration author comment},
|
162
161
|
:SEND_CUSTOM_HOST_NOTIFICATION => %w{host_name options author comment},
|
163
162
|
:SEND_CUSTOM_SVC_NOTIFICATION => %w{host_name service_description options author comment},
|
164
163
|
:SET_HOST_NOTIFICATION_NUMBER => %w{host_name notification_number},
|
data/lib/nagios/status.rb
CHANGED
@@ -2,10 +2,9 @@ module Nagios
|
|
2
2
|
class Status
|
3
3
|
attr_reader :status, :path
|
4
4
|
|
5
|
-
|
6
5
|
def initialize(statusfile=nil)
|
7
6
|
if statusfile
|
8
|
-
raise ArgumentError, "Statusfile file name must be provided" unless statusfile
|
7
|
+
raise ArgumentError, "Statusfile file name must be provided" unless statusfile
|
9
8
|
raise RuntimeError, "Statusfile #{statusfile} does not exist" unless File.exist? statusfile
|
10
9
|
raise RuntimeError, "Statusfile #{statusfile} is not readable" unless File.readable? statusfile
|
11
10
|
@path = statusfile
|
@@ -90,6 +89,8 @@ module Nagios
|
|
90
89
|
acknowledged = options.fetch(:acknowledged, nil)
|
91
90
|
passive = options.fetch(:passive, nil)
|
92
91
|
current_state = options.fetch(:current_state, nil)
|
92
|
+
json = options.fetch(:json, false)
|
93
|
+
details = options.fetch(:details, false)
|
93
94
|
|
94
95
|
services = []
|
95
96
|
searchquery = []
|
@@ -126,7 +127,24 @@ module Nagios
|
|
126
127
|
services << parse_command_template(action, host_name, service_description, service_description)
|
127
128
|
end
|
128
129
|
|
129
|
-
|
130
|
+
if json
|
131
|
+
[ "[", svcs.join(", \n").gsub("=>", ":"), "]" ]
|
132
|
+
elsif details
|
133
|
+
space = ' '*100
|
134
|
+
delim = ' '
|
135
|
+
state = ['OK', 'Warning', 'Critical', 'Unknown']
|
136
|
+
details = Array.new
|
137
|
+
svcs.each do |s|
|
138
|
+
details << (s['host_name'] + space)[0, 25] + delim \
|
139
|
+
+ (s['service_description'] + space)[0,35] + delim \
|
140
|
+
+ (state[s['current_state'].to_i].to_s + space)[0,8] + delim \
|
141
|
+
+ (s['plugin_output'] + space)[0,120]
|
142
|
+
end
|
143
|
+
details
|
144
|
+
|
145
|
+
else
|
146
|
+
services.uniq.sort
|
147
|
+
end
|
130
148
|
end
|
131
149
|
|
132
150
|
private
|
data/ruby-nagios.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'ruby-nagios'
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.3.0"
|
4
4
|
s.author = 'R.I.Pienaar'
|
5
5
|
s.email = 'rip@devco.net'
|
6
6
|
s.homepage = 'http://devco.net/'
|
@@ -12,4 +12,5 @@ spec = Gem::Specification.new do |s|
|
|
12
12
|
s.require_paths = ['lib']
|
13
13
|
s.has_rdoc = false
|
14
14
|
s.add_development_dependency('rake')
|
15
|
+
s.add_development_dependency "rspec", "~> 3"
|
15
16
|
end
|
@@ -9,10 +9,10 @@ describe "Configuration" do
|
|
9
9
|
|
10
10
|
context "nagios.cfg" do
|
11
11
|
|
12
|
-
it { File.
|
12
|
+
it { expect(File).to exist @cfg.path }
|
13
13
|
|
14
14
|
it "should be parseable" do
|
15
|
-
|
15
|
+
expect { @cfg.parse }.not_to raise_error
|
16
16
|
end
|
17
17
|
|
18
18
|
context "parsing nagios.cfg file" do
|
@@ -20,11 +20,11 @@ describe "Configuration" do
|
|
20
20
|
before { @cfg.parse }
|
21
21
|
|
22
22
|
it "should have PATH to objects file" do
|
23
|
-
@cfg.object_cache_file.
|
23
|
+
expect(@cfg.object_cache_file).to be_a_kind_of String
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should have PATH to status file" do
|
27
|
-
@cfg.status_file.
|
27
|
+
expect(@cfg.status_file).to be_a_kind_of String
|
28
28
|
end
|
29
29
|
|
30
30
|
end # parsing nagios.cfg file
|
@@ -38,24 +38,24 @@ describe "Configuration" do
|
|
38
38
|
context "OOP style" do
|
39
39
|
subject { Nagios::Status.new( ::TEST[:status_file] || @cfg.status_file ) }
|
40
40
|
|
41
|
-
it { File.
|
41
|
+
it { expect(File).to exist( subject.path ) }
|
42
42
|
|
43
43
|
it "should be parseable" do
|
44
|
-
|
44
|
+
expect { subject.parse }.not_to raise_error
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
context "using parameter for parse method" do
|
49
49
|
subject { Nagios::Status.new() }
|
50
50
|
|
51
|
-
it { File.
|
51
|
+
it { expect(File).to exist( (::TEST[:status_file] || @cfg.status_file) ) }
|
52
52
|
|
53
53
|
it "should be parseable" do
|
54
|
-
|
54
|
+
expect { subject.parse(::TEST[:status_file] || @cfg.status_file) }.not_to raise_error
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should fail without a filename" do
|
58
|
-
|
58
|
+
expect { subject.parse() }.to raise_error
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
@@ -67,10 +67,10 @@ describe "Configuration" do
|
|
67
67
|
|
68
68
|
subject { Nagios::Objects.new( ::TEST[:object_cache_file] || @cfg.object_cache_file) }
|
69
69
|
|
70
|
-
it { File.
|
70
|
+
it { expect(File).to exist subject.path }
|
71
71
|
|
72
72
|
it "should be parseable" do
|
73
|
-
|
73
|
+
expect { subject.parse }.not_to raise_error
|
74
74
|
end
|
75
75
|
end # Nagios::Objects
|
76
76
|
|
metadata
CHANGED
@@ -1,49 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nagios
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 2
|
10
|
-
version: 0.2.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- R.I.Pienaar
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
23
21
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
33
34
|
type: :development
|
34
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3'
|
35
41
|
description: Manage alerts, checks and acks in bulk
|
36
42
|
email: rip@devco.net
|
37
|
-
executables:
|
43
|
+
executables:
|
38
44
|
- check_check
|
39
45
|
- nagsrv
|
40
46
|
extensions: []
|
41
|
-
|
42
47
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
48
|
+
files:
|
45
49
|
- .gitignore
|
50
|
+
- .travis.yml
|
46
51
|
- COPYING
|
52
|
+
- Gemfile
|
47
53
|
- README.md
|
48
54
|
- Rakefile
|
49
55
|
- bin/check_check
|
@@ -65,39 +71,27 @@ files:
|
|
65
71
|
- test/data/nagios.cfg
|
66
72
|
- test/data/objects.cache
|
67
73
|
- test/data/status.dat
|
68
|
-
has_rdoc: true
|
69
74
|
homepage: http://devco.net/
|
70
75
|
licenses: []
|
71
|
-
|
76
|
+
metadata: {}
|
72
77
|
post_install_message:
|
73
78
|
rdoc_options: []
|
74
|
-
|
75
|
-
require_paths:
|
79
|
+
require_paths:
|
76
80
|
- lib
|
77
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
none: false
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
hash: 3
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
version: "0"
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
95
91
|
requirements: []
|
96
|
-
|
97
92
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.14
|
99
94
|
signing_key:
|
100
|
-
specification_version:
|
95
|
+
specification_version: 4
|
101
96
|
summary: Ruby library for managing Nagios
|
102
97
|
test_files: []
|
103
|
-
|