sensu 0.9.0.beta.1 → 0.9.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.9.0.beta.1"
2
+ VERSION = "0.9.0.beta.2"
3
3
  end
data/lib/sensu/api.rb CHANGED
@@ -253,6 +253,7 @@ module Sensu
253
253
 
254
254
  def self.test(options={})
255
255
  self.setup(options)
256
+ $settings.client.timestamp = Time.now.to_i
256
257
  $redis.set('client:' + $settings.client.name, $settings.client.to_json).callback do
257
258
  $redis.sadd('clients', $settings.client.name).callback do
258
259
  $redis.hset('events:' + $settings.client.name, 'test', {
data/lib/sensu/config.rb CHANGED
@@ -17,15 +17,14 @@ module Sensu
17
17
  class Config
18
18
  attr_accessor :settings, :logger
19
19
 
20
- SERVICE = File.basename($0).split('-').last
21
-
22
20
  DEFAULT_OPTIONS = {
23
21
  :log_file => '/tmp/sensu.log',
24
22
  :config_file => '/etc/sensu/config.json',
25
23
  :config_dir => '/etc/sensu/conf.d',
26
24
  :validate => true,
25
+ :daemonize => false,
27
26
  :pid_file => '/tmp/' + File.basename($0) + '.pid',
28
- :daemonize => false
27
+ :service => File.basename($0)
29
28
  }
30
29
 
31
30
  def initialize(options={})
@@ -42,7 +41,7 @@ module Sensu
42
41
  def open_log
43
42
  @logger = Cabin::Channel.new
44
43
  if File.writable?(@options[:log_file]) || !File.exist?(@options[:log_file]) && File.writable?(File.dirname(@options[:log_file]))
45
- ruby_logger = case SERVICE
44
+ ruby_logger = case @options[:service]
46
45
  when 'rake'
47
46
  Logger.new(@options[:log_file])
48
47
  else
@@ -93,49 +92,27 @@ module Sensu
93
92
  @logger.debug('[config] -- validating configuration')
94
93
  end
95
94
  has_keys(%w[rabbitmq])
96
- case SERVICE
97
- when 'server', 'rake'
95
+ validate_common_config
96
+ case @options[:service]
97
+ when 'rake'
98
+ has_keys(%w[redis api handlers checks client])
99
+ validate_server_config
100
+ validate_client_config
101
+ when 'sensu-server'
98
102
  has_keys(%w[redis handlers checks])
99
- unless @settings.handlers.include?('default')
100
- invalid_config('missing default handler')
101
- end
102
- @settings.handlers.each do |name, details|
103
- unless details.is_a?(Hash)
104
- invalid_config('hander details must be a hash ' + name)
105
- end
106
- unless details.key?('type')
107
- invalid_config('missing type for handler ' + name)
108
- end
109
- case details.type
110
- when 'pipe'
111
- unless details.key?('command')
112
- invalid_config('missing command for pipe handler ' + name)
113
- end
114
- when 'amqp'
115
- unless details.key?('exchange')
116
- invalid_config('missing exchange details for amqp handler ' + name)
117
- end
118
- unless details.exchange.key?('name')
119
- invalid_config('missing exchange name for amqp handler ' + name)
120
- end
121
- else
122
- invalid_config('unknown type for handler ' + name)
123
- end
124
- end
125
- when 'api', 'rake'
103
+ validate_server_config
104
+ when 'sensu-api'
126
105
  has_keys(%w[redis api])
127
- when 'client', 'rake'
106
+ when 'sensu-client'
128
107
  has_keys(%w[client checks])
129
- unless @settings.client.name.is_a?(String)
130
- invalid_config('client must have a name')
131
- end
132
- unless @settings.client.address.is_a?(String)
133
- invalid_config('client must have an address (ip or hostname)')
134
- end
135
- unless @settings.client.subscriptions.is_a?(Array) && @settings.client.subscriptions.count > 0
136
- invalid_config('client must have subscriptions')
137
- end
108
+ validate_client_config
109
+ end
110
+ if @logger
111
+ @logger.debug('[config] -- configuration valid -- running ' + @options[:service])
138
112
  end
113
+ end
114
+
115
+ def validate_common_config
139
116
  @settings.checks.each do |name, details|
140
117
  unless details.interval.is_a?(Integer) && details.interval > 0
141
118
  invalid_config('missing interval for check ' + name)
@@ -157,8 +134,46 @@ module Sensu
157
134
  end
158
135
  end
159
136
  end
160
- if @logger
161
- @logger.debug('[config] -- configuration valid -- running ' + SERVICE)
137
+ end
138
+
139
+ def validate_server_config
140
+ unless @settings.handlers.include?('default')
141
+ invalid_config('missing default handler')
142
+ end
143
+ @settings.handlers.each do |name, details|
144
+ unless details.is_a?(Hash)
145
+ invalid_config('hander details must be a hash ' + name)
146
+ end
147
+ unless details.key?('type')
148
+ invalid_config('missing type for handler ' + name)
149
+ end
150
+ case details.type
151
+ when 'pipe'
152
+ unless details.key?('command')
153
+ invalid_config('missing command for pipe handler ' + name)
154
+ end
155
+ when 'amqp'
156
+ unless details.key?('exchange')
157
+ invalid_config('missing exchange details for amqp handler ' + name)
158
+ end
159
+ unless details.exchange.key?('name')
160
+ invalid_config('missing exchange name for amqp handler ' + name)
161
+ end
162
+ else
163
+ invalid_config('unknown type for handler ' + name)
164
+ end
165
+ end
166
+ end
167
+
168
+ def validate_client_config
169
+ unless @settings.client.name.is_a?(String)
170
+ invalid_config('client must have a name')
171
+ end
172
+ unless @settings.client.address.is_a?(String)
173
+ invalid_config('client must have an address (ip or hostname)')
174
+ end
175
+ unless @settings.client.subscriptions.is_a?(Array) && @settings.client.subscriptions.count > 0
176
+ invalid_config('client must have subscriptions')
162
177
  end
163
178
  end
164
179
 
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: 62196273
4
+ hash: 62196279
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 0
10
10
  - beta
11
- - 1
12
- version: 0.9.0.beta.1
11
+ - 2
12
+ version: 0.9.0.beta.2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Sean Porter