sensu 0.9.9.beta.2 → 0.9.9.beta.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,25 @@
1
1
  module Sensu
2
2
  class Settings
3
+ include Utilities
4
+
3
5
  attr_reader :indifferent_access, :loaded_env, :loaded_files
4
6
 
5
7
  def initialize
6
- @logger = Sensu::Logger.get
8
+ @logger = Logger.get
7
9
  @settings = Hash.new
8
- [:checks, :filters, :mutators, :handlers].each do |key|
9
- @settings[key] = Hash.new
10
+ SETTINGS_CATEGORIES.each do |category|
11
+ @settings[category] = Hash.new
10
12
  end
11
13
  @indifferent_access = false
12
14
  @loaded_env = false
13
15
  @loaded_files = Array.new
14
16
  end
15
17
 
18
+ def indifferent_access!
19
+ @settings = with_indifferent_access(@settings)
20
+ @indifferent_access = true
21
+ end
22
+
16
23
  def [](key)
17
24
  unless @indifferent_access
18
25
  indifferent_access!
@@ -20,9 +27,16 @@ module Sensu
20
27
  @settings[key.to_sym]
21
28
  end
22
29
 
23
- def indifferent_access!
24
- @settings = indifferent_access(@settings)
25
- @indifferent_access = true
30
+ SETTINGS_CATEGORIES.each do |category|
31
+ define_method(category) do
32
+ @settings[category].map do |name, details|
33
+ details.merge(:name => name.to_s)
34
+ end
35
+ end
36
+
37
+ define_method((category.to_s.chop + '_exists?').to_sym) do |name|
38
+ @settings[category].has_key?(name.to_sym)
39
+ end
26
40
  end
27
41
 
28
42
  def load_env
@@ -85,27 +99,21 @@ module Sensu
85
99
  end
86
100
  end
87
101
 
88
- def set_env
89
- ENV['SENSU_CONFIG_FILES'] = @loaded_files.join(':')
90
- end
91
-
92
- [:checks, :filters, :mutators, :handlers].each do |key|
93
- define_method(key) do
94
- @settings[key].map do |name, details|
95
- details.merge(:name => name.to_s)
96
- end
102
+ def load_directory(directory)
103
+ Dir.glob(File.join(directory, '**/*.json')).each do |file|
104
+ load_file(file)
97
105
  end
106
+ end
98
107
 
99
- define_method((key.to_s.chop + '_exists?').to_sym) do |name|
100
- @settings[key].has_key?(name.to_sym)
101
- end
108
+ def set_env
109
+ ENV['SENSU_CONFIG_FILES'] = @loaded_files.join(':')
102
110
  end
103
111
 
104
112
  def validate
105
113
  @logger.debug('validating settings')
106
114
  validate_checks
107
115
  case File.basename($0)
108
- when 'rake'
116
+ when 'rspec'
109
117
  validate_client
110
118
  validate_api
111
119
  validate_server
@@ -121,52 +129,6 @@ module Sensu
121
129
 
122
130
  private
123
131
 
124
- def indifferent_access(hash)
125
- hash = indifferent_hash.merge(hash)
126
- hash.each do |key, value|
127
- if value.is_a?(Hash)
128
- hash[key] = indifferent_access(value)
129
- end
130
- end
131
- end
132
-
133
- def indifferent_hash
134
- Hash.new do |hash, key|
135
- if key.is_a?(String)
136
- hash[key.to_sym]
137
- end
138
- end
139
- end
140
-
141
- def deep_merge(hash_one, hash_two)
142
- merged = hash_one.dup
143
- hash_two.each do |key, value|
144
- merged[key] = case
145
- when hash_one[key].is_a?(Hash) && value.is_a?(Hash)
146
- deep_merge(hash_one[key], value)
147
- when hash_one[key].is_a?(Array) && value.is_a?(Array)
148
- hash_one[key].concat(value).uniq
149
- else
150
- value
151
- end
152
- end
153
- merged
154
- end
155
-
156
- def deep_diff(hash_one, hash_two)
157
- keys = hash_one.keys.concat(hash_two.keys).uniq
158
- keys.inject(Hash.new) do |diff, key|
159
- unless hash_one[key] == hash_two[key]
160
- if hash_one[key].is_a?(Hash) && hash_two[key].is_a?(Hash)
161
- diff[key] = deep_diff(hash_one[key], hash_two[key])
162
- else
163
- diff[key] = [hash_one[key], hash_two[key]]
164
- end
165
- end
166
- diff
167
- end
168
- end
169
-
170
132
  def invalid(reason, details={})
