flapjack 1.1.0 → 1.2.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +12 -7
  5. data/CHANGELOG.md +12 -0
  6. data/Gemfile +6 -2
  7. data/Gemfile-ruby1.9 +29 -0
  8. data/Gemfile-ruby1.9.lock +251 -0
  9. data/README.md +2 -2
  10. data/Rakefile +1 -0
  11. data/etc/flapjack_config.yaml.example +2 -2
  12. data/features/steps/events_steps.rb +2 -2
  13. data/features/steps/flapjack-netsaint-parser_steps.rb +1 -1
  14. data/features/support/env.rb +1 -6
  15. data/lib/flapjack/cli/import.rb +2 -5
  16. data/lib/flapjack/cli/purge.rb +4 -4
  17. data/lib/flapjack/cli/receiver.rb +122 -54
  18. data/lib/flapjack/cli/server.rb +0 -5
  19. data/lib/flapjack/coordinator.rb +6 -0
  20. data/lib/flapjack/data/contact.rb +10 -62
  21. data/lib/flapjack/data/entity.rb +36 -52
  22. data/lib/flapjack/data/entity_check.rb +90 -21
  23. data/lib/flapjack/data/event.rb +4 -5
  24. data/lib/flapjack/data/notification.rb +8 -10
  25. data/lib/flapjack/data/notification_rule.rb +32 -35
  26. data/lib/flapjack/data/tagged.rb +48 -0
  27. data/lib/flapjack/gateways/jabber.rb +4 -5
  28. data/lib/flapjack/gateways/jsonapi/check_methods.rb +45 -7
  29. data/lib/flapjack/gateways/jsonapi/check_presenter.rb +1 -1
  30. data/lib/flapjack/gateways/jsonapi/contact_methods.rb +8 -2
  31. data/lib/flapjack/gateways/jsonapi/entity_methods.rb +26 -8
  32. data/lib/flapjack/gateways/jsonapi/medium_methods.rb +13 -9
  33. data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +2 -2
  34. data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +1 -1
  35. data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +24 -17
  36. data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +1 -1
  37. data/lib/flapjack/gateways/jsonapi/report_methods.rb +4 -4
  38. data/lib/flapjack/gateways/jsonapi.rb +52 -31
  39. data/lib/flapjack/gateways/oobetet.rb +2 -3
  40. data/lib/flapjack/gateways/pagerduty.rb +9 -8
  41. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +19 -0
  42. data/lib/flapjack/gateways/web/public/js/flapjack.js +6 -2
  43. data/lib/flapjack/gateways/web/public/js/modules/contact.js +9 -14
  44. data/lib/flapjack/gateways/web/public/js/modules/medium.js +1 -0
  45. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
  46. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +3 -3
  47. data/lib/flapjack/gateways/web.rb +8 -7
  48. data/lib/flapjack/notifier.rb +2 -4
  49. data/lib/flapjack/processor.rb +2 -2
  50. data/lib/flapjack/version.rb +1 -1
  51. data/lib/flapjack.rb +10 -0
  52. data/spec/lib/flapjack/coordinator_spec.rb +18 -0
  53. data/spec/lib/flapjack/data/contact_spec.rb +4 -12
  54. data/spec/lib/flapjack/data/entity_check_spec.rb +56 -3
  55. data/spec/lib/flapjack/data/entity_spec.rb +79 -67
  56. data/spec/lib/flapjack/data/event_spec.rb +78 -78
  57. data/spec/lib/flapjack/data/notification_rule_spec.rb +4 -2
  58. data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +94 -11
  59. data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +84 -0
  60. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -3
  61. data/spec/lib/flapjack/gateways/web_spec.rb +3 -3
  62. data/spec/service_consumers/pact_helper.rb +74 -0
  63. data/spec/service_consumers/pacts/flapjack-diner_v1.0.json +4522 -0
  64. data/spec/service_consumers/provider_states_for_flapjack-diner.rb +356 -0
  65. data/spec/spec_helper.rb +0 -8
  66. data/spec/support/jsonapi_helper.rb +1 -1
  67. data/tasks/benchmarks.rake +6 -3
  68. data/tasks/profile.rake +1 -1
  69. data/tmp/acknowledge.rb +0 -3
  70. data/tmp/create_event_ok.rb +0 -3
  71. data/tmp/create_event_unknown.rb +0 -3
  72. data/tmp/create_events_failure.rb +0 -3
  73. data/tmp/create_events_ok.rb +0 -3
  74. data/tmp/create_events_ok_fail_ack_ok.rb +0 -3
  75. data/tmp/create_events_ok_failure.rb +2 -5
  76. data/tmp/create_events_ok_failure_ack.rb +0 -3
  77. data/tmp/test_json_post.rb +4 -3
  78. data/tmp/test_notification_rules_api.rb +2 -3
  79. metadata +13 -8
  80. data/lib/flapjack/data/tag.rb +0 -61
  81. data/lib/flapjack/data/tag_set.rb +0 -16
  82. data/spec/lib/flapjack/data/tag_spec.rb +0 -36
@@ -151,7 +151,7 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
151
151
  evt = { "service_key" => "11111111111111111111111111111111",
152
152
  "incident_key" => "Flapjack is running a NOOP",
153
153
  "event_type" => "nop",
154
- "description" => "I love APIs with noops." }
154
+ "description" => "I love APIs with noops."}
155
155
  body = evt.to_json
