sensu 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sensu (0.4.0)
4
+ sensu (0.5.12)
5
5
  amqp (= 0.7.4)
6
6
  async_sinatra
7
7
  em-hiredis
@@ -18,7 +18,7 @@ GEM
18
18
  async_sinatra (0.5.0)
19
19
  rack (>= 1.2.1)
20
20
  sinatra (>= 1.0)
21
- callsite (0.0.5)
21
+ callsite (0.0.6)
22
22
  bundler (~> 1.0.0)
23
23
  daemons (1.1.4)
24
24
  em-hiredis (0.1.0)
@@ -30,12 +30,12 @@ GEM
30
30
  eventmachine
31
31
  eventmachine (0.12.10)
32
32
  hiredis (0.3.2)
33
- json (1.5.4)
33
+ json (1.6.1)
34
34
  mime-types (1.16)
35
- minitest (2.5.1)
36
- rack (1.3.2)
35
+ minitest (2.6.0)
36
+ rack (1.3.3)
37
37
  rake (0.9.2)
38
- rest-client (1.6.3)
38
+ rest-client (1.6.7)
39
39
  mime-types (>= 1.16)
40
40
  sinatra (1.2.6)
41
41
  rack (~> 1.1)
data/README.org CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  Check results are handled by user created handlers.
7
7
 
