flapjack 0.9.6 → 1.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +6 -0
  4. data/.travis.yml +20 -16
  5. data/CHANGELOG.md +11 -25
  6. data/Dockerfile +8 -0
  7. data/Gemfile +2 -5
  8. data/bin/flapjack +24 -213
  9. data/etc/flapjack_config.yaml.example +6 -30
  10. data/features/cli.feature +16 -14
  11. data/features/cli_flapjack-feed-events.feature +12 -13
  12. data/features/cli_flapjack-nagios-receiver.feature +14 -15
  13. data/features/cli_flapjack-populator.feature +16 -15
  14. data/features/cli_flapper.feature +12 -12
  15. data/features/cli_receive-events.feature +6 -5
  16. data/features/cli_simulate-failed-check.feature +7 -6
  17. data/features/steps/cli_steps.rb +2 -2
  18. data/features/support/env.rb +1 -0
  19. data/flapjack.gemspec +1 -0
  20. data/lib/flapjack/cli/flapper.rb +200 -0
  21. data/lib/flapjack/cli/import.rb +102 -0
  22. data/lib/flapjack/cli/receiver.rb +656 -0
  23. data/lib/flapjack/cli/server.rb +256 -0
  24. data/lib/flapjack/cli/simulate.rb +180 -0
  25. data/lib/flapjack/configuration.rb +2 -0
  26. data/lib/flapjack/data/entity_check.rb +5 -22
  27. data/lib/flapjack/data/event.rb +7 -12
  28. data/lib/flapjack/gateways/email.rb +4 -1
  29. data/lib/flapjack/gateways/jabber.rb +12 -36
  30. data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
  31. data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
  32. data/lib/flapjack/gateways/pagerduty.rb +1 -1
  33. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
  34. data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
  35. data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
  36. data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
  37. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
  38. data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
  39. data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
  40. data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
  41. data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
  42. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
  43. data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
  44. data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
  45. data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
  46. data/lib/flapjack/gateways/web/views/layout.erb +10 -10
  47. data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
  48. data/lib/flapjack/gateways/web.rb +36 -7
  49. data/lib/flapjack/pikelet.rb +0 -2
  50. data/lib/flapjack/processor.rb +3 -1
  51. data/lib/flapjack/redis_pool.rb +2 -6
  52. data/lib/flapjack/version.rb +1 -1
  53. data/spec/lib/flapjack/coordinator_spec.rb +3 -3
  54. data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
  55. data/spec/lib/flapjack/data/event_spec.rb +0 -31
  56. data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
  57. data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
  58. data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
  59. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
  60. data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
  61. data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
  62. data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
  63. data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
  64. data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
  65. data/spec/support/profile_all_formatter.rb +44 -0
  66. data/spec/support/uncolored_doc_formatter.rb +9 -0
  67. data/tasks/benchmarks.rake +0 -4
  68. metadata +28 -38
  69. data/.ruby-version +0 -1
  70. data/Gemfile-ruby1.9 +0 -28
  71. data/Gemfile-ruby1.9.lock +0 -227
  72. data/bin/flapjack-feed-events +0 -124
  73. data/bin/flapjack-nagios-receiver +0 -246
  74. data/bin/flapjack-nsca-receiver +0 -246
  75. data/bin/flapjack-populator +0 -132
  76. data/bin/flapper +0 -152
  77. data/bin/receive-events +0 -179
  78. data/bin/simulate-failed-check +0 -151
  79. data/lib/flapjack/data/migration.rb +0 -36
  80. data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
  81. data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
  82. data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
  83. data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
  84. data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
  85. data/lib/flapjack/gateways/api.rb +0 -124
  86. data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
  87. data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
  88. data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
  89. data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
  90. data/spec/lib/flapjack/gateways/api_spec.rb +0 -30
