Skip to content

Commit

Permalink
revert some of the media interval changes, not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-graham committed Nov 5, 2014
1 parent f8b01fc commit 0c9e2c4
Show file tree
Hide file tree
Showing 17 changed files with 1,197 additions and 1,243 deletions.
22 changes: 11 additions & 11 deletions features/notification_rules.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ Feature: Notification rules on a per contact basis
| c5 | Wang Fang Wong | Asia/Shanghai |

And the following media exist:
| id | contact_id | type | address | initial_failure_interval | repeat_failure_interval | rollup_threshold |
| m1e | c1 | email | malak@example.com | 15 | 15 | 5 |
| m1s | c1 | sms | +61400000001 | 60 | 15 | 5 |
| m2e | c2 | email | imani@example.com | 15 | 15 | 5 |
| m2s | c2 | sms | +61400000002 | 60 | 15 | 5 |
| m3e | c3 | email | vera@example.com | 15 | 15 | 5 |
| m3s | c3 | sms | +61400000003 | 60 | 15 | 5 |
| m4e | c4 | email | lucia@example.com | 15 | 15 | 5 |
| m4s | c4 | sms | +61400000004 | 60 | 15 | 5 |
| m5e | c5 | email | fang@example.com | 15 | 15 | 5 |
| m5s | c5 | sms | +61400000005 | 60 | 15 | 5 |
| id | contact_id | type | address | interval | rollup_threshold |
| m1e | c1 | email | malak@example.com | 15 | 5 |
| m1s | c1 | sms | +61400000001 | 60 | 5 |
| m2e | c2 | email | imani@example.com | 15 | 5 |
| m2s | c2 | sms | +61400000002 | 60 | 5 |
| m3e | c3 | email | vera@example.com | 15 | 5 |
| m3s | c3 | sms | +61400000003 | 60 | 5 |
| m4e | c4 | email | lucia@example.com | 15 | 5 |
| m4s | c4 | sms | +61400000004 | 60 | 5 |
| m5e | c5 | email | fang@example.com | 15 | 5 |
| m5s | c5 | sms | +61400000005 | 60 | 5 |

And the following checks exist:
| id | name | tags |
Expand Down
6 changes: 3 additions & 3 deletions features/rollup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Feature: Rollup on a per contact, per media basis
| c1 | Malak Al-Musawi | Asia/Baghdad |

And the following media exist:
| id | contact_id | type | address | initial_failure_interval | repeat_failure_interval | rollup_threshold |
| m1e | c1 | email | malak@example.com | 15 | 15 | 1 |
| m1s | c1 | sms | +61400000001 | 60 | 15 | 2 |
| id | contact_id | type | address | interval | rollup_threshold |
| m1e | c1 | email | malak@example.com | 15 | 1 |
| m1s | c1 | sms | +61400000001 | 15 | 2 |

And the following checks exist:
| id | name | tags |
Expand Down
17 changes: 8 additions & 9 deletions features/steps/notifications_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ def find_or_create_check(check_data)
medium = Flapjack::Data::Medium.find_by_id(medium_data['id'])
expect(medium).to be nil
medium = Flapjack::Data::Medium.new(
:id => medium_data['id'],
:type => medium_data['type'],
:address => medium_data['address'],
:initial_failure_interval => medium_data['initial_failure_interval'].to_i * 60,
:repeat_failure_interval => medium_data['repeat_failure_interval'].to_i * 60,
:rollup_threshold => medium_data['rollup_threshold'].to_i
:id => medium_data['id'],
:type => medium_data['type'],
:address => medium_data['address'],
:interval => medium_data['interval'].to_i * 60,
:rollup_threshold => medium_data['rollup_threshold'].to_i
)
expect(medium.save).to be true
contact.media << medium
Expand Down Expand Up @@ -174,7 +173,7 @@ def find_or_create_check(check_data)
'name' => 'John Smith')

sms = Flapjack::Data::Medium.new(:type => 'sms',
:address => '+61888888888', :initial_failure_interval => 600, :repeat_failure_interval => 600)
:address => '+61888888888', :interval => 600)
expect(sms.save).to be true
contact.media << sms

Expand Down Expand Up @@ -211,7 +210,7 @@ def find_or_create_check(check_data)
'name' => 'Jane Smith')

email = Flapjack::Data::Medium.new(:type => 'email',
:address => '[email protected]', :initial_failure_interval => 600, :repeat_failure_interval => 600)
:address => '[email protected]', :interval => 600)
expect(email.save).to be true
contact.media << email

Expand Down Expand Up @@ -247,7 +246,7 @@ def find_or_create_check(check_data)
'name' => 'James Smithson')

sns = Flapjack::Data::Medium.new(:type => 'sns',
:address => 'arn:aws:sns:us-east-1:698519295917:My-Topic', :initial_failure_interval => 600, :repeat_failure_interval => 600)
:address => 'arn:aws:sns:us-east-1:698519295917:My-Topic', :interval => 600)
expect(sns.save).to be true
contact.media << sns

