flapjack 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d001e3be416a31b890c1d7342e31318de35883b6
4
- data.tar.gz: 2fbab643fdaf9689ad1e7cb7b021c8e0c5269405
3
+ metadata.gz: 0b98530923891264cb55c429358ca9597f1ef4ca
4
+ data.tar.gz: c957beff3e8d6942157ac1e085cd912932f9e287
5
5
  SHA512:
6
- metadata.gz: ee9dd7d134bf6c3077ba7dbad4299538e1765073a6a3c5ecdaa3076b6caf944a146885bae9ae85d27541fc091d58eca39ffa819713eae35ff3e489f94a74d42e
7
- data.tar.gz: 8b132804ab7416c6110bc607322aeef2ae6bf16741e4f06f744625cdfeaf230dd9dab0f7c8622f7887ab00a2603272466d6c86985403448d9399550900025afa
6
+ metadata.gz: dd3e6b3b9af05c5f40ea6f884f985d7b5d6765eb4493f40ee12a12f8a51360933c971227b0afab1f0dd6b57f8c851c5e39276300e319610598208c945288f7aa
7
+ data.tar.gz: 8ecf0255ef2f7e6cdac040f62a3b8468138bb74bca9e024fbf8111d8743bedba5d861791d2d17ace0cba27ee70c0befc12155195b79b60ae9e4e2ad4ae31f861
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Flapjack Changelog
2
2
 
3
+ # 0.9.1 - 2014-06-27
4
+ - Bug: PATCHing blackhole properties for notification rule changes other blackholes - further fixes #504 (@ali-graham)
5
+ - Bug: JSONAPI get all entities/contacts with empty db e3725fc (@ali-graham)
6
+ - Bug: Decommission Check button returning a 404 #538 (@ali-graham)
7
+ - Bug: Weekday number 7 is accepted by the jsonapi but causes Flapjack to crash #549 (@ali-graham)
8
+
3
9
  # 0.9.0 - 2014-05-23
4
10
  - Chore: split reports data from entities and checks in jsonapi #525 (@ali-graham)
5
11
 
@@ -156,7 +156,8 @@ module Flapjack
156
156
  matches_regex_entities = rule_has_regex_entities ? rule.match_regex_entities?(@event_id) : true
157
157
 
158
158
  ((matches_entity && matches_regex_entities && matches_tags && matches_regex_tags) || ! rule.is_specific?) &&
159
- rule_occurring_now?(rule, :contact => contact, :default_timezone => default_timezone)
159
+ rule_occurring_now?(rule, :contact => contact, :default_timezone => default_timezone,
160
+ :logger => logger)
160
161
  end
161
162
 
162
163
  logger.debug "#{matchers.length} matchers remain for this contact after time, entity and tags are matched:"
@@ -280,7 +281,7 @@ module Flapjack
280
281
  rule.time_restrictions.any? do |tr|
281
282
  # add contact's timezone to the time restriction schedule
282
283
  schedule = Flapjack::Data::NotificationRule.
283
- time_restriction_to_icecube_schedule(tr, timezone)
284
+ time_restriction_to_icecube_schedule(tr, timezone, :logger => options[:logger])
284
285
  schedule && schedule.occurring_at?(usertime)
285
286
  end
286
287
  end
@@ -68,8 +68,16 @@ module Flapjack
68
68
  end
69
69
 
70
70
  def update(update_data, opts = {})
71
- rule_data = @redis.hgetall("notification_rule:#{@id}").merge(update_data.merge(:id => @id))
72
- errors = self.class.add_or_update(rule_data, :redis => @redis, :logger => opts[:logger])
71
+ [:entities, :regex_entities, :tags, :regex_tags,
72
+ :time_restrictions, :unknown_media, :warning_media, :critical_media,
73
+ :unknown_blackhole, :warning_blackhole, :critical_blackhole].each do |update_key|
74
+
75
+ next if update_data.has_key?(update_key)
76
+ update_data[update_key] = self.send(update_key)
77
+ end
78
+
79
+ update_data.update(:id => @id, :contact_id => @contact_id)
80
+ errors = self.class.add_or_update(update_data, :redis => @redis, :logger => opts[:logger])
73
81
  return errors unless errors.nil? || errors.empty?
74
82
 
75
83
  refresh
@@ -85,11 +93,19 @@ module Flapjack
85
93
  #
86
94
  # We don't want to replicate IceCube's from_hash behaviour here,
87
95
  # but we do need to apply some sanity checking on the passed data.
88
- def self.time_restriction_to_icecube_schedule(tr, timezone)
89
- return unless !tr.nil? && tr.is_a?(Hash)
90
- return if timezone.nil? && !timezone.is_a?(ActiveSupport::TimeZone)
91
- return unless tr = prepare_time_restriction(tr, timezone)
92
- IceCube::Schedule.from_hash(tr)
96
+ def self.time_restriction_to_icecube_schedule(tr, timezone, opts = {})
97
+ return if tr.nil? || !tr.is_a?(Hash) ||
98
+ timezone.nil? || !timezone.is_a?(ActiveSupport::TimeZone)
99
+ prepared_restrictions = prepare_time_restriction(tr, timezone)
100
+ return if prepared_restrictions.nil?
101
+ IceCube::Schedule.from_hash(prepared_restrictions)
102
+ rescue ArgumentError => ae
103
+ if logger = opts[:logger]
104
+ logger.error "Couldn't parse rule data #{e.class}: #{e.message}"
105
+ logger.error prepared_restrictions.inspect
106
+ logger.error e.backtrace.join("\n")
107
+ end
108
+ nil
93
109
  end
94
110
 
95
111
  def to_json(*args)
@@ -207,6 +223,7 @@ module Flapjack
207
223
  # whitelisting fields, rather than passing through submitted data directly
208
224
  tag_data = rule_data[:tags].is_a?(Set) ? rule_data[:tags].to_a : nil
209
225
  regex_tag_data = rule_data[:regex_tags].is_a?(Set) ? rule_data[:regex_tags].to_a : nil
226
+
210
227
  json_rule_data = {
211
228
  :id => rule_data[:id].to_s,
212
229
  :contact_id => rule_data[:contact_id].to_s,
@@ -222,6 +239,7 @@ module Flapjack
222
239
  :warning_blackhole => rule_data[:warning_blackhole],
223
240
  :critical_blackhole => rule_data[:critical_blackhole],
224
241
  }
242
+
225
243
  logger.debug("NotificationRule#add_or_update json_rule_data: #{json_rule_data.inspect}") if logger
226
244
 
227
245
  redis.sadd("contact_notification_rules:#{json_rule_data[:contact_id]}",
@@ -315,10 +333,11 @@ module Flapjack
315
333
  d[:regex_tags].all? {|et| et.is_a?(String)} ) } =>
316
334
  "regex_tags must be a tag_set of strings",
317
335
 
336
+ # conversion to a schedule needs a time zone, any one will do
318
337
  proc {|d| !d.has_key?(:time_restrictions) ||
319
338
  ( d[:time_restrictions].nil? ||
320
339
  d[:time_restrictions].all? {|tr|
321
- !!prepare_time_restriction(symbolize(tr))
340
+ !!self.time_restriction_to_icecube_schedule(symbolize(tr), ActiveSupport::TimeZone['UTC'])
322
341
  } )
323
342
  } =>
324
343
  "time restrictions are invalid",
@@ -116,7 +116,7 @@ module Flapjack
116
116
  raise Flapjack::Gateways::JSONAPI::ContactsNotFound.new(requested_contacts)
117
117
  end
118
118
 
119
- entity_ids = Flapjack::Data::Contact.entity_ids_for(contacts.map(&:id), :redis => redis)
119
+ entity_ids = contacts.empty? ? [] : Flapjack::Data::Contact.entity_ids_for(contacts.map(&:id), :redis => redis)
120
120
 
121
121
  contacts_json = contacts.collect {|contact|
122
122
  contact.to_jsonapi(:entity_ids => entity_ids[contact.id])
@@ -52,7 +52,7 @@ module Flapjack
52
52
  raise Flapjack::Gateways::JSONAPI::EntitiesNotFound.new(requested_entities)
53
53
  end
54
54
 
55
- linked_contact_ids = Flapjack::Data::Entity.contact_ids_for(entities.map(&:id), :redis => redis)
55
+ linked_contact_ids = entities.empty? ? [] : Flapjack::Data::Entity.contact_ids_for(entities.map(&:id), :redis => redis)
56
56
 
57
57
  entities_json = entities.collect {|entity|
58
58
  entity.to_jsonapi(:contact_ids => linked_contact_ids[entity.id])
@@ -72,6 +72,8 @@ module Flapjack
72
72
 
73
73
  include Flapjack::Utility
74
74
 
75
+ set :protection, :except => :path_traversal
76
+
75
77
  set :views, settings.root + '/web/views'
76
78
  set :public_folder, settings.root + '/web/public'
77
79
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.1"
5
5
  end
6
6
 
@@ -76,11 +76,10 @@ describe Flapjack::Data::NotificationRule, :redis => true do
76
76
 
77
77
  expect {
78
78
  expect {
79
- rule_data[:warning_blackhole] = true
80
- errors = rule.update(rule_data)
79
+ errors = rule.update(:warning_blackhole => true)
81
80
  expect(errors).to be_nil
82
81
  }.to change { rule.warning_blackhole }.from(false).to(true)
83
- }.not_to change { rule.warning_media }
82
+ }.not_to change { rule.contact_id }
84
83
  end
85
84
 
86
85
  it "converts time restriction data to an IceCube schedule" do
@@ -156,6 +155,34 @@ describe Flapjack::Data::NotificationRule, :redis => true do
156
155
  }.not_to change { rule.entities }
157
156
  end
158
157
 
158
+ # https://github.com/flapjack/flapjack/issues/549
159
+ it "fails to add a notification rule with invalid data" do
160
+ rule_data[:time_restrictions] = [
161
+ {
162
+ "start_time" => "2014-06-22 00:00:00",
163
+ "end_time" => "2015-01-01 00:00:00",
164
+ "rrules" => [
165
+ {
166
+ "validations" => {
167
+ "day" => [1,2,3,4,5,6,7]
168
+ },
169
+ "rule_type" => "Weekly",
170
+ "interval" => 1,
171
+ "week_start" => 0
172
+ }
173
+ ],
174
+ "exrules" => [],
175
+ "rtimes" => [],
176
+ "extimes" => []
177
+ }
178
+ ]
179
+ rule_or_errors = Flapjack::Data::NotificationRule.add(rule_data, :redis => @redis)
180
+ expect(rule_or_errors).not_to be_nil
181
+ expect(rule_or_errors).to be_an(Array)
182
+ expect(rule_or_errors.size).to eq(1)
183
+ expect(rule_or_errors).to eq(["Rule time restrictions are invalid"])
184
+ end
185
+
159
186
  end
160
187
 
161
188
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flapjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lindsay Holmwood
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-23 00:00:00.000000000 Z
13
+ date: 2014-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dante