@@ -1,211 +0,0 @@
1
- require 'spec_helper'
2
- require 'flapjack/gateways/api/entity_check_presenter'
3
-
4
- describe 'Flapjack::Gateways::API::EntityCheckPresenter' do
5
-
6
- let(:entity_check) { double(Flapjack::Data::EntityCheck) }
7
-
8
- let(:time) { Time.now.to_i }
9
-
10
- let(:states) {
11
- [{:state => 'critical', :timestamp => time - (4 * 60 * 60)},
12
- {:state => 'ok', :timestamp => time - (4 * 60 * 60) + (5 * 60)},
13
- {:state => 'critical', :timestamp => time - (3 * 60 * 60)},
14
- {:state => 'ok', :timestamp => time - (3 * 60 * 60) + (10 * 60)},
15
- {:state => 'critical', :timestamp => time - (2 * 60 * 60)},
16
- {:state => 'ok', :timestamp => time - (2 * 60 * 60) + (15 * 60)},
17
- {:state => 'critical', :timestamp => time - (1 * 60 * 60)},
18
- {:state => 'ok', :timestamp => time - (1 * 60 * 60) + (20 * 60)}
19
- ]
20
- }
21
-
22
- # one overlap at start, one overlap at end, one wholly overlapping,
23
- # one wholly contained
24
- let(:maintenances) {
25
- [{:start_time => time - ((4 * 60 * 60) + (1 * 60)), # 1 minute before outage starts
26
- :end_time => time - (4 * 60 * 60) + (2 * 60), # 2 minutes after outage starts
27
- :duration => (3 * 60)},
28
- {:start_time => time - (3 * 60 * 60) + (8 * 60), # 2 minutes before outage ends
29
- :end_time => time - (3 * 60 * 60) + (11 * 60), # 1 minute after outage ends
30
- :duration => (3 * 60)},
31
- {:start_time => time - ((2 * 60 * 60) + (1 * 60)), # 1 minute before outage starts
32
- :end_time => time - (2 * 60 * 60) + (17 * 60), # 2 minutes after outage ends
33
- :duration => (3 * 60)},
34
- {:start_time => time - (1 * 60 * 60) + (1 * 60), # 1 minute after outage starts
35
- :end_time => time - (1 * 60 * 60) + (10 * 60), # 10 minutes before outage ends
36
- :duration => (9 * 60)}
37
- ]
38
- }
39
-
40
- it "returns a list of outage hashes for an entity check" do
41
- expect(entity_check).to receive(:historical_states).
42
- with(time - (5 * 60 * 60), time - (2 * 60 * 60)).and_return(states)
43
-
44
- expect(entity_check).to receive(:historical_state_before).
45
- with(time - (4 * 60 * 60)).and_return(nil)
46
-
47
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
48
- outages = ecp.outages(time - (5 * 60 * 60), time - (2 * 60 * 60))
49
- expect(outages).not_to be_nil
50
- expect(outages).to be_an(Array)
51
- expect(outages.size).to eq(4)
52
-
53
- # TODO check the data in those hashes
54
- end
55
-
56
- it "returns a list of outage hashes with no start and end time set" do
57
- expect(entity_check).to receive(:historical_states).
58
- with(nil, nil).and_return(states)
59
-
60
- expect(entity_check).to receive(:historical_state_before).
61
- with(time - (4 * 60 * 60)).and_return(nil)
62
-
63
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
64
- outages = ecp.outages(nil, nil)
65
- expect(outages).not_to be_nil
66
- expect(outages).to be_an(Array)
67
- expect(outages.size).to eq(4)
68
-
69
- # TODO check the data in those hashes
70
- end
71
-
72
- it "returns a consolidated list of outage hashes with repeated state events" do
73
- states[1][:state] = 'critical'
74
- states[2][:state] = 'ok'
75
-
76
- expect(entity_check).to receive(:historical_states).
77
- with(nil, nil).and_return(states)
78
-
79
- expect(entity_check).to receive(:historical_state_before).
80
- with(time - (4 * 60 * 60)).and_return(nil)
81
-
82
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
83
- outages = ecp.outages(nil, nil)
84
- expect(outages).not_to be_nil
85
- expect(outages).to be_an(Array)
86
- expect(outages.size).to eq(3)
87
- end
88
-
89
- it "returns a (small) outage hash for a single state change" do
90
- expect(entity_check).to receive(:historical_states).
91
- with(nil, nil).and_return([{:state => 'critical', :timestamp => time - (4 * 60 * 60)}])
92
- expect(entity_check).to receive(:historical_state_before).
93
- with(time - (4 * 60 * 60)).and_return(nil)
94
-
95
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
96
- outages = ecp.outages(nil, nil)
97
- expect(outages).not_to be_nil
98
- expect(outages).to be_an(Array)
99
- expect(outages.size).to eq(1)
100
- end
101
-
102
- it "a list of unscheduled maintenances for an entity check" do
103
- expect(entity_check).to receive(:maintenances).
104
- with(time - (12 * 60 * 60), time, :scheduled => false).and_return(maintenances)
105
-
106
- expect(entity_check).to receive(:maintenances).
107
- with(nil, time - (12 * 60 * 60), :scheduled => false).and_return([])
108
-
109
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
110
- unsched_maint = ecp.unscheduled_maintenances(time - (12 * 60 * 60), time)
111
-
112
- expect(unsched_maint).to be_an(Array)
113
- expect(unsched_maint.size).to eq(4)
114
-
115
- # TODO check the data in those hashes
116
- end
117
-
118
- it "a list of scheduled maintenances for an entity check" do
119
- expect(entity_check).to receive(:maintenances).
120
- with(time - (12 * 60 * 60), time, :scheduled => true).and_return(maintenances)
121
-
122
- expect(entity_check).to receive(:maintenances).
123
- with(nil, time - (12 * 60 * 60), :scheduled => true).and_return([])
124
-
125
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
126
- sched_maint = ecp.scheduled_maintenances(time - (12 * 60 * 60), time)
127
-
128
- expect(sched_maint).to be_an(Array)
129
- expect(sched_maint.size).to eq(4)
130
-
131
- # TODO check the data in those hashes
132
- end
133
-
134
- it "returns downtime and percentage for a downtime check" do
135
- expect(entity_check).to receive(:historical_states).
136
- with(time - (12 * 60 * 60), time).and_return(states)
137
-
138
- expect(entity_check).to receive(:historical_state_before).
139
- with(time - (4 * 60 * 60)).and_return(nil)
140
-
141
- expect(entity_check).to receive(:maintenances).
142
- with(time - (12 * 60 * 60), time, :scheduled => true).and_return(maintenances)
143
-
144
- expect(entity_check).to receive(:maintenances).
145
- with(nil, time - (12 * 60 * 60), :scheduled => true).and_return([])
146
-
147
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
148
- downtimes = ecp.downtime(time - (12 * 60 * 60), time)
149
-
150
- # 22 minutes, 3 + 8 + 11
151
- expect(downtimes).to be_a(Hash)
152
- expect(downtimes[:total_seconds]).to eq({'critical' => (22 * 60),
153
- 'ok' => ((12 * 60 * 60) - (22 * 60))})
154
- expect(downtimes[:percentages]).to eq({'critical' => (((22 * 60) * 100.0) / (12 * 60 * 60)),
155
- 'ok' => ((((12 * 60 * 60) - (22 * 60)) * 100.0) / (12 * 60 *60))})
156
- expect(downtimes[:downtime]).to be_an(Array)
157
- # the last outage gets split by the intervening maintenance period,
158
- # but the fully covered one gets removed.
159
- expect(downtimes[:downtime].size).to eq(4)
160
- end
161
-
162
- it "returns downtime (but no percentage) for an unbounded downtime check" do
163
- expect(entity_check).to receive(:historical_states).
164
- with(nil, nil).and_return(states)
165
-
166
- expect(entity_check).to receive(:historical_state_before).
167
- with(time - (4 * 60 * 60)).and_return(nil)
168
-
169
- expect(entity_check).to receive(:maintenances).
170
- with(nil, nil, :scheduled => true).and_return(maintenances)
171
-
172
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
173
- downtimes = ecp.downtime(nil, nil)
174
-
175
- # 22 minutes, 3 + 8 + 11
176
- expect(downtimes).to be_a(Hash)
177
- expect(downtimes[:total_seconds]).to eq({'critical' => (22 * 60)})
178
- expect(downtimes[:percentages]).to eq({'critical' => nil})
179
- expect(downtimes[:downtime]).to be_an(Array)
180
- # the last outage gets split by the intervening maintenance period,
181
- # but the fully covered one gets removed.
182
- expect(downtimes[:downtime].size).to eq(4)
183
- end
184
-
185
- it "returns downtime and handles an unfinished problem state" do
186
- current = [{:state => 'critical', :timestamp => time - (4 * 60 * 60)},
187
- {:state => 'ok', :timestamp => time - (4 * 60 * 60) + (5 * 60)},
188
- {:state => 'critical', :timestamp => time - (3 * 60 * 60)}]
189
-
190
- expect(entity_check).to receive(:historical_states).
191
- with(nil, nil).and_return(current)
192
-
193
- expect(entity_check).to receive(:historical_state_before).
194
- with(time - (4 * 60 * 60)).and_return(nil)
195
-
196
- expect(entity_check).to receive(:maintenances).
197
- with(nil, nil, :scheduled => true).and_return([])
198
-
199
- ecp = Flapjack::Gateways::API::EntityCheckPresenter.new(entity_check)
200
- downtimes = ecp.downtime(nil, nil)
201
-
202
- expect(downtimes).to be_a(Hash)
203
- expect(downtimes[:total_seconds]).to eq({'critical' => (5 * 60)})
204
- expect(downtimes[:percentages]).to eq({'critical' => nil})
205
- expect(downtimes[:downtime]).to be_an(Array)
206
- # the last outage gets split by the intervening maintenance period,
207
- # but the fully covered one gets removed.
208
- expect(downtimes[:downtime].size).to eq(2)
209
- end
210
-
211
- end