flapjack 0.6.30 → 0.6.31
Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,8 @@ module Flapjack
|
|
29
29
|
hist_states.each_with_index do |obj, index|
|
30
30
|
if (index == 0)
|
31
31
|
# initial
|
32
|
-
|
32
|
+
ts = obj.delete(:timestamp)
|
33
|
+
obj[:start_time] = start_time ? [ts, start_time].max : ts
|
33
34
|
obj[:end_time] = hist_states[index + 1][:timestamp]
|
34
35
|
elsif index == (num_states - 1)
|
35
36
|
# last
|
@@ -40,7 +41,7 @@ module Flapjack
|
|
40
41
|
obj[:start_time] = obj.delete(:timestamp)
|
41
42
|
obj[:end_time] = hist_states[index + 1][:timestamp]
|
42
43
|
end
|
43
|
-
obj[:duration] = obj[:end_time] - obj[:start_time]
|
44
|
+
obj[:duration] = obj[:end_time] ? (obj[:end_time] - obj[:start_time]) : nil
|
44
45
|
end
|
45
46
|
|
46
47
|
hist_states.reject {|obj| obj[:state] == 'ok'}
|
@@ -159,11 +160,11 @@ module Flapjack
|
|
159
160
|
total_secs.each_pair do |st, ts|
|
160
161
|
percentages[st] = (total_secs[st] * 100.0) / (end_time.to_f - start_time.to_f)
|
161
162
|
end
|
163
|
+
total_secs['ok'] = (end_time - start_time) - total_secs.values.reduce(:+)
|
164
|
+
percentages['ok'] = 100 - percentages.values.reduce(:+)
|
162
165
|
end
|
163
166
|
end
|
164
167
|
|
165
|
-
total_secs['ok'] = (end_time - start_time) - total_secs.values.reduce(:+)
|
166
|
-
percentages['ok'] = 100 - percentages.values.reduce(:+)
|
167
168
|
{:total_seconds => total_secs, :percentages => percentages, :downtime => outs}
|
168
169
|
end
|
169
170
|
|
data/lib/flapjack/version.rb
CHANGED
@@ -56,6 +56,22 @@ describe 'Flapjack::API::EntityCheck::Presenter' do
|
|
56
56
|
# TODO check the data in those hashes
|
57
57
|
end
|
58
58
|
|
59
|
+
it "returns the same list of outage hashes with no start and end time set" do
|
60
|
+
entity_check.should_receive(:historical_states).
|
61
|
+
with(nil, nil).and_return(states)
|
62
|
+
|
63
|
+
entity_check.should_receive(:historical_state_before).
|
64
|
+
with(time - (4 * 60 * 60)).and_return(nil)
|
65
|
+
|
66
|
+
ecp = Flapjack::API::EntityCheckPresenter.new(entity_check)
|
67
|
+
outages = ecp.outages(nil, nil)
|
68
|
+
outages.should_not be_nil
|
69
|
+
outages.should be_an(Array)
|
70
|
+
outages.should have(4).time_ranges
|
71
|
+
|
72
|
+
# TODO check the data in those hashes
|
73
|
+
end
|
74
|
+
|
59
75
|
it "a list of unscheduled maintenances for an entity check" do
|
60
76
|
entity_check.should_receive(:maintenances).
|
61
77
|
with(time - (12 * 60 * 60), time, :scheduled => false).and_return(maintenances)
|
@@ -88,7 +104,7 @@ describe 'Flapjack::API::EntityCheck::Presenter' do
|
|
88
104
|
# TODO check the data in those hashes
|
89
105
|
end
|
90
106
|
|
91
|
-
it "returns downtime and percentage for
|
107
|
+
it "returns downtime and percentage for a downtime check" do
|
92
108
|
entity_check.should_receive(:historical_states).
|
93
109
|
with(time - (12 * 60 * 60), time).and_return(states)
|
94
110
|
|
@@ -117,4 +133,27 @@ describe 'Flapjack::API::EntityCheck::Presenter' do
|
|
117
133
|
downtimes[:downtime].should have(4).time_ranges
|
118
134
|
end
|
119
135
|
|
136
|
+
it "returns downtime (but no percentage) for an unbounded downtime check" do
|
137
|
+
entity_check.should_receive(:historical_states).
|
138
|
+
with(nil, nil).and_return(states)
|
139
|
+
|
140
|
+
entity_check.should_receive(:historical_state_before).
|
141
|
+
with(time - (4 * 60 * 60)).and_return(nil)
|
142
|
+
|
143
|
+
entity_check.should_receive(:maintenances).
|
144
|
+
with(nil, nil, :scheduled => true).and_return(maintenances)
|
145
|
+
|
146
|
+
ecp = Flapjack::API::EntityCheckPresenter.new(entity_check)
|
147
|
+
downtimes = ecp.downtime(nil, nil)
|
148
|
+
|
149
|
+
# 22 minutes, 3 + 8 + 11
|
150
|
+
downtimes.should be_a(Hash)
|
151
|
+
downtimes[:total_seconds].should == {'critical' => (22 * 60)}
|
152
|
+
downtimes[:percentages].should == {'critical' => nil}
|
153
|
+
downtimes[:downtime].should be_an(Array)
|
154
|
+
# the last outage gets split by the intervening maintenance period,
|
155
|
+
# but the fully covered one gets removed.
|
156
|
+
downtimes[:downtime].should have(4).time_ranges
|
157
|
+
end
|
158
|
+
|
120
159
|
end
|