Expand Down
11 changes: 3 additions & 8 deletions lib/flapjack/cli/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,15 @@ def contacts
unless media_data.nil? || media_data.empty?
media_data.each_pair do |type, medium_data|

ifi = medium_data['initial_failure_interval'].to_i
ifi = nil unless ifi >= 0

rfi = medium_data['repeat_failure_interval'].to_i
rfi = nil unless rfi >= 0
itv = medium_data['interval'].to_i
itv = nil unless itv >= 0

rut = medium_data['rollup_threshold'].to_i
rut = nil unless rut > 0

medium = Flapjack::Data::Medium.new(:type => type,
:address => medium_data['address'],
:initial_failure_interval => ifi,
:repeat_failure_interval => rfi,
:rollup_threshold => rut)
:interval => itv, :rollup_threshold => rut)
medium.save
contact.media << medium
end
Expand Down
7 changes: 2 additions & 5 deletions lib/flapjack/data/medium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Medium

define_attributes :type => :string,
:address => :string,
:initial_failure_interval => :integer,
:repeat_failure_interval => :integer,
:interval => :integer,
:rollup_threshold => :integer,
:last_rollup_type => :string,
:last_notification => :timestamp,
Expand All @@ -40,9 +39,7 @@ class Medium
validates :type, :presence => true,
:inclusion => {:in => Flapjack::Data::Medium::TYPES }
validates :address, :presence => true
validates :initial_failure_interval, :presence => true,
:numericality => {:greater_than_or_equal_to => 0, :only_integer => true}
validates :repeat_failure_interval, :presence => true,
validates :interval, :presence => true,
:numericality => {:greater_than_or_equal_to => 0, :only_integer => true}
validates :rollup_threshold, :allow_blank => true,
:numericality => {:greater_than => 0, :only_integer => true}
Expand Down
6 changes: 2 additions & 4 deletions lib/flapjack/gateways/jsonapi/medium_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def self.registered(app)
Flapjack::Data::Medium.new(:id => medium_data['id'],
:type => medium_data['type'],
:address => medium_data['address'],
:initial_failure_interval => medium_data['initial_failure_interval'],
:repeat_failure_interval => medium_data['repeat_failure_interval'],
:interval => medium_data['interval'],
:rollup_threshold => medium_data['rollup_threshold'])
end

Expand Down Expand Up @@ -113,8 +112,7 @@ def self.registered(app)
case op

when 'replace'
if ['type', 'address', 'initial_failure_interval',
'repeat_failure_interval', 'rollup_threshold'].include?(property)
if ['type', 'address', 'interval', 'rollup_threshold'].include?(property)
medium.send("#{property}=".to_sym, value)
end

