ruby-nagios 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/check_check CHANGED
@@ -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, :down_min_percent)
81
+ Settings = Struct.new(:nagios_cfg, :status_path, :service_pattern, :host_pattern, :percent_critical, :percent_warning, :percent_unknown, :show_ok)
82
82
  def main(args)
83
83
  progname = File.basename($0)
84
84
  settings = Settings.new
@@ -102,9 +102,23 @@ def main(args)
102
102
  settings.host_pattern = val
103
103
  end
104
104
 
105
- opts.on("-p NUM", "--percent NUM",
106
- "Only alert if this percentage of the cluster is down") do |val|
107
- settings.down_min_percent = Float(val)
105
+ opts.on( "--percent-warning NUM",
106
+ "Only alert if this percentage of the cluster is in warning state") do |val|
107
+ settings.percent_warning = Float(val)
108
+ end
109
+
110
+ opts.on( "--percent-critical NUM",
111
+ "Only alert if this percentage of the cluster is in critical state") do |val|
112
+ settings.percent_critical = Float(val)
113
+ end
114
+
115
+ opts.on( "--percent-unknown NUM",
116
+ "Only alert if this percentage of the cluster is in unknown state") do |val|
117
+ settings.percent_unknown = Float(val)
118
+ end
119
+
120
+ opts.on( "--show-ok", "Show details for checks in OK state too") do
121
+ settings.show_ok = true
108
122
  end
109
123
  end # OptionParser.new
110
124
 
@@ -148,44 +162,50 @@ def main(args)
148
162
  print "hosts=/#{settings.host_pattern}/ "
149
163
  puts
150
164
 
165
+ total_results = ["OK", "WARNING", "CRITICAL", "UNKNOWN"].inject(0) {|aggr,state| aggr += results[state].length}
166
+
151
167
  # More data output
152
- total_results = 0.0
153
168
  ["WARNING", "CRITICAL", "UNKNOWN"].each do |state|
154
169
  if results[state] && results[state].size > 0
155
170
  puts "Services in #{state}:"
156
171
  results[state].sort { |a,b| a["host_name"] <=> b["host_name"] }.each do |service|
157
- total_results += 1
158
- puts " #{service["host_name"]} => #{service["service_description"]} (#{service["plugin_output"]})"
172
+ if service["long_plugin_output"] and !service["long_plugin_output"].empty?
173
+ puts " #{service["host_name"]} => #{service["service_description"]} (#{service["plugin_output"]})"
174
+ puts " #{service["long_plugin_output"]}"
175
+ else
176
+ puts " #{service["host_name"]} => #{service["service_description"]} (#{service["plugin_output"]})"
177
+ end
159
178
  end
160
179
  end # if results[state]
161
180
  end # for each non-OK state
162
181
 
163
- # If everything is OK, still print detailed output for confirmation
164
- if total_results == 0 and results["OK"].size > 0
165
- puts "OK Services:"
166
- results["OK"].sort { |a,b| a["host_name"] <=> b["host_name"] }.each do |service|
167
- puts " #{service["host_name"]} => #{service["service_description"]}"
168
- end
182
+ if settings.show_ok and results["OK"].size > 0
183
+ puts "OK Services:"
184
+ results["OK"].sort { |a,b| a["host_name"] <=> b["host_name"] }.each do |service|
185
+ puts " #{service["host_name"]} => #{service["service_description"]}"
186
+ end
169
187
  end
170
188
 
171
189
  exitcode = 0
172
190
 
173
- if settings.down_min_percent
174
- if results["WARNING"].length > 0 && (results["WARNING"].length / total_results) * 100 >= settings.down_min_percent
175
- exitcode = 1
176
- end
177
- if results["CRITICAL"].length > 0 && (results["CRITICAL"].length / total_results) * 100 >= settings.down_min_percent
178
- exitcode = 2
179
- end
191
+ if settings.percent_unknown
192
+ exitcode = 3 if results["UNKNOWN"].length > 0 && (results["UNKNOWN"].length.to_f / total_results) * 100 >= settings.percent_unknown
180
193
  else
181
- if results["WARNING"].length > 0
182
- exitcode = 1
183
- end
194
+ exitcode = 3 if results["UNKNOWN"].length > 0
195
+ end
184
196
 
185
- if results["CRITICAL"].length > 0
186
- exitcode = 2
187
- end
197
+ if settings.percent_warning
198
+ exitcode = 1 if results["WARNING"].length > 0 && ((results["WARNING"].length.to_f + results["CRITICAL"].length.to_f) / total_results) * 100 >= settings.percent_warning
199
+ else
200
+ exitcode = 1 if results["WARNING"].length > 0
188
201
  end