171
133
  @logger.fatal('invalid settings', {
172
134
  :reason => reason
@@ -191,7 +153,7 @@ module Sensu
191
153
  })
192
154
  end
193
155
  unless check[:standalone]
194
- unless check[:subscribers].is_a?(Array) && check[:subscribers].count > 0
156
+ unless check[:subscribers].is_a?(Array) && check[:subscribers].size > 0
195
157
  invalid('check is missing subscribers', {
196
158
  :check => check
197
159
  })
@@ -490,7 +452,7 @@ module Sensu
490
452
  })
491
453
  end
492
454
  handler[:severities].each do |severity|
493
- unless Sensu::SEVERITIES.include?(severity)
455
+ unless SEVERITIES.include?(severity)
494
456
  invalid('handler severities are invalid', {
495
457
  :handler => handler
496
458
  })
@@ -0,0 +1,75 @@
1
+ module Sensu
2
+ module Utilities
3
+ def testing?
4
+ File.basename($0) == 'rspec'
5
+ end
6
+
7
+ def retry_until_true(wait=0.5, &block)
8
+ EM::Timer.new(wait) do
9
+ unless block.call
10
+ retry_until_true(wait, &block)
11
+ end
12
+ end
13
+ end
14
+
15
+ def indifferent_hash
16
+ Hash.new do |hash, key|
17
+ if key.is_a?(String)
18
+ hash[key.to_sym]
19
+ end
20
+ end
21
+ end
22
+
23
+ def with_indifferent_access(hash)
24
+ hash = indifferent_hash.merge(hash)
25
+ hash.each do |key, value|
26
+ if value.is_a?(Hash)
27
+ hash[key] = with_indifferent_access(value)
28
+ end
29
+ end
30
+ end
31
+
32
+ def deep_merge(hash_one, hash_two)
33
+ merged = hash_one.dup
34
+ hash_two.each do |key, value|
35
+ merged[key] = case
36
+ when hash_one[key].is_a?(Hash) && value.is_a?(Hash)
37
+ deep_merge(hash_one[key], value)
38
+ when hash_one[key].is_a?(Array) && value.is_a?(Array)
39
+ hash_one[key].concat(value).uniq
40
+ else
41
+ value
42
+ end
43
+ end
44
+ merged
45
+ end
46
+
47
+ def deep_diff(hash_one, hash_two)
48
+ keys = hash_one.keys.concat(hash_two.keys).uniq
49
+ keys.inject(Hash.new) do |diff, key|
50
+ unless hash_one[key] == hash_two[key]
51
+ if hash_one[key].is_a?(Hash) && hash_two[key].is_a?(Hash)
52
+ diff[key] = deep_diff(hash_one[key], hash_two[key])
53
+ else
54
+ diff[key] = [hash_one[key], hash_two[key]]
55
+ end
56
+ end
57
+ diff
58
+ end
59
+ end
60
+
61
+ def hash_values_equal?(hash_one, hash_two)
62
+ hash_one.keys.all? do |key|
63
+ if hash_one[key] == hash_two[key]
64
+ true
65
+ else
66
+ if hash_one[key].is_a?(Hash) && hash_two[key].is_a?(Hash)
67
+ hash_values_equal?(hash_one[key], hash_two[key])
68
+ else
69
+ false
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
data/sensu.gemspec CHANGED
@@ -13,15 +13,15 @@ Gem::Specification.new do |s|
13
13
  s.has_rdoc = false