156
156
 
157
157
  stub_request(:post, "https://events.pagerduty.com/generic/2010-04-15/create_event.json").
@@ -169,9 +169,11 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
169
169
 
170
170
  it "sends an event to pagerduty" do
171
171
  evt = {"service_key" => "abcdefg",
172
- "incident_key" => "Flapjack test",
172
+ "incident_key" => "www.example.com:ssh",
173
173
  "event_type" => "nop",
174
- "description" => "Not really sent anyway"}
174
+ "description" => "Not really sent anyway",
175
+ "details" => { 'HOSTNAME' => 'www.example.com', 'SERVICE' => 'ssh' }
176
+ }
175
177
  body = evt.to_json
176
178
 
177
179
  stub_request(:post, "https://events.pagerduty.com/generic/2010-04-15/create_event.json").
@@ -44,7 +44,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
44
44
  def expect_entity_stats
45
45
  expect(Flapjack::Data::Entity).to receive(:all).
46
46
  with(:enabled => true, :redis => redis).and_return([entity_name])
47
- expect(Flapjack::Data::Entity).to receive(:find_all_with_failing_checks).
47
+ expect(Flapjack::Data::Entity).to receive(:find_all_names_with_failing_checks).
48
48
  with(:redis => redis).and_return([entity_name])
49
49
  end
50
50
 
@@ -120,7 +120,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
120
120
 
121
121
  it "shows a page listing all checks" do
122
122
  #redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}"])
123
- expect(Flapjack::Data::EntityCheck).to receive(:find_current_by_entity).
123
+ expect(Flapjack::Data::EntityCheck).to receive(:find_current_names_by_entity).
124
124
  with(:redis => redis).and_return({entity_name => [check]})
125
125
  expect_check_stats
126
126
 
@@ -146,7 +146,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
146
146
  expect(Flapjack::Data::Entity).to receive(:find_by_name).
147
147
  with(entity_name, :redis => redis).and_return(entity)
148
148
 
149
- expect(Flapjack::Data::EntityCheck).to receive(:find_current_failing_by_entity).
149
+ expect(Flapjack::Data::EntityCheck).to receive(:find_current_names_failing_by_entity).
150
150
  with(:redis => redis).and_return({entity_name => [check]})
151
151
 
152
152
  expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
@@ -0,0 +1,74 @@
1
+ require 'pact/provider/rspec'
2
+
3
+ require 'flapjack/configuration'
4
+ require 'flapjack/gateways/jsonapi'
5
+
6
+ require './spec/service_consumers/provider_states_for_flapjack-diner.rb'
7
+
8
+ $testing = true
9
+
10
+ FLAPJACK_ENV = ENV["FLAPJACK_ENV"] || 'test'
11
+ FLAPJACK_ROOT = File.join(File.dirname(__FILE__), '..')
12
+ FLAPJACK_CONFIG = File.join(FLAPJACK_ROOT, 'etc', 'flapjack_config.yaml')
13
+ ENV['RACK_ENV'] = ENV["FLAPJACK_ENV"]
14
+
15
+ require 'bundler'
16
+ Bundler.require(:default, :test)
17
+
18
+ class MockLogger
19
+ attr_accessor :messages
20
+
21
+ def initialize
22
+ @messages = []
23
+ end
24
+
25
+ %w(debug info warn error fatal).each do |level|
26
+ class_eval <<-RUBY
27
+ def #{level}?
28
+ true
29
+ end
30
+
31
+ def #{level}(msg)
32
+ @messages << msg
33
+ end
34
+ RUBY
35
+ end
36
+ end
37
+
38
+ Flapjack::Gateways::JSONAPI.instance_variable_get('@middleware').delete_if {|m|
39
+ m[0] == Rack::FiberPool
40
+ }
41
+
42
+ Flapjack::Gateways::JSONAPI.class_eval do
43
+ set :show_exceptions, false
44
+ set :raise_errors, false
45
+ error do
46
+ Flapjack::Gateways::JSONAPI.instance_variable_get('@rescue_exception').
47
+ call(env, env['sinatra.error'])
48
+ end
49
+ end
50
+
51
+ cfg = Flapjack::Configuration.new
52
+ $redis_options = cfg.load(FLAPJACK_CONFIG) ?
53
+ cfg.for_redis :
54
+ {:db => 14, :driver => :ruby}
55
+
56
+ Flapjack::Gateways::JSONAPI.instance_variable_set('@config', 'port' => 19081)
57
+
58
+ Flapjack::Gateways::JSONAPI.instance_variable_set('@redis_config', $redis_options)
59
+ Flapjack::Gateways::JSONAPI.instance_variable_set('@logger', MockLogger.new)
60
+
61
+ Flapjack::Gateways::JSONAPI.start
62
+
63
+ Pact.configure do |config|
64
+
65
+ end
66
+
67
+ Pact.service_provider "flapjack" do
68
+
69
+ app { Flapjack::Gateways::JSONAPI.new }
70
+
71
+ honours_pact_with 'flapjack-diner' do
72
+ pact_uri './spec/service_consumers/pacts/flapjack-diner_v1.0.json'
73
+ end
74
+ end