Expand Down
18 changes: 6 additions & 12 deletions lib/flapjack/gateways/web/public/js/modules/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@
medium = new Medium.Model({
type: type,
address: '',
initial_failure_interval: 15,
repeat_failure_interval: 15,
interval: 15,
rollup_threshold: 3,
});
context.collection.add(medium);
Expand Down Expand Up @@ -313,10 +312,9 @@
Contact.Views.MediaListItem = Backbone.View.extend({
tagName: 'tr',
events: {
"change input[data-attr='address']" : 'setAddress',
"change input[data-attr='initial_failure_interval']" : 'setInitialFailureInterval',
"change input[data-attr='repeat_failure_interval']" : 'setRepeatFailureInterval',
"change input[data-attr='rollup_threshold']" : 'setRollupThreshold'
"change input[data-attr='address']" : 'setAddress',
"change input[data-attr='interval']" : 'setInterval',
"change input[data-attr='rollup_threshold']" : 'setRollupThreshold'
},
initialize: function() {
this.template = _.template($('#contact-media-list-item-template').html());
Expand All @@ -338,12 +336,8 @@
this.model.set('address', $(event.target).val());
if ( this.model.isValid() ) { this.addOrUpdate(this.model); }
},
setInitialFailureInterval: function(event) {
this.model.set('initial_failure_interval', $(event.target).val());
if ( this.model.isValid() ) { this.addOrUpdate(this.model); }
},
setRepeatFailureInterval: function(event) {
this.model.set('repeat_failure_interval', $(event.target).val());
setInterval: function(event) {
this.model.set('interval', $(event.target).val());
if ( this.model.isValid() ) { this.addOrUpdate(this.model); }
},
setRollupThreshold: function(event) {
Expand Down
6 changes: 2 additions & 4 deletions lib/flapjack/gateways/web/public/js/modules/medium.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
defaults: {
type: null,
address: '',
initial_failure_interval: 60,
repeat_failure_interval: 60,
interval: 60,
rollup_threshold: 3,
id: null,
links: {},
},
toJSON: function() {
return _.pick(this.attributes, 'id', 'type', 'address',
'initial_failure_interval', 'repeat_failure_interval',
'rollup_threshold');
'interval', 'rollup_threshold');
},
sync: function(method, model, options) {
if ( method == 'create') {
Expand Down
14 changes: 3 additions & 11 deletions lib/flapjack/gateways/web/views/contact.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<tr>
<th>Media</th>
<th>Address</th>
<th>Initial Interval</th>
<th>Repeat Interval</th>
<th>Interval</th>
<th>Summary Mode</th>
<th>Summary Threshold</th>
</tr>
Expand All @@ -40,15 +39,8 @@
<% end %>
<td><%= h med.address %></td>
<td>
<% if med.initial_failure_interval %>
<%= h med.initial_failure_interval %> seconds
<% else %>
no custom interval
<% end %>
</td>
<td>
<% if med.repeat_failure_interval %>
<%= h med.repeat_failure_interval %> seconds
<% if med.interval %>
<%= h med.interval %> seconds
<% else %>
no custom interval
<% end %>
Expand Down
8 changes: 2 additions & 6 deletions lib/flapjack/gateways/web/views/edit_contacts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
<tr>
<th style="width: 15%">Media</th>
<th style="width: 55%">Address</th>
<th style="width: 10%">Initial Interval</th>
<th style="width: 10%">Repeat Interval</th>
<th style="width: 10%">Interval</th>
<th style="width: 10%">Rollup</th>
</tr>
</thead>
Expand All @@ -87,10 +86,7 @@
<input type="text" id="<@- labels[type] @>-address" data-attr="address" class="form-control" value="<@- address @>">
</td>
<td>
<input type="text" id="<@- labels[type] @>-initial_failure_interval" data-attr="initial_failure_interval" class="form-control" value="<@- initial_failure_interval @>">
</td>
<td>
<input type="text" id="<@- labels[type] @>-repeat_failure_interval" data-attr="repeat_failure_interval" class="form-control" value="<@- repeat_failure_interval @>">
<input type="text" id="<@- labels[type] @>-interval" data-attr="interval" class="form-control" value="<@- interval @>">
</td>
<td>
<input type="text" id="<@- labels[type] @>-rollup_threshold" data-attr="rollup_threshold" class="form-control <@- labels[type] @>-rollup_threshold" value="<@- rollup_threshold @>">
Expand Down
4 changes: 1 addition & 3 deletions lib/flapjack/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,8 @@ def self.alerts_for(notification, route_ids_by_contact_id, opts = {})
end

interval_allows = medium.last_notification.nil? ||
((last_notification_ok && this_notification_failure) &&
((medium.last_notification + medium.initial_failure_interval) < timestamp)) ||
((last_notification_failure && this_notification_failure) &&
((medium.last_notification + medium.repeat_failure_interval) < timestamp))
((medium.last_notification + medium.interval) < timestamp))

logger.info " last_notification_failure = #{last_notification_failure}\n" \
" last_notification_ok = #{last_notification_ok}" \
Expand Down
9 changes: 4 additions & 5 deletions spec/lib/flapjack/gateways/jsonapi/medium_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
let(:medium_data) {
{:type => 'email',
:address => '[email protected]',
:initial_failure_interval => 120,
:repeat_failure_interval => 60,
:interval => 120,
:rollup_threshold => 3
}
}
Expand Down Expand Up @@ -148,14 +147,14 @@
expect(Flapjack::Data::Medium).to receive(:find_by_ids!).
with(medium.id, medium_2.id).and_return([medium, medium_2])

expect(medium).to receive(:initial_failure_interval=).with(80)
expect(medium).to receive(:interval=).with(80)
expect(medium).to receive(:save).and_return(true)

expect(medium_2).to receive(:initial_failure_interval=).with(80)
expect(medium_2).to receive(:interval=).with(80)
expect(medium_2).to receive(:save).and_return(true)

patch "/media/#{medium.id},#{medium_2.id}",
Flapjack.dump_json([{:op => 'replace', :path => '/media/0/initial_failure_interval', :value => 80}]),
Flapjack.dump_json([{:op => 'replace', :path => '/media/0/interval', :value => 80}]),
jsonapi_patch_env
expect(last_response.status).to eq(204)
end
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/flapjack/gateways/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ def expect_check_status(ec)
expect(medium).to receive(:alerting_checks).and_return(no_checks)
expect(medium).to receive(:type).twice.and_return('sms')
expect(medium).to receive(:address).and_return('0123456789')
expect(medium).to receive(:initial_failure_interval).twice.and_return(60)
expect(medium).to receive(:repeat_failure_interval).twice.and_return(60)
expect(medium).to receive(:interval).twice.and_return(60)
expect(medium).to receive(:rollup_threshold).and_return(10)

all_media = double('all_media', :all => [medium])
Expand Down
Loading

0 comments on commit 0c9e2c4

Please sign in to comment.