flapjack 0.7.29 → 0.7.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +8 -0
  2. data/bin/flapjack-nagios-receiver +20 -15
  3. data/bin/flapjack-populator +30 -13
  4. data/bin/flapper +1 -1
  5. data/bin/receive-events +13 -10
  6. data/bin/simulate-failed-check +13 -3
  7. data/dist/etc/init.d/flapjack +5 -42
  8. data/dist/etc/init.d/flapjack-nagios-receiver +3 -17
  9. data/dist/etc/init.d/flapper +3 -12
  10. data/etc/flapjack_config.yaml.example +81 -52
  11. data/features/cli.feature +30 -13
  12. data/features/cli_flapjack-nagios-receiver.feature +66 -0
  13. data/features/cli_flapjack-populator.feature +80 -0
  14. data/features/cli_flapper.feature +45 -0
  15. data/features/cli_receive-events.feature +27 -0
  16. data/features/cli_simulate-failed-check.feature +31 -0
  17. data/features/events.feature +3 -6
  18. data/features/packaging-lintian.feature +2 -2
  19. data/features/rollup.feature +2 -4
  20. data/features/steps/cli_steps.rb +25 -7
  21. data/features/steps/packaging-lintian_steps.rb +12 -6
  22. data/features/support/daemons.rb +11 -1
  23. data/features/support/env.rb +16 -4
  24. data/lib/flapjack/coordinator.rb +1 -1
  25. data/lib/flapjack/filters/delays.rb +1 -1
  26. data/lib/flapjack/gateways/email/alert.html.erb +1 -1
  27. data/lib/flapjack/gateways/email/alert.text.erb +1 -1
  28. data/lib/flapjack/gateways/email/rollup.html.erb +1 -1
  29. data/lib/flapjack/gateways/email/rollup.text.erb +1 -1
  30. data/lib/flapjack/gateways/web/views/check.html.erb +1 -1
  31. data/lib/flapjack/gateways/web/views/contact.html.erb +37 -32
  32. data/lib/flapjack/gateways/web.rb +7 -7
  33. data/lib/flapjack/logger.rb +25 -45
  34. data/lib/flapjack/version.rb +1 -1
  35. data/spec/lib/flapjack/coordinator_spec.rb +9 -7
  36. data/spec/lib/flapjack/logger_spec.rb +19 -13
  37. data/tasks/benchmarks.rake +1 -1
  38. data/tasks/support/flapjack_config_benchmark.yaml +1 -29
  39. metadata +97 -47
  40. checksums.yaml +0 -7
  41. data/bin/flapjack-netsaint-parser +0 -432
  42. data/dist/puppet/flapjack/files/.stub +0 -0
  43. data/dist/puppet/flapjack/manifests/common.pp +0 -61
  44. data/dist/puppet/flapjack/manifests/notifier.pp +0 -13
  45. data/dist/puppet/flapjack/manifests/worker.pp +0 -13
  46. data/dist/puppet/flapjack/templates/.stub +0 -0
  47. data/dist/puppet/ruby/manifests/dev.pp +0 -5
  48. data/dist/puppet/ruby/manifests/rubygems.pp +0 -14
  49. data/dist/puppet/sqlite3/manifests/dev.pp +0 -5