8
+ Documentation can be found [[https://github.com/sonian/sensu/wiki][here]].
9
+
8
10
  * License
9
11
  Sensu is released under the [[https://github.com/sonian/sensu/blob/master/MIT-LICENSE.txt][MIT license]].
10
12
 
@@ -19,19 +21,20 @@
19
21
  *** A Client Will
20
22
  - Have a set of attributes to describe it, including its responsibilities
21
23
  - Send keep-alives to a server
22
- - Subscribe to a set of queues bound to a set of fanout exchanges, determined by its responsibilities
24
+ - Subscribe to a queue bound to a set of fanout exchanges, determined by its responsibilities
23
25
  - Substitute tokens in check commands with their matching client attribute
26
+ - Report when it does not have a client attribute for token substitution
24
27
  - Receive checks from subscriptions, execute them, and publish the results to a queue with its client name
25
28
  - Not allow overlapping check executions of the same name
26
29
  - Report when it is unaware of a check it received from a subscription
27
30
 
28
31
  *** A Server Will
29
- - Subscribe to a queue for check scheduling, another for check results
30
- - Populate the check scheduling queue using a JSON config file
31
- - Pull a check from the check scheduling queue and push it onto its associated fanout exchanges
32
+ - Subscribe to a queue for check results, another for keep-alives
33
+ - Pull keep-alives, storing client details
34
+ - Publish checks on defined intervals to their associated fanout exchanges
32
35
  - Pull check results, storing the latest events for clients, a good result will flush a previous event for that client
33
36
  - Create an event when it stops receiving keep-alives from a client, a new keep-alive for the client will clear the event
34
- - Trigger a event handler, determined by the type of the check that produced the event, providing it with a JSON event file
37
+ - Trigger a event handler, either the default handler or one specified for the check, providing it with a JSON event file
35
38
 
36
39
  *** An API Will
37
40
  - List all current events
data/bin/sensu-api CHANGED
@@ -3,4 +3,4 @@
3
3
  $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
4
4
  require 'sensu/api'
5
5
 
6
- Sensu::API.run
6
+ Sensu::API.run(Sensu::Config.read_arguments(ARGV))
data/bin/sensu-client CHANGED
@@ -3,4 +3,4 @@
3
3
  $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
4
4
  require 'sensu/client'
5
5
 
6
- Sensu::Client.run
6
+ Sensu::Client.run(Sensu::Config.read_arguments(ARGV))
data/bin/sensu-server CHANGED
@@ -3,4 +3,4 @@
3
3
  $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
4
4
  require 'sensu/server'
5
5
 
6
- Sensu::Server.run
6
+ Sensu::Server.run(Sensu::Config.read_arguments(ARGV))
data/lib/sensu/client.rb CHANGED
@@ -71,11 +71,11 @@ module Sensu
71
71
  end
72
72
 
73
73
  def setup_subscriptions
74
- @uniq_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
74
+ @check_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
75
75
  @settings['client']['subscriptions'].each do |exchange|
76
- @uniq_queue.bind(@amq.fanout(exchange))
76
+ @check_queue.bind(@amq.fanout(exchange))
77
77
  end
78
- @uniq_queue.subscribe do |check_json|
78
+ @check_queue.subscribe do |check_json|
79
79
  check = JSON.parse(check_json)
80
80
  execute_check(check)
81
81
  end
@@ -83,8 +83,8 @@ module Sensu
83
83
 
84
84
  def monitor_queues
85
85
  EM.add_periodic_timer(5) do
86
- unless @uniq_queue.subscribed?
87
- @uniq_queue.delete
86
+ unless @check_queue.subscribed?
87
+ @check_queue.delete
88
88
  EM.add_timer(1) do
89
89
  setup_subscriptions
90
90
  end
data/lib/sensu/config.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems' if RUBY_VERSION < '1.9.0'
2
+ require 'optparse'
2
3
  require 'json'
3
4
  require 'uuidtools'
4
5
  require 'amqp'
@@ -38,6 +39,26 @@ module Sensu
38
39
  end
39
40
  end
40
41
 
42
+ def self.read_arguments(arguments)
43
+ options = Hash.new
44
+ optparse = OptionParser.new do |opts|
45
+ opts.on('-h', '--help', 'Display this screen') do
46
+ puts opts
47
+ exit
48
+ end
49
+ options[:worker] = false
50
+ opts.on('-w', '--worker', 'Only consume jobs, no check publishing (default: false)') do
51
+ options[:worker] = true
52
+ end
53
+ options[:config_file] = nil
54
+ opts.on('-c', '--config FILE', 'Sensu JSON config FILE (default: /etc/sensu/config.json)') do |file|
55
+ options[:config_file] = file
56
+ end
57
+ end
58
+ optparse.parse!(arguments)
59
+ options
60
+ end
61
+
41
62
  def create_working_directory
42
63
  begin
43
64
  Dir.mkdir('/tmp/sensu')
data/lib/sensu/server.rb CHANGED
@@ -3,7 +3,7 @@ require 'em-hiredis'
3
3
 
4
4
  module Sensu
5
5
  class Server
6
- attr_accessor :redis
6
+ attr_accessor :redis, :is_worker
7
7
  alias :redis_connection :redis
8
8
 
9
9
  def self.run(options={})
@@ -15,8 +15,10 @@ module Sensu
15
15
  server.setup_keepalives
16
16
  server.setup_handlers
17
17
  server.setup_results
18
- server.setup_publisher
19
- server.setup_keepalive_monitor
18
+ unless server.is_worker
19
+ server.setup_publisher
20
+ server.setup_keepalive_monitor
21
+ end
20
22
  server.monitor_queues
21
23
 
22
24
  Signal.trap('INT') do
@@ -33,6 +35,7 @@ module Sensu
33
35
  config = Sensu::Config.new(:config_file => options[:config_file])
34
36
  config.create_working_directory
35
37
  @settings = config.settings
38
+ @is_worker = options[:worker]
36
39
  end
37
40
 
38
41
  def setup_logging
@@ -155,7 +158,6 @@ module Sensu
155
158
  end
156
159
 
157
160
  def setup_keepalive_monitor
158
- result_queue = @amq.queue('results')
159
161
  EM.add_periodic_timer(30) do
160
162
  @redis.smembers('clients').callback do |clients|
161
163
  clients.each do |client_id|
@@ -166,15 +168,15 @@ module Sensu
166
168
  case
167
169
  when time_since_last_check >= 180
168
170
  result['check'].merge!({'status' => 2, 'output' => 'No keep-alive sent from host in over 180 seconds'})
169
- result_queue.publish(result.to_json)
171
+ @result_queue.publish(result.to_json)
170
172
  when time_since_last_check >= 120
171
173
  result['check'].merge!({'status' => 1, 'output' => 'No keep-alive sent from host in over 120 seconds'})
172
- result_queue.publish(result.to_json)
174
+ @result_queue.publish(result.to_json)
173
175
  else
174
176
  @redis.hexists('events:' + client_id, 'keepalive').callback do |exists|
175
177
  if exists == 1
176
178
  result['check'].merge!({'status' => 0, 'output' => 'Keep-alive sent from host'})
177
- result_queue.publish(result.to_json)
179
+ @result_queue.publish(result.to_json)
178
180
  end
179
181
  end
180
182
  end
@@ -187,16 +189,10 @@ module Sensu
187
189
  def monitor_queues
188
190
  EM.add_periodic_timer(5) do
189
191
  unless @keepalive_queue.subscribed?
190
- @keepalive_queue.delete
191
- EM.add_timer(1) do
192
- setup_keepalives
193
- end
192
+ setup_keepalives
194
193
  end
195
194
  unless @result_queue.subscribed?
196
- @result_queue.delete
197
- EM.add_timer(1) do
198
- setup_results
199
- end
195
+ setup_results
200
196
  end
201
197
  end
202
198
  end
data/sensu.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sensu"
3
- s.version = "0.5.12"
3
+ s.version = "0.5.13"
4
4
  s.authors = ["Sean Porter", "Justin Kolberg"]
5
5
  s.email = ["sean.porter@sonian.net", "justin.kolberg@sonian.net"]
6
6
  s.homepage = "https://github.com/sonian/sensu"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.12
5
+ version: 0.5.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sean Porter
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-09-19 00:00:00 Z
14
+ date: 2011-09-22 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: amqp