14
14
 
15
15
  s.add_dependency('eventmachine', '1.0.0')
16
- s.add_dependency('amqp', '0.9.7')
16
+ s.add_dependency('amqp', '0.9.8')
17
17
  s.add_dependency('json')
18
18
  s.add_dependency('cabin', '0.4.4')
19
- s.add_dependency('ruby-redis', '0.0.2')
19
+ s.add_dependency('em-redis-unified', '0.4.1')
20
20
  s.add_dependency('thin', '1.5.0')
21
21
  s.add_dependency('async_sinatra', '1.0.0')
22
22
 
23
23
  s.add_development_dependency('rake')
24
- s.add_development_dependency('em-spec')
24
+ s.add_development_dependency('rspec')
25
25
  s.add_development_dependency('em-http-request')
26
26
 
27
27
  s.files = Dir.glob('{bin,lib}/**/*') + %w[sensu.gemspec README.md CHANGELOG.md MIT-LICENSE.txt]
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1743839652
4
+ hash: 2679144457
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 9
10
10
  - beta
11
- - 2
12
- version: 0.9.9.beta.2
11
+ - 3
12
+ version: 0.9.9.beta.3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Sean Porter
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2013-01-02 00:00:00 -08:00
21
+ date: 2013-01-11 00:00:00 -08:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -45,12 +45,12 @@ dependencies:
45
45
  requirements:
46
46
  - - "="
47
47
  - !ruby/object:Gem::Version
48
- hash: 53
48
+ hash: 43
49
49
  segments:
50
50
  - 0
51
51
  - 9
52
- - 7
53
- version: 0.9.7
52
+ - 8
53
+ version: 0.9.8
54
54
  type: :runtime
55
55
  version_requirements: *id002
56
56
  - !ruby/object:Gem::Dependency
@@ -84,19 +84,19 @@ dependencies:
84
84
  type: :runtime
85
85
  version_requirements: *id004
86
86
  - !ruby/object:Gem::Dependency
87
- name: ruby-redis
87
+ name: em-redis-unified
88
88
  prerelease: false
89
89
  requirement: &id005 !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
92
92
  - - "="
93
93
  - !ruby/object:Gem::Version
94
- hash: 27
94
+ hash: 13
95
95
  segments:
96
96
  - 0
97
- - 0
98
- - 2
99
- version: 0.0.2
97
+ - 4
98
+ - 1
99
+ version: 0.4.1
100
100
  type: :runtime
101
101
  version_requirements: *id005
102
102
  - !ruby/object:Gem::Dependency
@@ -146,7 +146,7 @@ dependencies:
146
146
  type: :development
147
147
  version_requirements: *id008
148
148
  - !ruby/object:Gem::Dependency
149
- name: em-spec
149
+ name: rspec
150
150
  prerelease: false
151
151
  requirement: &id009 !ruby/object:Gem::Requirement
152
152
  none: false
@@ -195,12 +195,17 @@ files:
195
195
  - lib/sensu/settings.rb
196
196
  - lib/sensu/redis.rb
197
197
  - lib/sensu/server.rb
198
+ - lib/sensu/utilities.rb
198
199
  - lib/sensu/client.rb
200
+ - lib/sensu/rabbitmq.rb
199
201
  - lib/sensu/process.rb
202
+ - lib/sensu/extensions/handlers/debug.rb
203
+ - lib/sensu/extensions/mutators/only_check_output.rb
200
204
  - lib/sensu/cli.rb
205
+ - lib/sensu/logstream.rb
206
+ - lib/sensu/extensions.rb
201
207
  - lib/sensu/io.rb
202
208
  - lib/sensu/base.rb
203
- - lib/sensu/logger.rb
204
209
  - lib/sensu.rb
205
210
  - sensu.gemspec
206
211
  - README.md