202
+
203
+ if settings.percent_critical
204
+ exitcode = 2 if results["CRITICAL"].length > 0 && (results["CRITICAL"].length.to_f / total_results) * 100 >= settings.percent_critical
205
+ else
206
+ exitcode = 2 if results["CRITICAL"].length > 0
207
+ end
208
+
189
209
  return exitcode
190
210
  end
191
211
 
data/lib/nagios/config.rb CHANGED
@@ -88,7 +88,7 @@ first one will be used. For example, Debian can have both Nagios 2 and
88
88
 
89
89
  @configuration[key] = val
90
90
  instance_variable_set("@#{key}", val)
91
- instance_eval val =~ /^[\d\.-]+/ ?
91
+ instance_eval val =~ /^[\d\.-]+$/ ?
92
92
  "def #{key}; return #{val}; end" :
93
93
  "def #{key}; return %Q{#{val}}; end"
94
94
  end
@@ -21,7 +21,7 @@ module Nagios
21
21
  class ExternalCommands
22
22
 
23
23
  require 'erb'
24
- require_relative 'external_commands/list'
24
+ require 'nagios/external_commands/list'
25
25
 
26
26
  # Constructor for the external command write class.
27
27
  #
@@ -132,11 +132,11 @@ module Nagios
132
132
  end
133
133
  end
134
134
 
135
- output << { data: params, result: messages.empty? , messages: messages }
135
+ output << { :data => params, :result => messages.empty? , :messages => messages }
136
136
  result &&= messages.empty?
137
137
  end # data.each
138
138
 
139
- { result: result, data: output }
139
+ { :result => result, :data => output }
140
140
  end # def write
141
141
  end
142
142
  end
@@ -16,170 +16,170 @@ module Nagios
16
16
  #
17
17
  # == Example
18
18
  #
19
- # PROCESS_SERVICE_CHECK_RESULT: %w{host_name service_description return_code plugin_output}
19
+ # :PROCESS_SERVICE_CHECK_RESULT => %w{host_name service_description return_code plugin_output}
20
20
  #
21
21
  # converted to template on print:
22
22
  #
23
23
  # [timestamp] PROCESS_SERVICE_CHECK_RESULT;<%= host_name %>;<%= service_description %>;<%= return_code %>;<%= plugin_output %>\n
24
24
  #
25
25
  ACTIONS = {
26
- ACKNOWLEDGE_HOST_PROBLEM: %w{host_name sticky notify persistent author comment},
27
- ACKNOWLEDGE_SVC_PROBLEM: %w{host_name service_description sticky notify persistent author comment},
28
- ADD_HOST_COMMENT: %w{host_name persistent author comment},
29
- ADD_SVC_COMMENT: %w{host_name service_description persistent author comment},
30
- CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD: %w{contact_name notification_timeperiod},
31
- CHANGE_CONTACT_MODATTR: %w{contact_name value},
32
- CHANGE_CONTACT_MODHATTR: %w{contact_name value},
33
- CHANGE_CONTACT_MODSATTR: %w{contact_name value},
34
- CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD: %w{contact_name notification_timeperiod},
35
- CHANGE_CUSTOM_CONTACT_VAR: %w{contact_name varname varvalue},
36
- CHANGE_CUSTOM_HOST_VAR: %w{host_name varname varvalue},
37
- CHANGE_CUSTOM_SVC_VAR: %w{host_name service_description varname varvalue},
38
- CHANGE_GLOBAL_HOST_EVENT_HANDLER: %w{event_handler_command},
39
- CHANGE_GLOBAL_SVC_EVENT_HANDLER: %w{event_handler_command},
40
- CHANGE_HOST_CHECK_COMMAND: %w{host_name check_command},
41
- CHANGE_HOST_CHECK_TIMEPERIOD: %w{host_name check_timeperod},
42
- CHANGE_HOST_CHECK_TIMEPERIOD: %w{host_name timeperiod},
43
- CHANGE_HOST_EVENT_HANDLER: %w{host_name event_handler_command},
44
- CHANGE_HOST_MODATTR: %w{host_name value},
45
- CHANGE_MAX_HOST_CHECK_ATTEMPTS: %w{host_name check_attempts},
46
- CHANGE_MAX_SVC_CHECK_ATTEMPTS: %w{host_name service_description check_attempts},
47
- CHANGE_NORMAL_HOST_CHECK_INTERVAL: %w{host_name check_interval},
48
- CHANGE_NORMAL_SVC_CHECK_INTERVAL: %w{host_name service_description check_interval},
49
- CHANGE_RETRY_HOST_CHECK_INTERVAL: %w{host_name service_description check_interval},
50
- CHANGE_RETRY_SVC_CHECK_INTERVAL: %w{host_name service_description check_interval},
51
- CHANGE_SVC_CHECK_COMMAND: %w{host_name service_description check_command},
52
- CHANGE_SVC_CHECK_TIMEPERIOD: %w{host_name service_description check_timeperiod},
53
- CHANGE_SVC_EVENT_HANDLER: %w{host_name service_description event_handler_command},
54
- CHANGE_SVC_MODATTR: %w{host_name service_description value},
55
- CHANGE_SVC_NOTIFICATION_TIMEPERIOD: %w{host_name service_description notification_timeperiod},
56
- DELAY_HOST_NOTIFICATION: %w{host_name notification_time},
57
- DELAY_SVC_NOTIFICATION: %w{host_name service_description notification_time},
58
- DEL_ALL_HOST_COMMENTS: %w{host_name},
59
- DEL_ALL_SVC_COMMENTS: %w{host_name service_description},
60
- DEL_HOST_COMMENT: %w{comment_id},
61
- DEL_HOST_DOWNTIME: %w{downtime_id},
62
- DEL_SVC_COMMENT: %w{comment_id},
63
- DEL_SVC_DOWNTIME: %w{downtime_id},
64
- DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST: %w{host_name},
65
- DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS: %w{contactgroup_name},
66
- DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS: %w{contactgroup_name},
67
- DISABLE_CONTACT_HOST_NOTIFICATIONS: %w{contact_name},
68
- DISABLE_CONTACT_SVC_NOTIFICATIONS: %w{contact_name},
69
- DISABLE_EVENT_HANDLERS: [],
70
- DISABLE_FAILURE_PREDICTION: [],
71
- DISABLE_FLAP_DETECTION: [],
72
- DISABLE_HOSTGROUP_HOST_CHECKS: %w{hostgroup_name},
73
- DISABLE_HOSTGROUP_HOST_NOTIFICATIONS: %w{hostgroup_name},
74
- DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS: %w{hostgroup_name},
75
- DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS: %w{hostgroup_name},
76
- DISABLE_HOSTGROUP_SVC_CHECKS: %w{hostgroup_name},
77
- DISABLE_HOSTGROUP_SVC_NOTIFICATIONS: %w{hostgroup_name},
78
- DISABLE_HOST_AND_CHILD_NOTIFICATIONS: %w{host_name},
79
- DISABLE_HOST_CHECK: %w{host_name},
80
- DISABLE_HOST_EVENT_HANDLER: %w{host_name},
81
- DISABLE_HOST_FLAP_DETECTION: %w{host_name},
82
- DISABLE_HOST_FRESHNESS_CHECKS: [],
83
- DISABLE_HOST_NOTIFICATIONS: %w{host_name},
84
- DISABLE_HOST_SVC_CHECKS: %w{host_name},
85
- DISABLE_HOST_SVC_NOTIFICATIONS: %w{host_name},
86
- DISABLE_NOTIFICATIONS: [],
87
- DISABLE_PASSIVE_HOST_CHECKS: %w{host_name},
88
- DISABLE_PASSIVE_SVC_CHECKS: %w{host_name service_description},
89
- DISABLE_PERFORMANCE_DATA: [],
90
- DISABLE_SERVICEGROUP_HOST_CHECKS: %w{servicegroup_name},
91
- DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS: %w{servicegroup_name},
92
- DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS: %w{servicegroup_name},
93
- DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS: %w{servicegroup_name},
94
- DISABLE_SERVICEGROUP_SVC_CHECKS: %w{servicegroup_name},
95
- DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS: %w{servicegroup_name},
96
- DISABLE_SERVICE_FLAP_DETECTION: %w{host_name service_description},
97
- DISABLE_SERVICE_FRESHNESS_CHECKS: [],
98
- DISABLE_SVC_CHECK: %w{host_name service_description},
99
- DISABLE_SVC_EVENT_HANDLER: %w{host_name service_description},
100
- DISABLE_SVC_FLAP_DETECTION: %w{host_name service_description},
101
- DISABLE_SVC_NOTIFICATIONS: %w{host_name service_description},
102
- ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST: %w{host_name},
103
- ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS: %w{contactgroup_name},
104
- ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS: %w{contactgroup_name},
105
- ENABLE_CONTACT_HOST_NOTIFICATIONS: %w{contact_name},
106
- ENABLE_CONTACT_SVC_NOTIFICATIONS: %w{contact_name},
107
- ENABLE_EVENT_HANDLERS: [],
108
- ENABLE_FAILURE_PREDICTION: [],
109
- ENABLE_FLAP_DETECTION: [],
110
- ENABLE_HOSTGROUP_HOST_CHECKS: %w{hostgroup_name},
111
- ENABLE_HOSTGROUP_HOST_NOTIFICATIONS: %w{hostgroup_name},
112
- ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS: %w{hostgroup_name},
113
- ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS: %w{hostgroup_name},
114
- ENABLE_HOSTGROUP_SVC_CHECKS: %w{hostgroup_name},
115
- ENABLE_HOSTGROUP_SVC_NOTIFICATIONS: %w{hostgroup_name},
116
- ENABLE_HOST_AND_CHILD_NOTIFICATIONS: %w{host_name},
117
- ENABLE_HOST_CHECK: %w{host_name},
118
- ENABLE_HOST_EVENT_HANDLER: %w{host_name},
119
- ENABLE_HOST_FLAP_DETECTION: %w{host_name},
120
- ENABLE_HOST_FRESHNESS_CHECKS: [],
121
- ENABLE_HOST_NOTIFICATIONS: %w{host_name},
122
- ENABLE_HOST_SVC_CHECKS: %w{host_name},
123
- ENABLE_HOST_SVC_NOTIFICATIONS: %w{host_name},
124
- ENABLE_NOTIFICATIONS: [],
125
- ENABLE_PASSIVE_HOST_CHECKS: %w{host_name},
126
- ENABLE_PASSIVE_SVC_CHECKS: %w{host_name service_description},
127
- ENABLE_PERFORMANCE_DATA: [],
128
- ENABLE_SERVICEGROUP_HOST_CHECKS: %w{servicegroup_name},
129
- ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS: %w{servicegroup_name},
130
- ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS: %w{servicegroup_name},
131
- ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS: %w{servicegroup_name},
132
- ENABLE_SERVICEGROUP_SVC_CHECKS: %w{servicegroup_name},
133
- ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS: %w{servicegroup_name},
134
- ENABLE_SERVICE_FRESHNESS_CHECKS: [],
135
- ENABLE_SVC_CHECK: %w{host_name service_description},
136
- ENABLE_SVC_EVENT_HANDLER: %w{host_name service_description},
137
- ENABLE_SVC_FLAP_DETECTION: %w{host_name service_description},
138
- ENABLE_SVC_NOTIFICATIONS: %w{host_name service_description},
139
- PROCESS_FILE: %w{file_name delete},
140
- PROCESS_HOST_CHECK_RESULT: %w{host_name status_code plugin_output},
141
- PROCESS_SERVICE_CHECK_RESULT: %w{host_name service_description return_code plugin_output},
142
- READ_STATE_INFORMATION: [],
143
- REMOVE_HOST_ACKNOWLEDGEMENT: %w{host_name},
144
- REMOVE_SVC_ACKNOWLEDGEMENT: %w{host_name service_description},
145
- RESTART_PROGRAM: [],
146
- SAVE_STATE_INFORMATION: [],
147
- SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME: %w{host_name start_time end_time fixed trigger_id duration author comment},
148
- SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME: %w{host_name start_time end_time fixed trigger_id duration author comment},
149
- SCHEDULE_FORCED_HOST_CHECK: %w{host_name check_time},
150
- SCHEDULE_FORCED_HOST_SVC_CHECKS: %w{host_name check_time},
151
- SCHEDULE_FORCED_SVC_CHECK: %w{host_name service_description check_time},
152
- SCHEDULE_HOSTGROUP_HOST_DOWNTIME: %w{hostgroup_name start_time end_time fixed trigger_id duration author comment},
153
- SCHEDULE_HOSTGROUP_SVC_DOWNTIME: %w{hostgroup_name start_time end_time fixed trigger_id duration author comment},
154
- SCHEDULE_HOST_CHECK: %w{host_name check_time},
155
- SCHEDULE_HOST_DOWNTIME: %w{host_name start_time end_time fixed trigger_id duration author comment},
156
- SCHEDULE_HOST_SVC_CHECKS: %w{host_name check_time},
157
- SCHEDULE_HOST_SVC_DOWNTIME: %w{host_name start_time end_time fixed trigger_id duration author comment},
158
- SCHEDULE_SERVICEGROUP_HOST_DOWNTIME: %w{servicegroup_name start_time end_time fixed trigger_id duration author comment},
159
- SCHEDULE_SERVICEGROUP_SVC_DOWNTIME: %w{servicegroup_name start_time end_time fixed trigger_id duration author comment},
160
- SCHEDULE_SVC_CHECK: %w{host_name service_description check_time},
161
- SCHEDULE_SVC_DOWNTIME: %w{host_name service_desription start_time end_time fixed trigger_id duration author comment},
162
- SEND_CUSTOM_HOST_NOTIFICATION: %w{host_name options author comment},
163
- SEND_CUSTOM_SVC_NOTIFICATION: %w{host_name service_description options author comment},
164
- SET_HOST_NOTIFICATION_NUMBER: %w{host_name notification_number},
165
- SET_SVC_NOTIFICATION_NUMBER: %w{host_name service_description notification_number},
166
- SHUTDOWN_PROGRAM: [],
167
- START_ACCEPTING_PASSIVE_HOST_CHECKS: [],
168
- START_ACCEPTING_PASSIVE_SVC_CHECKS: [],
169
- START_EXECUTING_HOST_CHECKS: [],
170
- START_EXECUTING_SVC_CHECKS: [],
171
- START_OBSESSING_OVER_HOST: %w{host_name},
172
- START_OBSESSING_OVER_HOST_CHECKS: [],
173
- START_OBSESSING_OVER_SVC: %w{host_name service_description},
174
- START_OBSESSING_OVER_SVC_CHECKS: [],
175
- STOP_ACCEPTING_PASSIVE_HOST_CHECKS: [],
176
- STOP_ACCEPTING_PASSIVE_SVC_CHECKS: [],
177
- STOP_EXECUTING_HOST_CHECKS: [],
178
- STOP_EXECUTING_SVC_CHECKS: [],
179
- STOP_OBSESSING_OVER_HOST: %w{host_name},
180
- STOP_OBSESSING_OVER_HOST_CHECKS: [],
181
- STOP_OBSESSING_OVER_SVC: %w{host_name service_description},
182
- STOP_OBSESSING_OVER_SVC_CHECKS: []
26
+ :ACKNOWLEDGE_HOST_PROBLEM => %w{host_name sticky notify persistent author comment},
27
+ :ACKNOWLEDGE_SVC_PROBLEM => %w{host_name service_description sticky notify persistent author comment},
28
+ :ADD_HOST_COMMENT => %w{host_name persistent author comment},
29
+ :ADD_SVC_COMMENT => %w{host_name service_description persistent author comment},
30
+ :CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD => %w{contact_name notification_timeperiod},
31
+ :CHANGE_CONTACT_MODATTR => %w{contact_name value},
32
+ :CHANGE_CONTACT_MODHATTR => %w{contact_name value},
33
+ :CHANGE_CONTACT_MODSATTR => %w{contact_name value},
34
+ :CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD => %w{contact_name notification_timeperiod},
35
+ :CHANGE_CUSTOM_CONTACT_VAR => %w{contact_name varname varvalue},
36
+ :CHANGE_CUSTOM_HOST_VAR => %w{host_name varname varvalue},
37
+ :CHANGE_CUSTOM_SVC_VAR => %w{host_name service_description varname varvalue},
38
+ :CHANGE_GLOBAL_HOST_EVENT_HANDLER => %w{event_handler_command},
39
+ :CHANGE_GLOBAL_SVC_EVENT_HANDLER => %w{event_handler_command},
40
+ :CHANGE_HOST_CHECK_COMMAND => %w{host_name check_command},
41
+ :CHANGE_HOST_CHECK_TIMEPERIOD => %w{host_name check_timeperod},
42
+ :CHANGE_HOST_CHECK_TIMEPERIOD => %w{host_name timeperiod},
43
+ :CHANGE_HOST_EVENT_HANDLER => %w{host_name event_handler_command},
44
+ :CHANGE_HOST_MODATTR => %w{host_name value},
45
+ :CHANGE_MAX_HOST_CHECK_ATTEMPTS => %w{host_name check_attempts},
46
+ :CHANGE_MAX_SVC_CHECK_ATTEMPTS => %w{host_name service_description check_attempts},
47
+ :CHANGE_NORMAL_HOST_CHECK_INTERVAL => %w{host_name check_interval},
48
+ :CHANGE_NORMAL_SVC_CHECK_INTERVAL => %w{host_name service_description check_interval},
49
+ :CHANGE_RETRY_HOST_CHECK_INTERVAL => %w{host_name service_description check_interval},
50
+ :CHANGE_RETRY_SVC_CHECK_INTERVAL => %w{host_name service_description check_interval},
51
+ :CHANGE_SVC_CHECK_COMMAND => %w{host_name service_description check_command},
52
+ :CHANGE_SVC_CHECK_TIMEPERIOD => %w{host_name service_description check_timeperiod},
53
+ :CHANGE_SVC_EVENT_HANDLER => %w{host_name service_description event_handler_command},
54
+ :CHANGE_SVC_MODATTR => %w{host_name service_description value},
55
+ :CHANGE_SVC_NOTIFICATION_TIMEPERIOD => %w{host_name service_description notification_timeperiod},
56
+ :DELAY_HOST_NOTIFICATION => %w{host_name notification_time},
57
+ :DELAY_SVC_NOTIFICATION => %w{host_name service_description notification_time},
58
+ :DEL_ALL_HOST_COMMENTS => %w{host_name},
59
+ :DEL_ALL_SVC_COMMENTS => %w{host_name service_description},
60
+ :DEL_HOST_COMMENT => %w{comment_id},
61
+ :DEL_HOST_DOWNTIME => %w{downtime_id},
62
+ :DEL_SVC_COMMENT => %w{comment_id},
63
+ :DEL_SVC_DOWNTIME => %w{downtime_id},
64
+ :DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST => %w{host_name},
65
+ :DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS => %w{contactgroup_name},
66
+ :DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS => %w{contactgroup_name},
67
+ :DISABLE_CONTACT_HOST_NOTIFICATIONS => %w{contact_name},
68
+ :DISABLE_CONTACT_SVC_NOTIFICATIONS => %w{contact_name},
69
+ :DISABLE_EVENT_HANDLERS => [],
70
+ :DISABLE_FAILURE_PREDICTION => [],
71
+ :DISABLE_FLAP_DETECTION => [],
72
+ :DISABLE_HOSTGROUP_HOST_CHECKS => %w{hostgroup_name},
73
+ :DISABLE_HOSTGROUP_HOST_NOTIFICATIONS => %w{hostgroup_name},
74
+ :DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS => %w{hostgroup_name},
75
+ :DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS => %w{hostgroup_name},
76
+ :DISABLE_HOSTGROUP_SVC_CHECKS => %w{hostgroup_name},
77
+ :DISABLE_HOSTGROUP_SVC_NOTIFICATIONS => %w{hostgroup_name},
78
+ :DISABLE_HOST_AND_CHILD_NOTIFICATIONS => %w{host_name},
79
+ :DISABLE_HOST_CHECK => %w{host_name},
80
+ :DISABLE_HOST_EVENT_HANDLER => %w{host_name},
81
+ :DISABLE_HOST_FLAP_DETECTION => %w{host_name},
82
+ :DISABLE_HOST_FRESHNESS_CHECKS => [],
83
+ :DISABLE_HOST_NOTIFICATIONS => %w{host_name},
84
+ :DISABLE_HOST_SVC_CHECKS => %w{host_name},
85
+ :DISABLE_HOST_SVC_NOTIFICATIONS => %w{host_name},
86
+ :DISABLE_NOTIFICATIONS => [],
87
+ :DISABLE_PASSIVE_HOST_CHECKS => %w{host_name},
88
+ :DISABLE_PASSIVE_SVC_CHECKS => %w{host_name service_description},
89
+ :DISABLE_PERFORMANCE_DATA => [],
90
+ :DISABLE_SERVICEGROUP_HOST_CHECKS => %w{servicegroup_name},
91
+ :DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS => %w{servicegroup_name},
92
+ :DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS => %w{servicegroup_name},
93
+ :DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS => %w{servicegroup_name},
94
+ :DISABLE_SERVICEGROUP_SVC_CHECKS => %w{servicegroup_name},
95
+ :DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS => %w{servicegroup_name},
96
+ :DISABLE_SERVICE_FLAP_DETECTION => %w{host_name service_description},
97
+ :DISABLE_SERVICE_FRESHNESS_CHECKS => [],
98
+ :DISABLE_SVC_CHECK => %w{host_name service_description},
99
+ :DISABLE_SVC_EVENT_HANDLER => %w{host_name service_description},
100
+ :DISABLE_SVC_FLAP_DETECTION => %w{host_name service_description},
101
+ :DISABLE_SVC_NOTIFICATIONS => %w{host_name service_description},
102
+ :ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST => %w{host_name},
103
+ :ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS => %w{contactgroup_name},
104
+ :ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS => %w{contactgroup_name},
105
+ :ENABLE_CONTACT_HOST_NOTIFICATIONS => %w{contact_name},
106
+ :ENABLE_CONTACT_SVC_NOTIFICATIONS => %w{contact_name},
107
+ :ENABLE_EVENT_HANDLERS => [],
108
+ :ENABLE_FAILURE_PREDICTION => [],
109
+ :ENABLE_FLAP_DETECTION => [],
110
+ :ENABLE_HOSTGROUP_HOST_CHECKS => %w{hostgroup_name},
111
+ :ENABLE_HOSTGROUP_HOST_NOTIFICATIONS => %w{hostgroup_name},
112
+ :ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS => %w{hostgroup_name},
113
+ :ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS => %w{hostgroup_name},
114
+ :ENABLE_HOSTGROUP_SVC_CHECKS => %w{hostgroup_name},
115
+ :ENABLE_HOSTGROUP_SVC_NOTIFICATIONS => %w{hostgroup_name},
116
+ :ENABLE_HOST_AND_CHILD_NOTIFICATIONS => %w{host_name},
117
+ :ENABLE_HOST_CHECK => %w{host_name},
118
+ :ENABLE_HOST_EVENT_HANDLER => %w{host_name},
119
+ :ENABLE_HOST_FLAP_DETECTION => %w{host_name},
120
+ :ENABLE_HOST_FRESHNESS_CHECKS => [],
121
+ :ENABLE_HOST_NOTIFICATIONS => %w{host_name},
122
+ :ENABLE_HOST_SVC_CHECKS => %w{host_name},
123
+ :ENABLE_HOST_SVC_NOTIFICATIONS => %w{host_name},
124
+ :ENABLE_NOTIFICATIONS => [],
125
+ :ENABLE_PASSIVE_HOST_CHECKS => %w{host_name},
126
+ :ENABLE_PASSIVE_SVC_CHECKS => %w{host_name service_description},
127
+ :ENABLE_PERFORMANCE_DATA => [],
128
+ :ENABLE_SERVICEGROUP_HOST_CHECKS => %w{servicegroup_name},
129
+ :ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS => %w{servicegroup_name},
130
+ :ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS => %w{servicegroup_name},
131
+ :ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS => %w{servicegroup_name},
132
+ :ENABLE_SERVICEGROUP_SVC_CHECKS => %w{servicegroup_name},
133
+ :ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS => %w{servicegroup_name},
134
+ :ENABLE_SERVICE_FRESHNESS_CHECKS => [],
135
+ :ENABLE_SVC_CHECK => %w{host_name service_description},
136
+ :ENABLE_SVC_EVENT_HANDLER => %w{host_name service_description},
137
+ :ENABLE_SVC_FLAP_DETECTION => %w{host_name service_description},
138
+ :ENABLE_SVC_NOTIFICATIONS => %w{host_name service_description},
139
+ :PROCESS_FILE => %w{file_name delete},
140
+ :PROCESS_HOST_CHECK_RESULT => %w{host_name status_code plugin_output},
141
+ :PROCESS_SERVICE_CHECK_RESULT => %w{host_name service_description return_code plugin_output},
142
+ :READ_STATE_INFORMATION => [],
143
+ :REMOVE_HOST_ACKNOWLEDGEMENT => %w{host_name},
144
+ :REMOVE_SVC_ACKNOWLEDGEMENT => %w{host_name service_description},
145
+ :RESTART_PROGRAM => [],
146
+ :SAVE_STATE_INFORMATION => [],
147
+ :SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME => %w{host_name start_time end_time fixed trigger_id duration author comment},
148
+ :SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME => %w{host_name start_time end_time fixed trigger_id duration author comment},
149
+ :SCHEDULE_FORCED_HOST_CHECK => %w{host_name check_time},
150
+ :SCHEDULE_FORCED_HOST_SVC_CHECKS => %w{host_name check_time},
151
+ :SCHEDULE_FORCED_SVC_CHECK => %w{host_name service_description check_time},
152
+ :SCHEDULE_HOSTGROUP_HOST_DOWNTIME => %w{hostgroup_name start_time end_time fixed trigger_id duration author comment},
153
+ :SCHEDULE_HOSTGROUP_SVC_DOWNTIME => %w{hostgroup_name start_time end_time fixed trigger_id duration author comment},
154
+ :SCHEDULE_HOST_CHECK => %w{host_name check_time},
155
+ :SCHEDULE_HOST_DOWNTIME => %w{host_name start_time end_time fixed trigger_id duration author comment},
156
+ :SCHEDULE_HOST_SVC_CHECKS => %w{host_name check_time},
157
+ :SCHEDULE_HOST_SVC_DOWNTIME => %w{host_name start_time end_time fixed trigger_id duration author comment},
158
+ :SCHEDULE_SERVICEGROUP_HOST_DOWNTIME => %w{servicegroup_name start_time end_time fixed trigger_id duration author comment},
159
+ :SCHEDULE_SERVICEGROUP_SVC_DOWNTIME => %w{servicegroup_name start_time end_time fixed trigger_id duration author comment},
160
+ :SCHEDULE_SVC_CHECK => %w{host_name service_description check_time},
161
+ :SCHEDULE_SVC_DOWNTIME => %w{host_name service_desription start_time end_time fixed trigger_id duration author comment},
162
+ :SEND_CUSTOM_HOST_NOTIFICATION => %w{host_name options author comment},
163
+ :SEND_CUSTOM_SVC_NOTIFICATION => %w{host_name service_description options author comment},
164
+ :SET_HOST_NOTIFICATION_NUMBER => %w{host_name notification_number},
165
+ :SET_SVC_NOTIFICATION_NUMBER => %w{host_name service_description notification_number},
166
+ :SHUTDOWN_PROGRAM => [],
167
+ :START_ACCEPTING_PASSIVE_HOST_CHECKS => [],
168
+ :START_ACCEPTING_PASSIVE_SVC_CHECKS => [],
169
+ :START_EXECUTING_HOST_CHECKS => [],
170
+ :START_EXECUTING_SVC_CHECKS => [],
171
+ :START_OBSESSING_OVER_HOST => %w{host_name},
172
+ :START_OBSESSING_OVER_HOST_CHECKS => [],
173
+ :START_OBSESSING_OVER_SVC => %w{host_name service_description},
174
+ :START_OBSESSING_OVER_SVC_CHECKS => [],
175
+ :STOP_ACCEPTING_PASSIVE_HOST_CHECKS => [],
176
+ :STOP_ACCEPTING_PASSIVE_SVC_CHECKS => [],
177
+ :STOP_EXECUTING_HOST_CHECKS => [],
178
+ :STOP_EXECUTING_SVC_CHECKS => [],
179
+ :STOP_OBSESSING_OVER_HOST => %w{host_name},
180
+ :STOP_OBSESSING_OVER_HOST_CHECKS => [],
181
+ :STOP_OBSESSING_OVER_SVC => %w{host_name service_description},
182
+ :STOP_OBSESSING_OVER_SVC_CHECKS => []
183
183
  }.freeze
184
184
  end
185
185
  end
@@ -101,6 +101,17 @@ Example of a parsed object:
101
101
  nagios.contactgroup
102
102
  => {"admins"=>{:contactgroup_name=>"admins", :alias=>"Nagios Administrators", :members=>"root"}}
103
103
 
104
+ Services are a bit different from other objects, since they are
105
+ related to hosts, all host's services are nested under hostname, as:
106
+
107
+ nagios.service =>
108
+ {"airport"=>
109
+ {"PING"=>
110
+ { :host_name=>"airport",
111
+ :service_description=>"PING",
112
+
113
+
114
+
104
115
  === Convenience methods
105
116
 
106
117
  Method parse creates helper methods for every type of object after
@@ -124,7 +135,18 @@ parsing. Same property can be accessed either using Hash @objects
124
135
  # Process it. Each block type has line <type>_name in the definition: host_name, command_name
125
136
  #
126
137
  @objects[handler] ||= {}
127
- @objects[handler][block["#{handler.to_s}_name".to_sym]] = block
138
+ case handler
139
+ when :service
140
+ #
141
+ # Service has service_description, not name. Nest service
142
+ # hashes under hostnames.
143
+ #
144
+ next unless block[:host_name]
145
+ @objects[handler][block[:host_name]] ||= { }
146
+ @objects[handler][block[:host_name]][block["#{handler.to_s}_description".to_sym]] = block
147
+ else
148
+ @objects[handler][block["#{handler.to_s}_name".to_sym]] = block
149
+ end
128
150
  block = { }
129
151
  when line =~ /^\s*(\w+)\s+([^\{\}]+)$/ # Build Hash from key-value pairs like: "max_check_attempts 10"
130
152
  block[$1.to_sym] = $2.strip
@@ -188,3 +210,4 @@ parsing. Same property can be accessed either using Hash @objects
188
210
  end
189
211
  end
190
212
 
213
+
data/lib/nagios/status.rb CHANGED
@@ -23,7 +23,7 @@ module Nagios
23
23
 
24
24
  @status, handler, blocklines = {'hosts' => {}}, '', []
25
25
 
26
- File.readlines(path).each do |line|
26
+ File.readlines(path, :encoding => 'iso-8859-1').each do |line|
27
27
 
28
28
  # start of new sections
29
29
  if line =~ /(\w+) \{/
@@ -193,14 +193,14 @@ module Nagios
193
193
 
194
194
  # Figures out the service name from a block in a nagios status file
195
195
  def get_service_name(lines)
196
- if s = lines.grep(/\s+service_description=(\w+)/).first
196
+ if s = lines.grep(/\s+service_description=(\S+)/).first
197
197
  if s =~ /service_description=(.+)$/
198
198
  service = $1
199
199
  else
200
200
  raise("Cant't parse service in block: #{s}")
201
201
  end
202
202
  else
203
- raise("Cant't find a hostname in block")
203
+ raise("Cant't find a service in block")
204
204
  end
205
205
 
206
206
  service
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.2.0"
3
+ s.version = "0.2.2"
4
4
  s.author = 'R.I.Pienaar'
5
5
  s.email = 'rip@devco.net'
6
6
  s.homepage = 'http://devco.net/'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nagios
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I.Pienaar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-07-16 00:00:00 +01:00
18
+ date: 2014-05-25 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency