flapjack 1.2.0rc2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Dockerfile +1 -1
- data/Gemfile +6 -5
- data/Gemfile-ruby1.9 +6 -5
- data/Gemfile-ruby1.9.lock +11 -12
- data/features/steps/notifications_steps.rb +10 -10
- data/features/support/env.rb +4 -6
- data/flapjack.gemspec +1 -1
- data/lib/flapjack/data/entity.rb +124 -109
- data/lib/flapjack/data/entity_check.rb +46 -52
- data/lib/flapjack/data/event.rb +4 -4
- data/lib/flapjack/data/migration.rb +29 -0
- data/lib/flapjack/gateways/jsonapi.rb +3 -2
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +11 -4
- data/lib/flapjack/gateways/web.rb +1 -1
- data/lib/flapjack/notifier.rb +4 -8
- data/lib/flapjack/processor.rb +27 -25
- data/lib/flapjack/redis_pool.rb +2 -0
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/data/contact_spec.rb +6 -1
- data/spec/lib/flapjack/data/entity_check_spec.rb +7 -1
- data/spec/lib/flapjack/data/event_spec.rb +16 -20
- data/spec/lib/flapjack/data/migration_spec.rb +52 -0
- data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +10 -0
- data/spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb +3 -6
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -0
- data/tasks/benchmarks.rake +1 -1
- data/tasks/entities.rake +4 -4
- metadata +20 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d31109d0b39ced29a1b027a0894cab07b9d4c0
|
4
|
+
data.tar.gz: 86e20fc3b3f0d34acca6be7e33468fc3d609e868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a838f02684a7cee3ba40cc5be1ecfa2e3b15246912a7bff218944b323f14d43ef64ebce1e9ce978f37795b17d44acc4ec708f4a8768e9788df339a20619f1892
|
7
|
+
data.tar.gz: 93784a164826ef9af3bf84b947d0debdbf21acf3e601ee809c248534d52e0af2cbea643e5cd7ab2c4af4e14a7b8b6ced725883739ecd148ae11f3492a4771f4a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## Flapjack Changelog
|
2
2
|
|
3
|
+
# 1.2.0 - 2014-11-07
|
4
|
+
- Bug: multi blocks for safe redis connection pool usage #694 (@ali-graham)
|
5
|
+
- Bug: data migration to work around previous notification rule bug #699 (@ali-graham)
|
6
|
+
|
3
7
|
# 1.2.0rc2 - 2014-10-17
|
4
8
|
- Feature: Cache entity and check name <-> id lookups #682 (@ali-graham)
|
5
9
|
- Chore: Add last_change field to status_reports in the API (closes: #678) #679 (@Hobbsee)
|
data/Dockerfile
CHANGED
@@ -5,7 +5,7 @@ RUN apt-get install -y gnupg
|
|
5
5
|
RUN gpg --keyserver keys.gnupg.net --recv-keys 803709B6
|
6
6
|
RUN gpg -a --export 803709B6 | apt-key add -
|
7
7
|
|
8
|
-
RUN echo "deb http://packages.flapjack.io/deb/
|
8
|
+
RUN echo "deb http://packages.flapjack.io/deb/v1 trusty main" | tee /etc/apt/sources.list.d/flapjack.list
|
9
9
|
RUN apt-get update
|
10
10
|
RUN apt-cache policy flapjack
|
11
11
|
RUN apt-get install -y flapjack
|
data/Gemfile
CHANGED
@@ -8,7 +8,7 @@ end
|
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem 'rspec', '~> 3.0'
|
11
|
-
gem 'cucumber'
|
11
|
+
gem 'cucumber', '>= 2.0.0.beta.3'
|
12
12
|
gem 'delorean'
|
13
13
|
gem 'rack-test'
|
14
14
|
gem 'pact'
|
@@ -22,8 +22,9 @@ group :test do
|
|
22
22
|
gem 'fuubar'
|
23
23
|
gem 'simplecov', :require => false
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# # Not compiling under 1.9.3-p550 anyway
|
26
|
+
# if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
|
27
|
+
# gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
|
28
|
+
# gem 'perftools.rb'
|
29
|
+
# end
|
29
30
|
end
|
data/Gemfile-ruby1.9
CHANGED
@@ -8,7 +8,7 @@ end
|
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem 'rspec', '~> 3.0'
|
11
|
-
gem 'cucumber'
|
11
|
+
gem 'cucumber', '>= 2.0.0.beta.3'
|
12
12
|
gem 'delorean'
|
13
13
|
gem 'rack-test'
|
14
14
|
gem 'pact'
|
@@ -22,8 +22,9 @@ group :test do
|
|
22
22
|
gem 'fuubar'
|
23
23
|
gem 'simplecov', :require => false
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# # Not compiling under 1.9.3-p550 anyway
|
26
|
+
# if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
|
27
|
+
# gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
|
28
|
+
# gem 'perftools.rb'
|
29
|
+
# end
|
29
30
|
end
|
data/Gemfile-ruby1.9.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
flapjack (1.2.
|
4
|
+
flapjack (1.2.0)
|
5
5
|
activesupport (~> 3.2.14)
|
6
6
|
blather (~> 0.8.3)
|
7
7
|
chronic
|
@@ -31,7 +31,7 @@ PATH
|
|
31
31
|
GEM
|
32
32
|
remote: https://rubygems.org/
|
33
33
|
specs:
|
34
|
-
activesupport (3.2.
|
34
|
+
activesupport (3.2.20)
|
35
35
|
i18n (~> 0.6, >= 0.6.4)
|
36
36
|
multi_json (~> 1.0)
|
37
37
|
addressable (2.3.6)
|
@@ -54,15 +54,17 @@ GEM
|
|
54
54
|
cookiejar (0.3.2)
|
55
55
|
crack (0.4.2)
|
56
56
|
safe_yaml (~> 1.0.0)
|
57
|
-
cucumber (
|
57
|
+
cucumber (2.0.0.beta.3)
|
58
58
|
builder (>= 2.1.2)
|
59
|
+
cucumber-core (~> 1.0.0.beta.3)
|
59
60
|
diff-lcs (>= 1.1.3)
|
60
61
|
gherkin (~> 2.12)
|
61
62
|
multi_json (>= 1.7.5, < 2.0)
|
62
63
|
multi_test (>= 0.1.1)
|
64
|
+
cucumber-core (1.0.0.beta.3)
|
65
|
+
gherkin (~> 2.12.0)
|
63
66
|
daemons (1.1.9)
|
64
67
|
dante (0.2.0)
|
65
|
-
debugger-ruby_core_source (1.3.5)
|
66
68
|
delorean (2.1.0)
|
67
69
|
chronic
|
68
70
|
diff-lcs (1.2.5)
|
@@ -119,10 +121,10 @@ GEM
|
|
119
121
|
rb-fsevent (>= 0.9.3)
|
120
122
|
rb-inotify (>= 0.9)
|
121
123
|
lumberjack (1.0.9)
|
122
|
-
mail (2.6.
|
124
|
+
mail (2.6.3)
|
123
125
|
mime-types (>= 1.16, < 3)
|
124
126
|
method_source (0.8.2)
|
125
|
-
mime-types (2.4.
|
127
|
+
mime-types (2.4.3)
|
126
128
|
mini_portile (0.6.0)
|
127
129
|
msgpack (0.5.9)
|
128
130
|
multi_json (1.10.1)
|
@@ -132,7 +134,7 @@ GEM
|
|
132
134
|
nokogiri (1.6.2.1)
|
133
135
|
mini_portile (= 0.6.0)
|
134
136
|
numerizer (0.1.1)
|
135
|
-
oj (2.
|
137
|
+
oj (2.11.0)
|
136
138
|
pact (1.3.3)
|
137
139
|
awesome_print (~> 1.1)
|
138
140
|
find_a_port (~> 1.0.1)
|
@@ -143,7 +145,6 @@ GEM
|
|
143
145
|
term-ansicolor (~> 1.0)
|
144
146
|
thor
|
145
147
|
webrick
|
146
|
-
perftools.rb (2.0.1)
|
147
148
|
pry (0.10.1)
|
148
149
|
coderay (~> 1.1.0)
|
149
150
|
method_source (~> 0.8.1)
|
@@ -218,7 +219,7 @@ GEM
|
|
218
219
|
tins (1.3.3)
|
219
220
|
trollop (2.0)
|
220
221
|
tzinfo (1.0.1)
|
221
|
-
tzinfo-data (1.2014.
|
222
|
+
tzinfo-data (1.2014.9)
|
222
223
|
tzinfo (>= 1.0.0)
|
223
224
|
vegas (0.1.11)
|
224
225
|
rack (>= 1.0.0)
|
@@ -232,8 +233,7 @@ PLATFORMS
|
|
232
233
|
|
233
234
|
DEPENDENCIES
|
234
235
|
async_rack_test (>= 0.0.5)
|
235
|
-
cucumber
|
236
|
-
debugger-ruby_core_source (>= 1.3.4)
|
236
|
+
cucumber (>= 2.0.0.beta.3)
|
237
237
|
delorean
|
238
238
|
flapjack!
|
239
239
|
fuubar
|
@@ -241,7 +241,6 @@ DEPENDENCIES
|
|
241
241
|
guard-cucumber
|
242
242
|
guard-rspec
|
243
243
|
pact
|
244
|
-
perftools.rb
|
245
244
|
rack-test
|
246
245
|
rb-fsevent
|
247
246
|
resque_spec
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# copied from flapjack-populator
|
3
3
|
# TODO use Flapjack::Data::Contact.add
|
4
4
|
def add_contact(contact = {})
|
5
|
-
@redis.multi
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
@redis.multi do |multi|
|
6
|
+
multi.del("contact:#{contact['id']}")
|
7
|
+
multi.del("contact_media:#{contact['id']}")
|
8
|
+
multi.hset("contact:#{contact['id']}", 'first_name', contact['first_name'])
|
9
|
+
multi.hset("contact:#{contact['id']}", 'last_name', contact['last_name'])
|
10
|
+
multi.hset("contact:#{contact['id']}", 'email', contact['email'])
|
11
|
+
contact['media'].each_pair {|medium, address|
|
12
|
+
multi.hset("contact_media:#{contact['id']}", medium, address)
|
13
|
+
}
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
17
|
Given /^the user wants to receive SMS notifications for entity '([\w\.\-]+)'$/ do |entity|
|
data/features/support/env.rb
CHANGED
@@ -115,16 +115,13 @@ end
|
|
115
115
|
|
116
116
|
config = Flapjack::Configuration.new
|
117
117
|
redis_opts = config.load(FLAPJACK_CONFIG) ?
|
118
|
-
config.for_redis :
|
118
|
+
config.for_redis.merge(:driver => :ruby) :
|
119
119
|
{:db => 14, :driver => :ruby}
|
120
120
|
redis = ::Redis.new(redis_opts)
|
121
121
|
redis.flushdb
|
122
122
|
RedisDelorean.before_all(:redis => redis)
|
123
123
|
redis.quit
|
124
124
|
|
125
|
-
# NB: this seems to execute outside the Before/After hooks
|
126
|
-
# regardless of placement -- this is what we want, as the
|
127
|
-
# @redis driver should be initialised in the sync block.
|
128
125
|
Around do |scenario, blk|
|
129
126
|
EM.synchrony do
|
130
127
|
blk.call
|
@@ -140,7 +137,6 @@ After do
|
|
140
137
|
@logger.messages = []
|
141
138
|
end
|
142
139
|
|
143
|
-
|
144
140
|
Before('@processor') do
|
145
141
|
@processor = Flapjack::Processor.new(:logger => @logger,
|
146
142
|
:redis_config => redis_opts, :config => {})
|
@@ -150,6 +146,7 @@ end
|
|
150
146
|
After('@processor') do
|
151
147
|
@redis.flushdb
|
152
148
|
@redis.quit
|
149
|
+
@redis = nil
|
153
150
|
end
|
154
151
|
|
155
152
|
Before('@notifier') do
|
@@ -165,6 +162,7 @@ end
|
|
165
162
|
After('@notifier') do
|
166
163
|
@notifier_redis.flushdb
|
167
164
|
@notifier_redis.quit
|
165
|
+
@notifier_redis = nil
|
168
166
|
end
|
169
167
|
|
170
168
|
Before('@resque') do
|
@@ -173,7 +171,7 @@ Before('@resque') do
|
|
173
171
|
end
|
174
172
|
|
175
173
|
Before('@time') do
|
176
|
-
RedisDelorean.before_each(:redis => @redis)
|
174
|
+
RedisDelorean.before_each(:redis => @redis || @notifier_redis)
|
177
175
|
end
|
178
176
|
|
179
177
|
After('@time') do
|
data/flapjack.gemspec
CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency 'dante'
|
22
22
|
gem.add_dependency 'oj', '>= 2.9.0'
|
23
23
|
gem.add_dependency 'eventmachine', '~> 1.0.0'
|
24
|
+
gem.add_dependency 'redis', '~> 3.0.6'
|
24
25
|
gem.add_dependency 'hiredis'
|
25
26
|
gem.add_dependency 'em-synchrony', '~> 1.0.2'
|
26
27
|
gem.add_dependency 'em-http-request'
|
27
|
-
gem.add_dependency 'redis', '~> 3.0.6'
|
28
28
|
gem.add_dependency 'em-resque'
|
29
29
|
gem.add_dependency 'resque', '~> 1.23.0'
|
30
30
|
gem.add_dependency 'sinatra'
|
data/lib/flapjack/data/entity.rb
CHANGED
@@ -44,12 +44,17 @@ module Flapjack
|
|
44
44
|
|
45
45
|
check_history_keys = redis.keys("#{existing_name}:*:states") +
|
46
46
|
redis.keys("#{existing_name}:*:state") +
|
47
|
-
redis.keys("#{existing_name}:*:summary") +
|
48
47
|
redis.keys("#{existing_name}:*:sorted_state_timestamps")
|
49
48
|
|
50
49
|
action_keys = redis.keys("#{existing_name}:*:actions")
|
51
50
|
|
52
|
-
maint_keys = redis.keys("#{existing_name}:*:*scheduled_maintenance*")
|
51
|
+
maint_keys = redis.keys("#{existing_name}:*:*scheduled_maintenance*")
|
52
|
+
|
53
|
+
all_summary_keys = redis.keys("#{existing_name}:*:summary")
|
54
|
+
maint_summary_keys = redis.keys("#{existing_name}:*:*scheduled_maintenance:summary")
|
55
|
+
check_summary_keys = all_summary_keys - maint_summary_keys
|
56
|
+
|
57
|
+
check_history_keys += check_summary_keys
|
53
58
|
|
54
59
|
notif_keys = redis.keys("#{existing_name}:*:last_*_notification") +
|
55
60
|
redis.keys("#{existing_name}:*:*_notifications")
|
@@ -100,54 +105,61 @@ module Flapjack
|
|
100
105
|
|
101
106
|
block_keys = redis.keys("drop_alerts_for_contact:*:*:#{existing_name}:*:*")
|
102
107
|
|
103
|
-
redis.
|
108
|
+
rename_all_checks = redis.exists("all_checks:#{existing_name}")
|
109
|
+
rename_current_checks = redis.exists("current_checks:#{existing_name}")
|
104
110
|
|
105
|
-
|
111
|
+
redis.multi do |multi|
|
106
112
|
|
107
|
-
|
108
|
-
redis.rename(csk, csk.sub(/^check:#{Regexp.escape(existing_name)}:/, "check:#{entity_name}:"))
|
109
|
-
end
|
113
|
+
yield(multi) if block_given? # entity id -> name update from add()
|
110
114
|
|
111
|
-
|
112
|
-
|
113
|
-
|
115
|
+
check_state_keys.each do |csk|
|
116
|
+
multi.rename(csk, csk.sub(/^check:#{Regexp.escape(existing_name)}:/, "check:#{entity_name}:"))
|
117
|
+
end
|
114
118
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
+
(check_history_keys + action_keys + maint_keys + notif_keys).each do |chk|
|
120
|
+
multi.rename(chk, chk.sub(/^#{Regexp.escape(existing_name)}:/, "#{entity_name}:"))
|
121
|
+
end
|
119
122
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
123
|
+
all_checks.each_pair do |ch, score|
|
124
|
+
multi.zrem('all_checks', "#{existing_name}:#{ch}")
|
125
|
+
multi.zadd('all_checks', score, "#{entity_name}:#{ch}")
|
126
|
+
end
|
125
127
|
|
126
|
-
|
127
|
-
|
128
|
+
# currently failing checks
|
129
|
+
failed_checks.each_pair do |ch, score|
|
130
|
+
multi.zrem('failed_checks', "#{existing_name}:#{ch}")
|
131
|
+
multi.zadd('failed_checks', score, "#{entity_name}:#{ch}")
|
132
|
+
end
|
128
133
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
134
|
+
if rename_all_checks
|
135
|
+
multi.rename("all_checks:#{existing_name}", "all_checks:#{entity_name}")
|
136
|
+
end
|
133
137
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
+
if rename_current_checks
|
139
|
+
multi.rename("current_checks:#{existing_name}", "current_checks:#{entity_name}")
|
140
|
+
end
|
138
141
|
|
139
|
-
|
140
|
-
|
142
|
+
unless current_score.nil?
|
143
|
+
multi.zrem('current_entities', existing_name)
|
144
|
+
multi.zadd('current_entities', current_score, entity_name)
|
145
|
+
end
|
141
146
|
|
142
|
-
|
143
|
-
|
144
|
-
|
147
|
+
block_keys.each do |blk|
|
148
|
+
multi.rename(blk, blk.sub(/^drop_alerts_for_contact:(.+):([^:]+):#{Regexp.escape(existing_name)}:(.+):([^:]+)$/,
|
149
|
+
"drop_alerts_for_contact:\\1:\\2:#{entity_name}:\\3:\\4"))
|
150
|
+
end
|
145
151
|
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
hashes_to_remove.each {|hash| multi.hdel('checks_by_hash', hash) }
|
153
|
+
hashes_to_add.each_pair {|hash, chk| multi.hset('checks_by_hash', hash, chk)}
|
154
|
+
|
155
|
+
alerting_to_remove.each_pair do |alerting, chks|
|
156
|
+
chks.each {|chk| multi.zrem(alerting, chk)}
|
157
|
+
end
|
149
158
|
|
150
|
-
|
159
|
+
alerting_to_add.each_pair do |alerting, chks|
|
160
|
+
chks.each_pair {|chk, score| multi.zadd(alerting, score, chk)}
|
161
|
+
end
|
162
|
+
end
|
151
163
|
end
|
152
164
|
|
153
165
|
# NB only used by the 'entities:reparent' Rake task, but kept in this
|
@@ -213,8 +225,12 @@ module Flapjack
|
|
213
225
|
ch_fail_score = redis.zscore("failed_checks", old_check)
|
214
226
|
failed_checks_to_add[current_check] = ch_fail_score unless ch_fail_score.nil?
|
215
227
|
|
216
|
-
|
217
|
-
|
228
|
+
if redis.exists("check:#{old_check}")
|
229
|
+
keys_to_rename["check:#{old_check}"] = "check:#{current_check}"
|
230
|
+
end
|
231
|
+
if redis.exists(old_states)
|
232
|
+
keys_to_rename[old_states] = new_states
|
233
|
+
end
|
218
234
|
end
|
219
235
|
|
220
236
|
notification_types.each do |notif|
|
@@ -229,7 +245,7 @@ module Flapjack
|
|
229
245
|
end
|
230
246
|
|
231
247
|
keys_to_delete << old_notif
|
232
|
-
|
248
|
+
elsif redis.exists(old_notif)
|
233
249
|
keys_to_rename[old_notif] = new_notif
|
234
250
|
end
|
235
251
|
end
|
@@ -258,13 +274,13 @@ module Flapjack
|
|
258
274
|
|
259
275
|
if redis.exists("all_checks:#{current_name}")
|
260
276
|
keys_to_delete << "all_checks:#{old_name}"
|
261
|
-
|
277
|
+
elsif redis.exists("all_checks:#{old_name}")
|
262
278
|
keys_to_rename["all_checks:#{old_name}"] = "all_checks:#{current_name}"
|
263
279
|
end
|
264
280
|
|
265
281
|
if redis.exists("current_checks:#{current_name}")
|
266
282
|
keys_to_delete << "current_checks:#{old_name}"
|
267
|
-
|
283
|
+
elsif redis.exists("current_checks:#{old_name}")
|
268
284
|
keys_to_rename["current_checks:#{old_name}"] = "current_checks:#{current_name}"
|
269
285
|
end
|
270
286
|
|
@@ -291,7 +307,7 @@ module Flapjack
|
|
291
307
|
if redis.exists(current_actions)
|
292
308
|
action_data[current_actions] = redis.hgetall(old_actions)
|
293
309
|
keys_to_delete << old_actions
|
294
|
-
|
310
|
+
elsif redis.exists(old_actions)
|
295
311
|
keys_to_rename[old_actions] = current_actions
|
296
312
|
end
|
297
313
|
end
|
@@ -317,7 +333,7 @@ module Flapjack
|
|
317
333
|
# TTL < 0 is a redis error code -- key not present, etc.
|
318
334
|
if (old_ttl >= 0) && ((new_ttl < 0) ||
|
319
335
|
((old_time + old_ttl) > (new_time + new_ttl)))
|
320
|
-
keys_to_rename[maint_key] = new_maint_key
|
336
|
+
keys_to_rename[maint_key] = new_maint_key if redis.exists(maint_key)
|
321
337
|
maints_to_set[new_maint_key] = redis.zscore("#{maint_key}s", old_time)
|
322
338
|
end
|
323
339
|
|
@@ -350,84 +366,83 @@ module Flapjack
|
|
350
366
|
|
351
367
|
notif_keys = redis.keys("#{old_name}:*:last_*_notification")
|
352
368
|
|
353
|
-
redis.multi
|
369
|
+
redis.multi do |multi|
|
354
370
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
check_timestamps_keys.each do |ctk|
|
360
|
-
dest = ctk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
|
361
|
-
redis.zunionstore(dest, [ctk, dest], :aggregate => :max)
|
362
|
-
end
|
371
|
+
check_history_keys.each do |chk|
|
372
|
+
multi.renamenx(chk, chk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:"))
|
373
|
+
end
|
363
374
|
|
364
|
-
|
365
|
-
|
366
|
-
|
375
|
+
check_timestamps_keys.each do |ctk|
|
376
|
+
dest = ctk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
|
377
|
+
multi.zunionstore(dest, [ctk, dest], :aggregate => :max)
|
378
|
+
end
|
367
379
|
|
368
|
-
|
369
|
-
|
370
|
-
|
380
|
+
all_checks_to_remove.each do |actr|
|
381
|
+
multi.zrem('all_checks', actr)
|
382
|
+
end
|
371
383
|
|
372
|
-
|
373
|
-
|
374
|
-
|
384
|
+
all_checks_to_add.each_pair do |acta, score|
|
385
|
+
multi.zadd('all_checks', score, acta)
|
386
|
+
end
|
375
387
|
|
376
|
-
|
377
|
-
|
378
|
-
|
388
|
+
failed_checks_to_remove.each do |fctr|
|
389
|
+
multi.zrem('failed_checks', fctr)
|
390
|
+
end
|
379
391
|
|
380
|
-
|
381
|
-
|
382
|
-
redis.hsetnx(action_key, k, v)
|
392
|
+
failed_checks_to_add.each_pair do |fcta, score|
|
393
|
+
multi.zadd('failed_checks', score, fcta)
|
383
394
|
end
|
384
|
-
end
|
385
395
|
|
386
|
-
|
387
|
-
|
388
|
-
|
396
|
+
action_data.each_pair do |action_key, data|
|
397
|
+
data.each_pair do |k, v|
|
398
|
+
multi.hsetnx(action_key, k, v)
|
399
|
+
end
|
400
|
+
end
|
389
401
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
end
|
402
|
+
multi.zunionstore("current_checks:#{current_name}",
|
403
|
+
["current_checks:#{old_name}", "current_checks:#{current_name}"],
|
404
|
+
:aggregate => :max)
|
394
405
|
|
395
|
-
|
396
|
-
|
397
|
-
|
406
|
+
multi.zrem('current_entities', old_name)
|
407
|
+
unless old_score.nil?
|
408
|
+
multi.zadd('current_entities', old_score, current_name)
|
409
|
+
end
|
398
410
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
[stored_maint_key, new_stored_maint_key],
|
403
|
-
:aggregate => :max)
|
404
|
-
end
|
411
|
+
maints_to_set.each_pair do |maint_key, score|
|
412
|
+
multi.zadd("#{maint_key}s", score, current_name)
|
413
|
+
end
|
405
414
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
415
|
+
stored_maint_keys.each do |stored_maint_key|
|
416
|
+
new_stored_maint_key = stored_maint_key.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
|
417
|
+
multi.zunionstore(new_stored_maint_key,
|
418
|
+
[stored_maint_key, new_stored_maint_key],
|
419
|
+
:aggregate => :max)
|
420
|
+
end
|
411
421
|
|
412
|
-
|
413
|
-
|
414
|
-
|
422
|
+
notif_keys.each do |nk|
|
423
|
+
dest = nk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
|
424
|
+
multi.renamenx(nk, dest)
|
425
|
+
multi.del(nk)
|
426
|
+
end
|
415
427
|
|
416
|
-
|
417
|
-
|
418
|
-
|
428
|
+
alerting_to_remove.each_pair do |alerting, chks|
|
429
|
+
chks.each {|chk| multi.zrem(alerting, chk)}
|
430
|
+
end
|
419
431
|
|
420
|
-
|
421
|
-
|
422
|
-
|
432
|
+
alerting_to_add.each_pair do |alerting, chks|
|
433
|
+
chks.each_pair {|chk, score| multi.zadd(alerting, score, chk)}
|
434
|
+
end
|
423
435
|
|
424
|
-
|
425
|
-
|
426
|
-
|
436
|
+
blocks_to_set.each_pair do |block_key, (timestamp, value)|
|
437
|
+
multi.setex(block_key, (timestamp - Time.now.to_i), value)
|
438
|
+
end
|
427
439
|
|
428
|
-
|
440
|
+
keys_to_rename.each_pair do |old_key, new_key|
|
441
|
+
multi.rename(old_key, new_key)
|
442
|
+
end
|
429
443
|
|
430
|
-
|
444
|
+
multi.del(*keys_to_delete) unless keys_to_delete.empty?
|
445
|
+
end
|
431
446
|
end
|
432
447
|
|
433
448
|
# NB: If entities are renamed in imported data before they are
|
@@ -467,10 +482,10 @@ module Flapjack
|
|
467
482
|
if redis.hexists('all_entity_ids_by_name', entity_name)
|
468
483
|
merge(existing_name, entity_name, :redis => redis)
|
469
484
|
else
|
470
|
-
rename(existing_name, entity_name, :redis => redis) {
|
471
|
-
|
472
|
-
|
473
|
-
|
485
|
+
rename(existing_name, entity_name, :redis => redis) {|multi|
|
486
|
+
multi.hdel('all_entity_ids_by_name', existing_name)
|
487
|
+
multi.hset('all_entity_ids_by_name', entity_name, entity_id)
|
488
|
+
multi.hset('all_entity_names_by_id', entity_id, entity_name)
|
474
489
|
}
|
475
490
|
end
|
476
491
|
end
|