lib/flapjack/gateways/jsonapi/check_presenter.rb in flapjack-0.9.2 vs lib/flapjack/gateways/jsonapi/check_presenter.rb in flapjack-0.9.3

- old
+ new

@@ -79,11 +79,11 @@ :summary => obj[:summary] || '', :details => obj[:details] || '' } end - result + {:outages => result} end def unscheduled_maintenance(start_time, end_time) # unsched_maintenance is an array of hashes, with [duration, timestamp, summary] keys unsched_maintenance = @entity_check.maintenances(start_time, end_time, @@ -94,11 +94,11 @@ start_in_unsched = start_time.nil? ? [] : @entity_check.maintenances(nil, start_time, :scheduled => false).select {|pu| pu[:end_time] >= start_time } - start_in_unsched + unsched_maintenance + {:unscheduled_maintenances => (start_in_unsched + unsched_maintenance)} end def scheduled_maintenance(start_time, end_time) # sched_maintenance is an array of hashes, with [duration, timestamp, summary] keys sched_maintenance = @entity_check.maintenances(start_time, end_time, @@ -109,23 +109,21 @@ start_in_sched = start_time.nil? ? [] : @entity_check.maintenances(nil, start_time, :scheduled => true).select {|ps| ps[:end_time] >= start_time } - start_in_sched + sched_maintenance + {:scheduled_maintenances => (start_in_sched + sched_maintenance)} end # TODO test whether the below overlapping logic is prone to off-by-one # errors; the numbers may line up more neatly if we consider outages to # start one second after the maintenance period ends. # # TODO test performance with larger data sets def downtime(start_time, end_time) - sched_maintenances = scheduled_maintenance(start_time, end_time) + outs = outage(start_time, end_time)[:outages] - outs = outage(start_time, end_time) - total_secs = {} percentages = {} outs.collect {|obj| obj[:state]}.uniq.each do |st| total_secs[st] = 0 @@ -136,9 +134,11 @@ # Initially we need to check for cases where a scheduled # maintenance period is fully covered by an outage period. # We then create two new outage periods to cover the time around # the scheduled maintenance period, and remove the original. + + sched_maintenances = scheduled_maintenance(start_time, end_time)[:scheduled_maintenances] sched_maintenances.each do |sm| split_outs = []