nagios-manage 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/check_check.rb +29 -3
  2. metadata +5 -4
@@ -80,6 +80,7 @@ Settings = Struct.new(:nagios_cfg, :status_path, :service_pattern, :host_pattern
80
80
  def main(args)
81
81
  progname = File.basename($0)
82
82
  settings = Settings.new
83
+ thresholds = Hash.new { |h,k| h[k] = 0 }
83
84
  settings.nagios_cfg = "/etc/nagios3/nagios.cfg" # debian/ubuntu default
84
85
 
85
86
  opts = OptionParser.new do |opts|
@@ -99,6 +100,24 @@ def main(args)
99
100
  "Aggregate only services from hosts matching the given pattern") do |val|
100
101
  settings.host_pattern = val
101
102
  end
103
+
104
+ thresholds["WARNING"] = 1
105
+ opts.on("-w NUMBER", "--warning NUMBER",
106
+ "Exit with a warning state if more than x checks are in warning state (defaults to 1, 0 disables the check)") do |val|
107
+ thresholds["WARNING"] = val.to_i
108
+ end
109
+
110
+ thresholds["CRITICAL"] = 1
111
+ opts.on("-c NUMBER", "--critical NUMBER",
112
+ "Exit with a critical state if more than x checks are in critical state (defaults to 1, 0 disables the check)") do |val|
113
+ thresholds["CRITICAL"] = val.to_i
114
+ end
115
+
116
+ thresholds["UNKNOWN"] = 1
117
+ opts.on("-u NUMBER", "--unknown NUMBER",
118
+ "Exit with a unknown state if more than x checks are in unknown state (defaults to 1, 0 disables the check)") do |val|
119
+ thresholds["UNKNOWN"] = val.to_i
120
+ end
102
121
  end # OptionParser.new
103
122
 
104
123
  opts.parse!(args)
@@ -136,6 +155,9 @@ def main(args)
136
155
  # Output a summary line
137
156
  ["OK", "WARNING", "CRITICAL", "UNKNOWN"].each do | state|
138
157
  print "#{state}=#{results[state].length} "
158
+ if ["WARNING", "CRITICAL", "UNKNOWN"].include?(state)
159
+ print"(threshold: #{thresholds[state]}) "
160
+ end
139
161
  end
140
162
  print "services=/#{settings.service_pattern}/ "
141
163
  print "hosts=/#{settings.host_pattern}/ "
@@ -143,7 +165,7 @@ def main(args)
143
165
 
144
166
  # More data output
145
167
  ["WARNING", "CRITICAL", "UNKNOWN"].each do |state|
146
- if results[state] && results[state].size > 0
168
+ if results[state] && results[state].size > 0 and thresholds[state] > 0
147
169
  puts "Services in #{state}:"
148
170
  results[state].sort { |a,b| a["host_name"] <=> b["host_name"] }.each do |service|
149
171
  puts " #{service["host_name"]} => #{service["service_description"]}"
@@ -153,11 +175,15 @@ def main(args)
153
175
 
154
176
  exitcode = 0
155
177
 
156
- if results["WARNING"].length > 0
178
+ if results["UNKNOWN"].length >= thresholds["UNKNOWN"] and thresholds["UNKNOWN"] > 0
179
+ exitcode = 3
180
+ end
181
+
182
+ if results["WARNING"].length >= thresholds["WARNING"] and thresholds["WARNING"] > 0
157
183
  exitcode = 1
158
184
  end
159
185
 
160
- if results["CRITICAL"].length > 0
186
+ if results["CRITICAL"].length >= thresholds["CRITICAL"] and thresholds["CRITICAL"] > 0
161
187
  exitcode = 2
162
188
  end
163
189
  return exitcode
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios-manage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-08 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Silence alerts, aggregate existing checks, etc.
15
15
  email: rip@devco.net, jls@semicomplete.com
@@ -20,8 +20,8 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/nagios/status.rb
23
- - bin/nagsrv.rb
24
23
  - bin/check_check.rb
24
+ - bin/nagsrv.rb
25
25
  homepage: http://code.google.com/p/ruby-nagios/
26
26
  licenses: []
27
27
  post_install_message:
@@ -43,8 +43,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  requirements: []
45
45
  rubyforge_project:
46
- rubygems_version: 1.8.10
46
+ rubygems_version: 1.8.24
47
47
  signing_key:
48
48
  specification_version: 3
49
49
  summary: nagios-manage - a ruby tool for managing your nagios instance
50
50
  test_files: []
51
+ has_rdoc: