flapjack 0.9.6 → 1.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +6 -0
- data/.travis.yml +20 -16
- data/CHANGELOG.md +11 -25
- data/Dockerfile +8 -0
- data/Gemfile +2 -5
- data/bin/flapjack +24 -213
- data/etc/flapjack_config.yaml.example +6 -30
- data/features/cli.feature +16 -14
- data/features/cli_flapjack-feed-events.feature +12 -13
- data/features/cli_flapjack-nagios-receiver.feature +14 -15
- data/features/cli_flapjack-populator.feature +16 -15
- data/features/cli_flapper.feature +12 -12
- data/features/cli_receive-events.feature +6 -5
- data/features/cli_simulate-failed-check.feature +7 -6
- data/features/steps/cli_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/flapjack.gemspec +1 -0
- data/lib/flapjack/cli/flapper.rb +200 -0
- data/lib/flapjack/cli/import.rb +102 -0
- data/lib/flapjack/cli/receiver.rb +656 -0
- data/lib/flapjack/cli/server.rb +256 -0
- data/lib/flapjack/cli/simulate.rb +180 -0
- data/lib/flapjack/configuration.rb +2 -0
- data/lib/flapjack/data/entity_check.rb +5 -22
- data/lib/flapjack/data/event.rb +7 -12
- data/lib/flapjack/gateways/email.rb +4 -1
- data/lib/flapjack/gateways/jabber.rb +12 -36
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
- data/lib/flapjack/gateways/pagerduty.rb +1 -1
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
- data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
- data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
- data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
- data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/layout.erb +10 -10
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
- data/lib/flapjack/gateways/web.rb +36 -7
- data/lib/flapjack/pikelet.rb +0 -2
- data/lib/flapjack/processor.rb +3 -1
- data/lib/flapjack/redis_pool.rb +2 -6
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +3 -3
- data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
- data/spec/lib/flapjack/data/event_spec.rb +0 -31
- data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
- data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
- data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
- data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
- data/spec/support/profile_all_formatter.rb +44 -0
- data/spec/support/uncolored_doc_formatter.rb +9 -0
- data/tasks/benchmarks.rake +0 -4
- metadata +28 -38
- data/.ruby-version +0 -1
- data/Gemfile-ruby1.9 +0 -28
- data/Gemfile-ruby1.9.lock +0 -227
- data/bin/flapjack-feed-events +0 -124
- data/bin/flapjack-nagios-receiver +0 -246
- data/bin/flapjack-nsca-receiver +0 -246
- data/bin/flapjack-populator +0 -132
- data/bin/flapper +0 -152
- data/bin/receive-events +0 -179
- data/bin/simulate-failed-check +0 -151
- data/lib/flapjack/data/migration.rb +0 -36
- data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
- data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
- data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
- data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
- data/lib/flapjack/gateways/api.rb +0 -124
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
- data/spec/lib/flapjack/gateways/api_spec.rb +0 -30
@@ -0,0 +1,656 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'dante'
|
4
|
+
require 'redis'
|
5
|
+
|
6
|
+
require 'oj'
|
7
|
+
Oj.default_options = { :indent => 0, :mode => :strict }
|
8
|
+
|
9
|
+
require 'flapjack/configuration'
|
10
|
+
require 'flapjack/data/event'
|
11
|
+
|
12
|
+
# TODO options should be overridden by similar config file options
|
13
|
+
|
14
|
+
module Flapjack
|
15
|
+
module CLI
|
16
|
+
class Receiver
|
17
|
+
|
18
|
+
def initialize(global_options, options)
|
19
|
+
@global_options = global_options
|
20
|
+
@options = options
|
21
|
+
|
22
|
+
config = Flapjack::Configuration.new
|
23
|
+
config.load(global_options[:config])
|
24
|
+
@config_env = config.all
|
25
|
+
|
26
|
+
if @config_env.nil? || @config_env.empty?
|
27
|
+
puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{global_options[:config]}'"
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
@redis_options = config.for_redis
|
32
|
+
end
|
33
|
+
|
34
|
+
# For nagios-receiver:
|
35
|
+
#
|
36
|
+
# nagios.cfg must contain the following perfdata templates for host and service data (modified from the default
|
37
|
+
# to include hoststate / servicestate, and a fake service 'HOST' for hostperfdata, so that the
|
38
|
+
# fields match up:
|
39
|
+
#
|
40
|
+
# host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
|
41
|
+
#
|
42
|
+
# service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
|
43
|
+
#
|
44
|
+
|
45
|
+
def nagios_start
|
46
|
+
if runner('nagios').daemon_running?
|
47
|
+
puts "nagios-receiver is already running."
|
48
|
+
exit 1
|
49
|
+
else
|
50
|
+
print "nagios-receiver starting..."
|
51
|
+
runner('nagios').execute(:daemonize => @options[:daemonize]) do
|
52
|
+
begin
|
53
|
+
main(:fifo => @options[:fifo], :nagios => true)
|
54
|
+
rescue Exception => e
|
55
|
+
p e.message
|
56
|
+
puts e.backtrace.join("\n")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
puts " done."
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def nagios_stop
|
64
|
+
if runner('nagios').daemon_running?
|
65
|
+
print "nagios-receiver stopping..."
|
66
|
+
runner('nagios').execute(:kill => true)
|
67
|
+
puts " done."
|
68
|
+
else
|
69
|
+
puts "nagios-receiver is not running."
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def nagios_restart
|
75
|
+
print "nagios-receiver restarting..."
|
76
|
+
runner('nagios').execute(:daemonize => true, :restart => true) do
|
77
|
+
main(:fifo => @options[:fifo], :nagios => true)
|
78
|
+
end
|
79
|
+
puts " done."
|
80
|
+
end
|
81
|
+
|
82
|
+
def nagios_status
|
83
|
+
config_runner = @config_env["nagios-receiver"] || {}
|
84
|
+
pidfile = @options[:pidfile] || config_runner['pid_file'] ||
|
85
|
+
"/var/run/flapjack/nagios-receiver.pid"
|
86
|
+
uptime = (runner('nagios').daemon_running?) ? (Time.now - File.stat(pidfile).ctime) : 0
|
87
|
+
if runner('nagios').daemon_running?
|
88
|
+
puts "nagios-receiver is running: #{uptime}"
|
89
|
+
else
|
90
|
+
puts "nagios-receiver is not running"
|
91
|
+
exit 3
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def nsca_start
|
96
|
+
if runner('nsca').daemon_running?
|
97
|
+
puts "nsca-receiver is already running."
|
98
|
+
exit 1
|
99
|
+
else
|
100
|
+
print "nsca-receiver starting..."
|
101
|
+
runner('nsca').execute(:daemonize => @options[:daemonize]) do
|
102
|
+
main(:fifo => @options[:fifo], :nsca => true)
|
103
|
+
end
|
104
|
+
puts " done."
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def nsca_stop
|
109
|
+
if runner('nsca').daemon_running?
|
110
|
+
print "nsca-receiver stopping..."
|
111
|
+
runner('nsca').execute(:kill => true)
|
112
|
+
puts " done."
|
113
|
+
else
|
114
|
+
puts "nsca-receiver is not running."
|
115
|
+
exit 1
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def nsca_restart
|
120
|
+
print "nsca-receiver restarting..."
|
121
|
+
runner('nsca').execute(:daemonize => true, :restart => true) do
|
122
|
+
main(:fifo => @options[:fifo], :nsca => true)
|
123
|
+
end
|
124
|
+
puts " done."
|
125
|
+
end
|
126
|
+
|
127
|
+
def nsca_status
|
128
|
+
config_runner = @config_env["nsca-receiver"] || {}
|
129
|
+
|
130
|
+
pidfile = @options[:pidfile] || config_runner['pid_file'] ||
|
131
|
+
"/var/run/flapjack/nsca-receiver.pid"
|
132
|
+
|
133
|
+
uptime = (runner('nsca').daemon_running?) ? (Time.now - File.stat(pidfile).ctime) : 0
|
134
|
+
if runner('nsca').daemon_running?
|
135
|
+
puts "nsca-receiver is running: #{uptime}"
|
136
|
+
else
|
137
|
+
puts "nsca-receiver is not running"
|
138
|
+
exit 3
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def json
|
143
|
+
json_feeder(:from => @options[:from])
|
144
|
+
end
|
145
|
+
|
146
|
+
def mirror
|
147
|
+
mirror_receive(:source => @options[:source],
|
148
|
+
:all => @options[:all], :follow => @options[:follow],
|
149
|
+
:last => @options[:last], :time => @options[:time])
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def redis
|
155
|
+
@redis ||= Redis.new(@redis_options)
|
156
|
+
end
|
157
|
+
|
158
|
+
def runner(type)
|
159
|
+
return @runner if @runner
|
160
|
+
|
161
|
+
config_runner = @config_env["#{type}-receiver"] || {}
|
162
|
+
|
163
|
+
pidfile = @options[:pidfile].nil? ?
|
164
|
+
(config_runner['pid_file'] || "/var/run/flapjack/#{type}-receiver.pid") :
|
165
|
+
@options[:pidfile]
|
166
|
+
|
167
|
+
logfile = @options[:logfile].nil? ?
|
168
|
+
(config_runner['log_file'] || "/var/log/flapjack/#{type}-receiver.log") :
|
169
|
+
@options[:logfile]
|
170
|
+
|
171
|
+
@runner = Dante::Runner.new("#{type}-receiver", :pid_path => pidfile,
|
172
|
+
:log_path => logfile)
|
173
|
+
@runner
|
174
|
+
end
|
175
|
+
|
176
|
+
def process_input(opts)
|
177
|
+
config_rec = if opts[:nagios]
|
178
|
+
@config_env['nagios-receiver'] || {}
|
179
|
+
elsif opts[:nsca]
|
180
|
+
@config_env['nsca-receiver'] || {}
|
181
|
+
else
|
182
|
+
raise "Unknown receiver type"
|
183
|
+
end
|
184
|
+
|
185
|
+
opt_fifo = (opts[:fifo] || config_rec['fifo'] || '/var/cache/nagios3/event_stream.fifo')
|
186
|
+
unless File.exist?(opt_fifo)
|
187
|
+
raise "No fifo (named pipe) file found at #{opt_fifo}"
|
188
|
+
end
|
189
|
+
unless File.pipe?(opt_fifo)
|
190
|
+
raise "The file at #{opt_fifo} is not a named pipe, try using mkfifo to make one"
|
191
|
+
end
|
192
|
+
unless File.readable?(opt_fifo)
|
193
|
+
raise "The fifo (named pipe) at #{opt_fifo} is unreadable"
|
194
|
+
end
|
195
|
+
|
196
|
+
fifo = File.new(opt_fifo)
|
197
|
+
begin
|
198
|
+
while line = fifo.gets
|
199
|
+
skip unless line
|
200
|
+
split_line = line.split("\t")
|
201
|
+
|
202
|
+
object_type, timestamp, entity, check, state, check_time,
|
203
|
+
check_latency, check_output, check_perfdata, check_long_output =
|
204
|
+
[nil] * 10
|
205
|
+
|
206
|
+
if opts[:nagios]
|
207
|
+
|
208
|
+
object_type, timestamp, entity, check, state, check_time,
|
209
|
+
check_latency, check_output, check_perfdata, check_long_output = split_line
|
210
|
+
|
211
|
+
case
|
212
|
+
when split_line.length < 9
|
213
|
+
puts "ERROR - rejecting this line as it doesn't split into at least 9 tab separated strings: [#{line}]"
|
214
|
+
next
|
215
|
+
when timestamp !~ /^\d+$/
|
216
|
+
puts "ERROR - rejecting this line as second string doesn't look like a timestamp: [#{line}]"
|
217
|
+
next
|
218
|
+
when (object_type != '[HOSTPERFDATA]') && (object_type != '[SERVICEPERFDATA]')
|
219
|
+
puts "ERROR - rejecting this line as first string is neither '[HOSTPERFDATA]' nor '[SERVICEPERFDATA]': [#{line}]"
|
220
|
+
next
|
221
|
+
end
|
222
|
+
|
223
|
+
elsif opts[:nsca]
|
224
|
+
|
225
|
+
timestamp, passivecheck = split_line
|
226
|
+
split_passive = passivecheck.split(";")
|
227
|
+
timestamp = timestamp.delete('[]')
|
228
|
+
|
229
|
+
check_long_output = ''
|
230
|
+
object_type, entity, check, state, check_output = split_passive
|
231
|
+
|
232
|
+
case
|
233
|
+
when (split_line.length < 2 || split_passive.length < 5)
|
234
|
+
puts "ERROR - rejecting this line; illegal format: [#{line}]"
|
235
|
+
next
|
236
|
+
when (timestamp !~ /^\d+$/)
|
237
|
+
puts "ERROR - rejecting this line; timestamp look like a timestamp: [#{line}]"
|
238
|
+
next
|
239
|
+
when (object_type != 'PROCESS_SERVICE_CHECK_RESULT')
|
240
|
+
puts "ERROR - rejecting this line; identifier 'PROCESS_SERVICE_CHECK_RESULT' is missing: [#{line}]"
|
241
|
+
next
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
puts "#{object_type}, #{timestamp}, #{entity}, #{check}, #{state}, #{check_output}, #{check_long_output}"
|
247
|
+
|
248
|
+
state = 'ok' if state.downcase == 'up'
|
249
|
+
state = 'critical' if state.downcase == 'down'
|
250
|
+
details = check_long_output ? check_long_output.gsub(/\\n/, "\n") : nil
|
251
|
+
event = {
|
252
|
+
'entity' => entity,
|
253
|
+
'check' => check,
|
254
|
+
'type' => 'service',
|
255
|
+
'state' => state,
|
256
|
+
'summary' => check_output,
|
257
|
+
'details' => details,
|
258
|
+
'perfdata' => check_perfdata,
|
259
|
+
'time' => timestamp,
|
260
|
+
}
|
261
|
+
Flapjack::Data::Event.add(event, :redis => redis)
|
262
|
+
end
|
263
|
+
rescue Redis::CannotConnectError
|
264
|
+
puts "Error, unable to to connect to the redis server (#{$!})"
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def main(opts)
|
269
|
+
fifo = opts[:fifo]
|
270
|
+
while true
|
271
|
+
process_input(:fifo => fifo, :nagios => opts[:nagios], :nsca => opts[:nsca])
|
272
|
+
puts "Whoops with the fifo, restarting main loop in 10 seconds"
|
273
|
+
sleep 10
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
class EventFeedHandler < Oj::ScHandler
|
279
|
+
|
280
|
+
def initialize(&block)
|
281
|
+
@hash_depth = 0
|
282
|
+
@callback = block if block_given?
|
283
|
+
end
|
284
|
+
|
285
|
+
def hash_start
|
286
|
+
@hash_depth += 1
|
287
|
+
Hash.new
|
288
|
+
end
|
289
|
+
|
290
|
+
def hash_end
|
291
|
+
@hash_depth -= 1
|
292
|
+
end
|
293
|
+
|
294
|
+
def array_start
|
295
|
+
Array.new
|
296
|
+
end
|
297
|
+
|
298
|
+
def array_end
|
299
|
+
end
|
300
|
+
|
301
|
+
def add_value(value)
|
302
|
+
@callback.call(value) if @callback
|
303
|
+
nil
|
304
|
+
end
|
305
|
+
|
306
|
+
def hash_set(hash, key, value)
|
307
|
+
hash[key] = value
|
308
|
+
end
|
309
|
+
|
310
|
+
def array_append(array, value)
|
311
|
+
array << value
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
def json_feeder(opts = {})
|
317
|
+
|
318
|
+
input = if opts[:from]
|
319
|
+
File.open(opts[:from]) # Explodes if file does not exist.
|
320
|
+
elsif $stdin.tty?
|
321
|
+
puts "No file provided, and STDIN is from terminal! Exiting..."
|
322
|
+
exit(1)
|
323
|
+
else
|
324
|
+
$stdin
|
325
|
+
end
|
326
|
+
|
327
|
+
# Sit and churn through the input stream until a valid JSON blob has been assembled.
|
328
|
+
# This handles both the case of a process sending a single JSON and then exiting
|
329
|
+
# (eg. cat foo.json | bin/flapjack receiver json) *and* a longer-running process spitting
|
330
|
+
# out events (eg. /usr/bin/slow-event-feed | bin/flapjack receiver json)
|
331
|
+
|
332
|
+
parser = EventFeedHandler.new do |parsed|
|
333
|
+
# Handle "parsed" (a hash)
|
334
|
+
errors = Flapjack::Data::Event.validation_errors_for_hash(parsed)
|
335
|
+
if errors.empty?
|
336
|
+
Flapjack::Data::Event.add(parsed, :redis => redis)
|
337
|
+
puts "Enqueued event data, #{parsed.inspect}"
|
338
|
+
else
|
339
|
+
puts "Invalid event data received, #{errors.join(', ')} #{parsed.inspect}"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
Oj.sc_parse(parser, input)
|
344
|
+
|
345
|
+
puts "Done."
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
def mirror_receive(opts)
|
350
|
+
unless opts[:follow] || opts[:all]
|
351
|
+
puts "one or both of --follow or --all is required"
|
352
|
+
exit 1
|
353
|
+
end
|
354
|
+
|
355
|
+
source_redis = Redis.new(:url => opts[:source])
|
356
|
+
|
357
|
+
archives = mirror_get_archive_keys_stats(source_redis)
|
358
|
+
raise "found no archives!" unless archives && archives.length > 0
|
359
|
+
|
360
|
+
puts "found archives: #{archives.inspect}"
|
361
|
+
|
362
|
+
# each archive bucket is a redis list that is written
|
363
|
+
# with brpoplpush, that is newest items are added to the left (head)
|
364
|
+
# of the list, so oldest events are to be found at the tail of the list.
|
365
|
+
#
|
366
|
+
# the index of these archives, in the 'archives' array, also stores the
|
367
|
+
# redis key names for each bucket in oldest to newest
|
368
|
+
events_sent = 0
|
369
|
+
case
|
370
|
+
when opts[:all]
|
371
|
+
archive_key = archives[0][:name]
|
372
|
+
cursor = -1
|
373
|
+
when opts[:last], opts[:time]
|
374
|
+
raise "Sorry, unimplemented"
|
375
|
+
else
|
376
|
+
# wait for the next event to be archived, so point the cursor at a non-existant
|
377
|
+
# slot in the list, the one before the 0'th
|
378
|
+
archive_key = archives[-1][:name]
|
379
|
+
cursor = -1 - archives[-1][:size]
|
380
|
+
end
|
381
|
+
|
382
|
+
puts archive_key
|
383
|
+
|
384
|
+
loop do
|
385
|
+
new_archive_key = false
|
386
|
+
# something to read at cursor?
|
387
|
+
event = source_redis.lindex(archive_key, cursor)
|
388
|
+
if event
|
389
|
+
Flapjack::Data::Event.add(event, :redis => redis)
|
390
|
+
events_sent += 1
|
391
|
+
print "#{events_sent} " if events_sent % 1000 == 0
|
392
|
+
cursor -= 1
|
393
|
+
else
|
394
|
+
puts "\narchive key: #{archive_key}, cursor: #{cursor}"
|
395
|
+
# do we need to look at the next archive bucket?
|
396
|
+
archives = mirror_get_archive_keys_stats(source_redis)
|
397
|
+
i = archives.index {|a| a[:name] == archive_key }
|
398
|
+
if archives[i][:size] = (cursor.abs + 1)
|
399
|
+
if archives[i + 1]
|
400
|
+
archive_key = archives[i + 1][:name]
|
401
|
+
puts archive_key
|
402
|
+
cursor = -1
|
403
|
+
new_archive_key = true
|
404
|
+
else
|
405
|
+
return unless opts[:follow]
|
406
|
+
end
|
407
|
+
end
|
408
|
+
sleep 1 unless new_archive_key
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
def mirror_get_archive_keys_stats(source_redis)
|
414
|
+
source_redis.keys("events_archive:*").sort.map {|a|
|
415
|
+
{ :name => a,
|
416
|
+
:size => source_redis.llen(a) }
|
417
|
+
}
|
418
|
+
end
|
419
|
+
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
desc 'Receive events from external systems and send them to Flapjack'
|
425
|
+
arg_name 'receiver'
|
426
|
+
command :receiver do |receiver|
|
427
|
+
|
428
|
+
receiver.desc 'Nagios receiver'
|
429
|
+
#receiver.arg_name 'Turn Nagios check results into Flapjack events'
|
430
|
+
receiver.command :nagios do |nagios|
|
431
|
+
|
432
|
+
# # Not sure what to do with this, was 'extended help'
|
433
|
+
|
434
|
+
# puts '
|
435
|
+
# Required Nagios Configuration Changes
|
436
|
+
# -------------------------------------
|
437
|
+
|
438
|
+
# flapjack-nagios-receiver reads events from a named pipe written to by Nagios. The named pipe needs creating, and Nagios needs to be told to write performance data output to it.
|
439
|
+
|
440
|
+
# To create the named pipe:
|
441
|
+
|
442
|
+
# mkfifo -m 0666 /var/cache/nagios3/event_stream.fifo
|
443
|
+
|
444
|
+
# nagios.cfg changes:
|
445
|
+
|
446
|
+
# # modified lines:
|
447
|
+
# enable_notifications=0
|
448
|
+
# host_perfdata_file=/var/cache/nagios3/event_stream.fifo
|
449
|
+
# service_perfdata_file=/var/cache/nagios3/event_stream.fifo
|
450
|
+
# host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
|
451
|
+
# service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
|
452
|
+
# host_perfdata_file_mode=p
|
453
|
+
# service_perfdata_file_mode=p
|
454
|
+
|
455
|
+
# Details on the wiki: https://github.com/flapjack/flapjack/wiki/USING#configuring-nagios
|
456
|
+
# '
|
457
|
+
|
458
|
+
nagios.command :start do |start|
|
459
|
+
|
460
|
+
start.switch [:d, 'daemonize'], :desc => 'Daemonize',
|
461
|
+
:default_value => true
|
462
|
+
|
463
|
+
start.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
464
|
+
|
465
|
+
start.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
466
|
+
|
467
|
+
start.flag [:f, 'fifo'], :desc => 'PATH of the nagios perfdata named pipe'
|
468
|
+
|
469
|
+
start.action do |global_options,options,args|
|
470
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
471
|
+
receiver.nagios_start
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
nagios.command :stop do |stop|
|
476
|
+
|
477
|
+
stop.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
478
|
+
|
479
|
+
stop.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
480
|
+
|
481
|
+
stop.action do |global_options,options,args|
|
482
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
483
|
+
receiver.nagios_stop
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
nagios.command :restart do |restart|
|
488
|
+
|
489
|
+
restart.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
490
|
+
|
491
|
+
restart.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
492
|
+
|
493
|
+
restart.flag [:f, 'fifo'], :desc => 'PATH of the nagios perfdata named pipe'
|
494
|
+
|
495
|
+
restart.action do |global_options,options,args|
|
496
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
497
|
+
receiver.nagios_restart
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
nagios.command :status do |status|
|
502
|
+
|
503
|
+
status.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
504
|
+
|
505
|
+
status.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
506
|
+
|
507
|
+
status.action do |global_options,options,args|
|
508
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
509
|
+
receiver.nagios_status
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
end
|
514
|
+
|
515
|
+
receiver.desc 'NSCA receiver'
|
516
|
+
#receiver.arg_name 'Turn Nagios passive check results into Flapjack events'
|
517
|
+
receiver.command :nsca do |nsca|
|
518
|
+
|
519
|
+
nsca.command :start do |start|
|
520
|
+
|
521
|
+
# # Not sure what to do with this, extra help output:
|
522
|
+
|
523
|
+
# Required Nagios Configuration Changes
|
524
|
+
# -------------------------------------
|
525
|
+
|
526
|
+
# flapjack-nsca-receiver reads events from the nagios "command file" read from by Nagios, written to by the Nsca-daemon.
|
527
|
+
|
528
|
+
# The named pipe is automatically created by _nagios_ if it is enabled
|
529
|
+
# in the configfile:
|
530
|
+
|
531
|
+
# # modified lines:
|
532
|
+
# command_file=/var/lib/nagios3/rw/nagios.cmd
|
533
|
+
|
534
|
+
# The Nsca daemon is optionally writing to a tempfile if the named pipe does
|
535
|
+
# not exist.
|
536
|
+
|
537
|
+
# Details on the wiki: https://github.com/flapjack/flapjack/wiki/USING#XXX
|
538
|
+
# '
|
539
|
+
|
540
|
+
start.switch [:d, 'daemonize'], :desc => 'Daemonize',
|
541
|
+
:default_value => true
|
542
|
+
|
543
|
+
start.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
544
|
+
|
545
|
+
start.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
546
|
+
|
547
|
+
start.flag [:f, 'fifo'], :desc => 'PATH of the nagios perfdata named pipe'
|
548
|
+
|
549
|
+
start.action do |global_options,options,args|
|
550
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
551
|
+
receiver.nsca_start
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
nsca.command :stop do |stop|
|
556
|
+
|
557
|
+
stop.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
558
|
+
|
559
|
+
stop.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
560
|
+
|
561
|
+
stop.action do |global_options,options,args|
|
562
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
563
|
+
receiver.nsca_stop
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
nsca.command :restart do |restart|
|
568
|
+
|
569
|
+
restart.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
570
|
+
|
571
|
+
restart.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
572
|
+
|
573
|
+
restart.flag [:f, 'fifo'], :desc => 'PATH of the nagios perfdata named pipe'
|
574
|
+
|
575
|
+
restart.action do |global_options,options,args|
|
576
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
577
|
+
receiver.nsca_restart
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
nsca.command :status do |status|
|
582
|
+
|
583
|
+
status.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to'
|
584
|
+
|
585
|
+
status.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to'
|
586
|
+
|
587
|
+
status.action do |global_options,options,args|
|
588
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
589
|
+
receiver.nsca_status
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
end
|
594
|
+
|
595
|
+
receiver.desc 'JSON receiver'
|
596
|
+
receiver.command :json do |json|
|
597
|
+
|
598
|
+
json.flag [:f, 'from'], :desc => 'PATH of the file to process [STDIN]'
|
599
|
+
|
600
|
+
json.action do |global_options,options,args|
|
601
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
602
|
+
receiver.json
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
receiver.desc 'Mirror receiver'
|
607
|
+
receiver.command :mirror do |mirror|
|
608
|
+
|
609
|
+
mirror.flag [:s, 'source'], :desc => 'URL of source redis database, eg redis://localhost:6379/0',
|
610
|
+
:required => true
|
611
|
+
|
612
|
+
# one or both of follow, all is required
|
613
|
+
mirror.switch [:f, 'follow'], :desc => 'keep reading events as they are archived on the source',
|
614
|
+
:default_value => nil
|
615
|
+
|
616
|
+
mirror.switch [:a, 'all'], :desc => 'replay all archived events from the source',
|
617
|
+
:default_value => nil
|
618
|
+
|
619
|
+
# options.count in code
|
620
|
+
mirror.flag [:l, 'last'], :desc => 'replay the last COUNT events from the source',
|
621
|
+
:default_value => nil
|
622
|
+
|
623
|
+
# options.since in code
|
624
|
+
mirror.flag [:t, 'time'], :desc => 'replay all events archived on the source since TIME',
|
625
|
+
:default_value => nil
|
626
|
+
|
627
|
+
mirror.action do |global_options,options,args|
|
628
|
+
receiver = Flapjack::CLI::Receiver.new(global_options, options)
|
629
|
+
receiver.mirror
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
end
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
# # Nsca example line for a storage-device check:
|
638
|
+
# #[1393410685] PROCESS_SERVICE_CHECK_RESULT;db1.dev;STORAGE;0;Raid Set # 000 (800.0GB) is Normal.
|
639
|
+
|
640
|
+
# config_nr = config_env['nsca-receiver'] || {}
|
641
|
+
|
642
|
+
# pidfile = options.pidfile.nil? ?
|
643
|
+
# (config_nr['pid_file'] || "/var/run/flapjack/#{exe}.pid") :
|
644
|
+
# options.pidfile
|
645
|
+
|
646
|
+
# logfile = options.logfile.nil? ?
|
647
|
+
# (config_nr['log_file'] || "/var/log/flapjack/#{exe}.log") :
|
648
|
+
# options.logfile
|
649
|
+
|
650
|
+
# fifo = options.fifo.nil? ?
|
651
|
+
# (config_nr['fifo'] || '/var/lib/nagios3/rw/nagios.cmd') :
|
652
|
+
# options.fifo
|
653
|
+
|
654
|
+
# daemonize = options.daemonize.nil? ?
|
655
|
+
# !!config_nr['daemonize'] :
|
656
|
+
# options.daemonize
|