@@ -1,432 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'oj'
4
- Oj.default_options = { :indent => 0, :mode => :strict }
5
-
6
- module Netsaint
7
- class Service
8
- def self.all
9
- @services = []
10
-
11
- Netsaint::Config.services.each do |id, attributes|
12
- attributes.each do |attrs|
13
- @services << self.new(attrs.merge("id" => id))
14
- end
15
- end
16
-
17
- #@services[0..500]
18
- @services
19
- end
20
-
21
- def initialize(opts={})
22
- @attributes = opts
23
-
24
- @attributes.keys.each do |key|
25
- if key == "id" || !self.respond_to?(key.to_sym)
26
- instance_eval <<-METHOD
27
- def #{key}
28
- @attributes["#{key}"]
29
- end
30
- METHOD
31
- end
32
- end
33
- end
34
-
35
- def flapjack_id
36
- "#{id}-#{description.downcase.gsub(' ', '_')}"
37
- end
38
-
39
- def check_command
40
- parts = @attributes["check_command"].split('!')
41
- command_id = parts.first
42
- arguments = parts[1..-1]
43
-
44
- attrs = { "arguments" => arguments,
45
- "hostname" => self.id }
46
- #command = ::Netsaint::Command.get(command_id)
47
- #command.attributes = attrs
48
- #command.expand_command_line
49
- "exit 0"
50
- end
51
-
52
- def to_flapjack
53
- {"id" => flapjack_id, "command" => check_command, "interval" => check_interval.to_i * 60 }
54
- end
55
- end
56
-
57
- class Command
58
- def self.all
59
- @commands = []
60
-
61
- Netsaint::Config.commands.each do |id, attributes|
62
- attributes.each do |attrs|
63
- @commands << self.new(attrs.merge("id" => id))
64
- end
65
- end
66
-
67
- @commands
68
- end
69
-
70
- def self.get(id)
71
- attrs = Netsaint::Config.commands[id].first
72
- command = attrs.merge({"id" => id})
73
-
74
- self.new(command)
75
- end
76
-
77
- def initialize(opts={})
78
- @attributes = opts
79
-
80
- @attributes.keys.each do |key|
81
- if key == "id" || !self.respond_to?(key.to_sym)
82
- instance_eval <<-METHOD
83
- def #{key}
84
- @attributes["#{key}"]
85
- end
86
- METHOD
87
- end
88
- end
89
- end
90
-
91
- def attributes=(attrs)
92
- @attributes.merge!(attrs)
93
- end
94
-
95
- def expand_command_line
96
- @attributes["command_line"].gsub(/\$\w+\$/) do |string|
97
- lookup_macro(string)
98
- end
99
- end
100
-
101
- def lookup_macro(string)
102
- case string
103
- when /^\$USER\d+\$$/
104
- ::Netsaint::Config.fetch(string)[string]
105
- when /^\$ARG(\d+)\$$/
106
- index = $1.to_i - 1
107
- @attributes["arguments"][index]
108
- when "$HOSTNAME$"
109
- @attributes["hostname"]
110
- when "$HOSTADDRESS$"
111
- hostname = @attributes["hostname"]
112
- ::Netsaint::Host.get(hostname).address
113
- else
114
- raise "Don't know how to handle the #{string} macro!"
115
- end
116
- end
117
- end
118
-
119
- class Host
120
- def self.get(id)
121
- attrs = Netsaint::Config.hosts[id].first
122
- host = attrs.merge({"id" => id})
123
-
124
- self.new(host)
125
- end
126
-
127
- def initialize(opts={})
128
- @attributes = opts
129
-
130
- @attributes.keys.each do |key|
131
- if key == "id" || !self.respond_to?(key.to_sym)
132
- instance_eval <<-METHOD
133
- def #{key}
134
- @attributes["#{key}"]
135
- end
136
- METHOD
137
- end
138
- end
139
- end
140
- end
141
-
142
- class ConfigFile
143
- attr_accessor :filename, :config
144
-
145
- def initialize(filename, opts={})
146
- @filename = filename
147
- @config = {}
148
- end
149
-
150
- def read
151
- @raw_cfg = File.readlines(@filename).grep(/^[^#]/).map {|l| l.strip.empty? ? nil : l.strip }.compact
152
- end
153
-
154
- def extract(keyname, opts={}, &blk)
155
- opts[:delete] ||= true
156
- attrs = @config.find_all {|k, v| k =~ /^#{keyname}\[/ }
157
- extracted = {}
158
-
159
- attrs.each do |key, value|
160
- @config.delete(key) if opts[:delete]
161
- name = key[/#{keyname}\[(.+)\]/, 1]
162
- extracted[name] ||= []
163
- if value.class == Array
164
- value.each { |v| extracted[name] << v }
165
- else
166
- extracted[name] << value
167
- end
168
- end
169
-
170
-
171
- if block_given?
172
- yielded = extracted.map do |key, value|
173
- key, value = yield key, value
174
- [ key, value ]
175
- end
176
- extracted = Hash[yielded]
177
- end
178
-
179
- extracted
180
- end
181
-
182
- def build_timeperiods
183
- timeperiods = extract "timeperiod" do |key, value|
184
- value.map! do |v|
185
- parts = v.split(';')
186
- { "timeperiod_alias" => parts[1], "sun_timeranges" => parts[2],
187
- "mon_timeranges" => parts[3], "tue_timeranges" => parts[4],
188
- "wed_timeranges" => parts[5], "thu_timeranges" => parts[6],
189
- "fri_timeranges" => parts[7], "sat_timeranges" => parts[8] }
190
- end
191
- [ key, value ]
192
- end
193
-
194
- @config["timeperiods"] = timeperiods
195
- end
196
-
197
- def build_services
198
- services = extract "service" do |key, value|
199
- value.map! do |v|
200
- parts = v.split(';')
201
- { "description" => parts[0], "volatile" => parts[1],
202
- "check_period" => parts[2], "max_attempts" => parts[3],
203
- "check_interval" => parts[4], "retry_interval" => parts[5],
204
- "notification_group" => parts[6], "notification_interval" => parts[7],
205
- "notification_period" => parts[8], "notify_recovery" => parts[9],
206
- "notify_critical" => parts[10], "notify_warning" => parts[11],
207
- "event_hander" => parts[12], "check_command" => parts[13] }
208
- end
209
- [ key, value ]
210
- end
211
-
212
- @config["services"] = services
213
- end
214
-
215
- def build_contactgroups
216
- contactgroups = extract "contactgroup" do |key, value|
217
- value.map! do |v|
218
- parts = v.split(';')
219
- { "group_alias" => parts[0], "contacts" => parts[1] }
220
- end
221
- [ key, value ]
222
- end
223
-
224
- @config["contactgroups"] = contactgroups
225
- end
226
-
227
- def build_contacts
228
- contacts = extract "contact" do |key, value|
229
- value.map! do |v|
230
- parts = v.split(';')
231
- { "contact_alias" => parts[0], "svc_notification_period" => parts[1],
232
- "host_notification_period" => parts[2], "notify_service_recovery" => parts[3],
233
- "notify_service_critical" => parts[4], "notify_service_warning" => parts[5],
234
- "notify_host_recovery" => parts[6], "notify_host_down" => parts[7],
235
- "notify_host_unreachable" => parts[8], "service_notify_commands" => parts[9],
236
- "host_notify_commands" => parts[10], "email_address" => parts[11],
237
- "pager" => parts[12] }
238
- end
239
- [ key, value ]
240
- end
241
-
242
- @config["contacts"] = contacts
243
- end
244
-
245
- def build_hosts
246
- hosts = extract "host" do |key, value|
247
- value.map! do |v|
248
- parts = v.split(';')
249
- { "host_alias" => parts[0], "address" => parts[1],
250
- "parent_hosts" => parts[2], "host_check_command" => parts[3],
251
- "max_attempts" => parts[4], "notification_interval" => parts[5],
252
- "notification_period" => parts[6], "notify_recovery" => parts[7],
253
- "notify_down" => parts[8], "notify_unreachable" => parts[9],
254
- "event_handler" => parts[10] }
255
- end
256
- [ key, value]
257
- end
258
-
259
- @config["hosts"] = hosts
260
- end
261
-
262
- def build_commands
263
- commands = extract "command" do |key, value|
264
- value.map! do |v|
265
- parts = v.split(';')
266
- { "command_line" => parts[0] }
267
- end
268
- [ key, value]
269
- end
270
-
271
- @config["commands"] = commands
272
- end
273
-
274
- def to_hash
275
- self.read unless @raw_cfg
276
-
277
- @raw_cfg.each do |o|
278
- parts = o.scan(/^([^=]+)=(.+)$/).flatten
279
- key = parts.first
280
- value = parts.last
281
- case
282
- when @config[key] && @config[key].class == Array
283
- @config[key] << value
284
- when @config[key]
285
- @config[key] = [ @config[key] ]
286
- else
287
- @config[key] = value
288
- end
289
- end
290
-
291
- build_timeperiods
292
- build_services
293
- build_contactgroups
294
- build_contacts
295
- build_hosts
296
- build_commands
297
-
298
- @config
299
- end
300
-
301
- end
302
-
303
- class Config
304
- include Enumerable
305
-
306
- class << self
307
- attr_accessor :root, :configs, :files
308
-
309
- @@configs = []
310
- @@files = []
311
-
312
- def root=(arg)
313
- @@root = arg
314
- @@root = Pathname.new(@@root) unless @@root.class == Pathname
315
- end
316
-
317
- def build
318
- filename = @@root.join('netsaint.cfg')
319
- build_file(filename)
320
- end
321
-
322
- def build_file(filename)
323
- file = ConfigFile.new(filename)
324
- hash = file.to_hash
325
- @@files << file
326
- @@configs << hash
327
- %w(cfg_file resource_file).each do |linked_file|
328
- if hash[linked_file]
329
- hash[linked_file].each do |name|
330
- path = relativise_path(name)
331
- build_file(path)
332
- end
333
- end
334
- end
335
- end
336
-
337
- def relativise_path(filename)
338
- @@match = nil
339
- parent = @@root.dirname.dirname
340
- path = parent + filename.to_s[1..-1]
341
-
342
- path
343
- end
344
-
345
- # Makes Enumerable mixin work
346
- def each
347
- @@configs.each {|i| yield i }
348
- end
349
-
350
- # Search across all configs for a particular key.
351
- #
352
- # Can be passed a string:
353
- #
354
- # Netsaint::Config.fetch("command_check_interval") # => {"command_check_interval" => "1"}
355
- #
356
- # Or a regex:
357
- #
358
- # Netsaint::Config.fetch(/^\$USER\d+\$$/) # => { "$USER2$"=>"/tmp", "$USER1$"=>"/boot" }
359
- #
360
- def fetch(key)
361
- configs = @@configs.find_all {|c| c.keys.find {|k| k[k]} }
362
- results = configs.map {|c| Hash[c.find_all { |k,v| k[key] }] }
363
- results.inject {|final, hash| final.merge(hash) }
364
- end
365
-
366
- %w(timeperiods services contactgroups contacts hosts commands).each do |method|
367
- class_eval <<-METHOD
368
- def #{method}
369
- #{method} = {}
370
- @@configs.each do |c|
371
- c["#{method}"].each do |key, value|
372
- #{method}[key] ||= []
373
- #{method}[key] << value
374
- #{method}[key].flatten!
375
- end
376
- end
377
-
378
- #{method}
379
- end
380
- METHOD
381
- end
382
-
383
- end
384
- end
385
- end
386
-
387
- command = ARGV[0]
388
-
389
- case command
390
- when "print"
391
- options = ARGV[2..-1]
392
- options = Hash[options.map {|o| o.scan(/--(.+)=(.+)/).flatten }]
393
-
394
- netsaint_root = Pathname.new(options["source"]).expand_path
395
- Netsaint::Config.root = netsaint_root
396
- Netsaint::Config.build
397
-
398
- command = ARGV[0]
399
- type = ARGV[1]
400
-
401
- json = { type => Netsaint::Config.method(type).call }.to_json
402
-
403
- if filename = options["to"]
404
- File.open(filename, 'w') do |f|
405
- f << json
406
- end
407
- else
408
- puts json
409
- end
410
-
411
- when "dump"
412
- options = ARGV[1..-1]
413
- options = Hash[options.map {|o| o.scan(/--(.+)=(.+)/).flatten }]
414
-
415
- netsaint_root = Pathname.new(options["source"]).expand_path
416
- Netsaint::Config.root = netsaint_root
417
- Netsaint::Config.build
418
-
419
- @checks = Netsaint::Service.all.map { |service| service.to_flapjack }
420
-
421
- json = { "batch" => {"id" => 1, "created_at" => Time.now}, "checks" => @checks }.to_json
422
-
423
- if filename = options["to"]
424
- File.open(filename, 'w') do |f|
425
- f << json
426
- end
427
- puts "Dumped config to #{filename}"
428
- else
429
- puts json
430
- end
431
-
432
- end
File without changes
@@ -1,61 +0,0 @@
1
- class flapjack::common {
2
-
3
- include ruby::rubygems
4
- include sqlite3::dev
5
-
6
- $version = "0.5.3"
7
-
8
- package { "flapjack":
9
- ensure => $version,
10
- provider => gem,
11
- require => [ Package["rubygems"],
12
- Package["libsqlite3-dev"] ],
13
- }
14
-
15
- file { "/var/run/flapjack":
16
- ensure => directory,
17
- mode => 777,
18
- require => [ Package["flapjack"] ],
19
- }
20
-
21
- file { "/etc/flapjack":
22
- ensure => directory,
23
- require => [ Package["flapjack"] ],
24
- }
25
-
26
- exec { "symlink-latest-flapjack-gem":
27
- command => "ln -sf $(dirname $(dirname $(dirname $(gem which flapjack/patches)))) /usr/lib/flapjack",
28
- path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin",
29
- unless => "readlink /usr/lib/flapjack |grep -E '$version$'",
30
- require => [ Package["flapjack"] ]
31
- }
32
-
33
- exec { "populate-etc-flapjack":
34
- command => "cp $(dirname $(dirname $(dirname $(gem which flapjack))))/dist/etc/flapjack/* /etc/flapjack",
35
- creates => [ "/etc/flapjack/flapjack-notifier.conf.example", "/etc/flapjack/recipients.conf.example" ],
36
- path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin",
37
- require => [ File["/etc/flapjack"],
38
- Package["flapjack"] ],
39
- }
40
-
41
- file { "/etc/default/flapjack-workers":
42
- source => "/usr/lib/flapjack/dist/etc/default/flapjack-workers",
43
- require => [ Exec["symlink-latest-flapjack-gem"] ],
44
- }
45
-
46
- file { "/etc/default/flapjack-notifier":
47
- source => "/usr/lib/flapjack/dist/etc/default/flapjack-notifier",
48
- require => [ Exec["symlink-latest-flapjack-gem"] ],
49
- }
50
-
51
- file { "/etc/init.d/flapjack-workers":
52
- source => "/usr/lib/flapjack/dist/etc/init.d/flapjack-workers",
53
- require => [ Exec["symlink-latest-flapjack-gem"] ],
54
- }
55
-
56
- file { "/etc/init.d/flapjack-notifier":
57
- source => "/usr/lib/flapjack/dist/etc/init.d/flapjack-notifier",
58
- require => [ Exec["symlink-latest-flapjack-gem"] ],
59
- }
60
-
61
- }
@@ -1,13 +0,0 @@
1
- class flapjack::notifier {
2
- include flapjack::common
3
-
4
- service { "flapjack-notifier":
5
- enable => true,
6
- ensure => running,
7
- require => [ Package["flapjack"],
8
- Exec["populate-etc-flapjack"],
9
- File["/etc/default/flapjack-notifier"],
10
- File["/etc/init.d/flapjack-notifier"] ],
11
- }
12
-
13
- }
@@ -1,13 +0,0 @@
1
- class flapjack::worker {
2
- include flapjack::common
3
-
4
- service { "flapjack-workers":
5
- enable => true,
6
- ensure => running,
7
- require => [ Package["flapjack"],
8
- Exec["populate-etc-flapjack"],
9
- File["/etc/default/flapjack-workers"],
10
- File["/etc/init.d/flapjack-workers"] ],
11
- }
12
-
13
- }
File without changes
@@ -1,5 +0,0 @@
1
- class ruby::dev {
2
- package { "ruby-dev":
3
- ensure => present,
4
- }
5
- }
@@ -1,14 +0,0 @@
1
- class ruby::rubygems {
2
- package { "rubygems":
3
- ensure => present,
4
- tag => "puppet"
5
- }
6
-
7
- exec { "export-rubygems-path":
8
- command => "echo 'export PATH=\$PATH:/var/lib/gems/1.8/bin' >> /etc/bash.bashrc",
9
- path => "/bin:/usr/bin",
10
- unless => "grep -c '/var/lib/gems/1.8/bin' /etc/bash.bashrc",
11
- require => [ Package["rubygems"] ],
12
- tag => "puppet"
13
- }
14
- }
@@ -1,5 +0,0 @@
1
- class sqlite3::dev {
2
- package { "libsqlite3-dev":
3
- ensure => present
4
- }
5
- }