sensu 0.9.5.beta.2 → 0.9.5.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sensu.rb +1 -1
- data/lib/sensu/api.rb +4 -2
- data/lib/sensu/config.rb +28 -8
- data/lib/sensu/patches/redis.rb +22 -11
- data/lib/sensu/version.rb +3 -0
- data/sensu.gemspec +1 -1
- metadata +5 -4
data/lib/sensu.rb
CHANGED
data/lib/sensu/api.rb
CHANGED
@@ -148,13 +148,15 @@ module Sensu
|
|
148
148
|
|
149
149
|
aget '/checks' do
|
150
150
|
$logger.debug('[checks] -- ' + request.ip + ' -- GET -- request for check list')
|
151
|
-
|
151
|
+
response = $settings.checks.map { |check, details| details.merge(:name => check) }
|
152
|
+
body response.to_json
|
152
153
|
end
|
153
154
|
|
154
155
|
aget '/check/:name' do |check|
|
155
156
|
$logger.debug('[check] -- ' + request.ip + ' -- GET -- request for check -- ' + check)
|
156
157
|
if $settings.checks.key?(check)
|
157
|
-
|
158
|
+
response = $settings.checks[check].merge(:name => check)
|
159
|
+
body response.to_json
|
158
160
|
else
|
159
161
|
status 404
|
160
162
|
body ''
|
data/lib/sensu/config.rb
CHANGED
@@ -12,7 +12,7 @@ require 'amqp'
|
|
12
12
|
require 'cabin'
|
13
13
|
require 'cabin/outputs/em/stdlib-logger'
|
14
14
|
|
15
|
-
require File.join(File.dirname(__FILE__), '
|
15
|
+
require File.join(File.dirname(__FILE__), 'version')
|
16
16
|
require File.join(File.dirname(__FILE__), 'patches', 'ruby')
|
17
17
|
require File.join(File.dirname(__FILE__), 'patches', 'amqp')
|
18
18
|
|
@@ -36,7 +36,9 @@ module Sensu
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def invalid_config(message)
|
39
|
-
|
39
|
+
puts 'CONFIGURATION INVALID: ' + message
|
40
|
+
puts 'SENSU NOT RUNNING'
|
41
|
+
exit 2
|
40
42
|
end
|
41
43
|
|
42
44
|
def setup_logging
|
@@ -75,6 +77,11 @@ module Sensu
|
|
75
77
|
unless details.subscribers.is_a?(Array) && details.subscribers.count > 0
|
76
78
|
invalid_config('missing subscribers for check ' + name)
|
77
79
|
end
|
80
|
+
details.subscribers.each do |subscriber|
|
81
|
+
unless subscriber.is_a?(String) && !subscriber.empty?
|
82
|
+
invalid_config('a check subscriber must be a string (not empty) for check ' + name)
|
83
|
+
end
|
84
|
+
end
|
78
85
|
end
|
79
86
|
if details.key?('handler')
|
80
87
|
unless details.handler.is_a?(String)
|
@@ -95,7 +102,7 @@ module Sensu
|
|
95
102
|
end
|
96
103
|
@settings.handlers.each do |name, details|
|
97
104
|
unless details.is_a?(Hash)
|
98
|
-
invalid_config('
|
105
|
+
invalid_config('handler details must be a hash for handler ' + name)
|
99
106
|
end
|
100
107
|
unless details['type'].is_a?(String)
|
101
108
|
invalid_config('missing type for handler ' + name)
|
@@ -128,12 +135,13 @@ module Sensu
|
|
128
135
|
end
|
129
136
|
|
130
137
|
def validate_api_settings
|
131
|
-
|
138
|
+
unless @settings.api.port.is_a?(Integer)
|
139
|
+
invalid_config('api port must be an integer')
|
140
|
+
end
|
141
|
+
if @settings.api.key?('user') || @settings.api.key?('password')
|
132
142
|
unless @settings.api.user.is_a?(String)
|
133
143
|
invalid_config('api user must be a string')
|
134
144
|
end
|
135
|
-
end
|
136
|
-
if @settings.api.key?('password')
|
137
145
|
unless @settings.api.password.is_a?(String)
|
138
146
|
invalid_config('api password must be a string')
|
139
147
|
end
|
@@ -150,6 +158,11 @@ module Sensu
|
|
150
158
|
unless @settings.client.subscriptions.is_a?(Array) && @settings.client.subscriptions.count > 0
|
151
159
|
invalid_config('client must have subscriptions')
|
152
160
|
end
|
161
|
+
@settings.client.subscriptions.each do |subscription|
|
162
|
+
unless subscription.is_a?(String) && !subscription.empty?
|
163
|
+
invalid_config('a client subscription must be a string (not empty)')
|
164
|
+
end
|
165
|
+
end
|
153
166
|
end
|
154
167
|
|
155
168
|
def has_keys(keys)
|
@@ -162,11 +175,11 @@ module Sensu
|
|
162
175
|
|
163
176
|
def validate_settings
|
164
177
|
@logger.debug('[validate] -- validating configuration')
|
165
|
-
has_keys(%w[
|
178
|
+
has_keys(%w[checks])
|
166
179
|
validate_common_settings
|
167
180
|
case File.basename($0)
|
168
181
|
when 'rake'
|
169
|
-
has_keys(%w[
|
182
|
+
has_keys(%w[api handlers client])
|
170
183
|
validate_server_settings
|
171
184
|
validate_api_settings
|
172
185
|
validate_client_settings
|
@@ -187,6 +200,9 @@ module Sensu
|
|
187
200
|
if File.readable?(@options[:config_file])
|
188
201
|
begin
|
189
202
|
config_hash = JSON.parse(File.open(@options[:config_file], 'r').read)
|
203
|
+
%w[rabbitmq redis].each do |key|
|
204
|
+
config_hash[key] ||= Hash.new
|
205
|
+
end
|
190
206
|
rescue JSON::ParserError => error
|
191
207
|
invalid_config('configuration file (' + @options[:config_file] + ') must be valid JSON: ' + error.to_s)
|
192
208
|
end
|
@@ -220,6 +236,10 @@ module Sensu
|
|
220
236
|
puts opts
|
221
237
|
exit
|
222
238
|
end
|
239
|
+
opts.on('-V', '--version', 'Display version') do
|
240
|
+
puts Sensu::VERSION
|
241
|
+
exit
|
242
|
+
end
|
223
243
|
opts.on('-c', '--config FILE', 'Sensu JSON config FILE. Default is /etc/sensu/config.json') do |file|
|
224
244
|
options[:config_file] = file
|
225
245
|
end
|
data/lib/sensu/patches/redis.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
1
|
module Redis
|
2
2
|
class Client
|
3
|
+
attr_accessor :redis_host, :redis_port, :redis_password
|
4
|
+
|
3
5
|
def connection_completed
|
4
6
|
@connected = true
|
5
7
|
@reconnecting = false
|
6
|
-
|
8
|
+
if @redis_password
|
9
|
+
auth(@redis_password).callback do |reply|
|
10
|
+
unless reply == "OK"
|
11
|
+
raise 'could not authenticate'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
info.callback do |reply|
|
16
|
+
redis_version = reply.split(/\n/).first.split(/:/).last
|
17
|
+
unless redis_version.to_i >= 2
|
18
|
+
raise 'redis version must be >= 2.0'
|
19
|
+
end
|
20
|
+
end
|
7
21
|
end
|
8
22
|
|
9
23
|
def close
|
@@ -15,14 +29,14 @@ module Redis
|
|
15
29
|
unless !@connected || @closing_connection
|
16
30
|
EM::Timer.new(1) do
|
17
31
|
@reconnecting = true
|
18
|
-
reconnect(@
|
32
|
+
reconnect(@redis_host, @redis_port)
|
19
33
|
end
|
20
34
|
else
|
21
35
|
until @queue.empty?
|
22
|
-
@queue.shift.fail RuntimeError.new
|
36
|
+
@queue.shift.fail RuntimeError.new('connection closed')
|
23
37
|
end
|
24
38
|
unless @connected
|
25
|
-
raise
|
39
|
+
raise 'could not connect to redis'
|
26
40
|
end
|
27
41
|
end
|
28
42
|
end
|
@@ -35,13 +49,10 @@ module Redis
|
|
35
49
|
def self.connect(options={})
|
36
50
|
host = options[:host] || 'localhost'
|
37
51
|
port = options[:port] || 6379
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
raise "redis version must be >= 2.0"
|
43
|
-
end
|
52
|
+
EM::connect(host, port, Redis::Client) do |client|
|
53
|
+
client.redis_host = host
|
54
|
+
client.redis_port = port
|
55
|
+
client.redis_password = options[:password]
|
44
56
|
end
|
45
|
-
redis
|
46
57
|
end
|
47
58
|
end
|
data/sensu.gemspec
CHANGED
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:
|
4
|
+
hash: 62196253
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
9
|
- 5
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.9.5.beta.
|
11
|
+
- 3
|
12
|
+
version: 0.9.5.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: 2012-03-
|
21
|
+
date: 2012-03-20 00:00:00 -07:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -222,6 +222,7 @@ files:
|
|
222
222
|
- lib/sensu/patches/redis.rb
|
223
223
|
- lib/sensu/patches/ruby.rb
|
224
224
|
- lib/sensu/server.rb
|
225
|
+
- lib/sensu/version.rb
|
225
226
|
- lib/sensu.rb
|
226
227
|
- sensu.gemspec
|
227
228
|
- README.org
|