sensu 0.5.13 → 0.5.14

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.5.12)
4
+ sensu (0.5.13)
5
5
  amqp (= 0.7.4)
6
6
  async_sinatra
7
7
  em-hiredis
data/lib/sensu/client.rb CHANGED
@@ -52,19 +52,28 @@ module Sensu
52
52
  @settings['client'][key].to_s
53
53
  end
54
54
  if unmatched_tokens.empty?
55
- EM.system('sh', '-c', command + ' 2>&1') do |output, status|
56
- result['check'].merge!({'status' => status.exitstatus, 'output' => output})
55
+ execute = proc do
56
+ IO.popen(command + ' 2>&1') do |io|
57
+ result['check']['output'] = io.read
58
+ end
59
+ result['check']['status'] = $?.exitstatus
60
+ result
61
+ end
62
+ publish = proc do |result|
57
63
  @result_queue.publish(result.to_json)
58
- @checks_in_progress.delete(check['name'])
64
+ @checks_in_progress.delete(result['check']['name'])
59
65
  end
66
+ EM.defer(execute, publish)
60
67
  else
61
- result['check'].merge!({'status' => 3, 'output' => 'Missing client attributes: ' + unmatched_tokens.join(', ')})
68
+ result['check']['status'] = 3
69
+ result['check']['output'] = 'Missing client attributes: ' + unmatched_tokens.join(', ')
62
70
  @result_queue.publish(result.to_json)
63
71
  @checks_in_progress.delete(check['name'])
64
72
  end
65
73
  end
66
74
  else
67
- result['check'].merge!({'status' => 3, 'output' => 'Unknown check'})
75
+ result['check']['status'] = 3
76
+ result['check']['output'] = 'Unknown check'
68
77
  @result_queue.publish(result.to_json)
69
78
  @checks_in_progress.delete(check['name'])
70
79
  end
data/lib/sensu/config.rb CHANGED
@@ -58,19 +58,5 @@ module Sensu
58
58
  optparse.parse!(arguments)
59
59
  options
60
60
  end
61
-
62
- def create_working_directory
63
- begin
64
- Dir.mkdir('/tmp/sensu')
65
- rescue SystemCallError
66
- end
67
- end
68
-
69
- def purge_working_directory
70
- Dir.foreach('/tmp/sensu') do |file|
71
- next if file == '.' || file == '..'
72
- File.delete('/tmp/sensu/' + file)
73
- end
74
- end
75
61
  end
76
62
  end
data/lib/sensu/server.rb CHANGED
@@ -7,13 +7,13 @@ module Sensu
7
7
  alias :redis_connection :redis
8
8
 
9
9
  def self.run(options={})
10
+ EM.threadpool_size = 15
10
11
  EM.run do
11
12
  server = self.new(options)
12
13
  server.setup_logging
13
14
  server.setup_redis
14
15
  server.setup_amqp
15
16
  server.setup_keepalives
16
- server.setup_handlers
17
17
  server.setup_results
18
18
  unless server.is_worker
19
19
  server.setup_publisher
@@ -33,7 +33,6 @@ module Sensu
33
33
 
34
34
  def initialize(options={})
35
35
  config = Sensu::Config.new(:config_file => options[:config_file])
36
- config.create_working_directory
37
36
  @settings = config.settings
38
37
  @is_worker = options[:worker]
39
38
  end
@@ -61,39 +60,21 @@ module Sensu
61
60
  end
62
61
  end
63
62
 
64
- def setup_handlers
65
- @handler_queue = EM::Queue.new
66
- handlers_in_progress = 0
67
- handle = Proc.new do |event|
68
- if handlers_in_progress < 15
69
- event_file = proc do
70
- handlers_in_progress += 1
71
- file_name = '/tmp/sensu/event-' + UUIDTools::UUID.random_create.to_s
72
- File.open(file_name, 'w') do |file|
73
- file.write(JSON.pretty_generate(event))
74
- end
75
- file_name
76
- end
77
- handler = proc do |event_file|
78
- EM.system('sh', '-c', @settings['handlers'][event['check']['handler']] + ' -f ' + event_file + ' 2>&1') do |output, status|
79
- EM.debug('handled :: ' + event['check']['handler'] + ' :: ' + status.exitstatus.to_s + ' :: ' + output)
80
- File.delete(event_file)
81
- handlers_in_progress -= 1
82
- end
83
- end
84
- EM.defer(event_file, handler)
85
- else
86
- @handler_queue.push(event)
87
- end
88
- EM.next_tick do
89
- @handler_queue.pop(&handle)
63
+ def handle_event(event)
64
+ handler = proc do
65
+ result = Hash.new
66
+ IO.popen(@settings['handlers'][event['check']['handler']] + ' 2>&1', 'r+') do |io|
67
+ io.write(JSON.pretty_generate(event))
68
+ io.close_write
69
+ result['output'] = io.read
90
70
  end
71
+ result['status'] = $?.exitstatus
72
+ result
91
73
  end
92
- @handler_queue.pop(&handle)
93
- end
94
-
95
- def handle_event(event)
96
- @handler_queue.push(event)
74
+ report = proc do |result|
75
+ EM.debug('handled :: ' + event['check']['handler'] + ' :: ' + result['status'].to_s + ' :: ' + result['output'])
76
+ end
77
+ EM.defer(handler, report)
97
78
  end
98
79
 
99
80
  def process_result(result)
@@ -102,8 +83,8 @@ module Sensu
102
83
  client = JSON.parse(client_json)
103
84
  check = result['check']
104
85
  check.merge!(@settings['checks'][check['name']]) if @settings['checks'].has_key?(check['name'])
105
- check['handler'] = 'default' unless check['handler']
106
- event = {'client' => client, 'check' => check}
86
+ check['handler'] ||= 'default'
87
+ event = {'client' => client, 'check' => check, 'occurrences' => 1}
107
88
  if check['type'] == 'metric'
108
89
  handle_event(event)
109
90
  else
@@ -114,12 +95,14 @@ module Sensu
114
95
  event['action'] = 'resolve'
115
96
  handle_event(event)
116
97
  elsif check['status'] > 0
117
- occurrences = 1
118
98
  if previous_event && check['status'] == previous_event['status']
119
- occurrences = previous_event['occurrences'] += 1
99
+ event['occurrences'] = previous_event['occurrences'] += 1
120
100
  end
121
- @redis.hset('events:' + client['name'], check['name'], {'status' => check['status'], 'output' => check['output'], 'occurrences' => occurrences}.to_json).callback do
122
- event['occurrences'] = occurrences
101
+ @redis.hset('events:' + client['name'], check['name'], {
102
+ 'status' => check['status'],
103
+ 'output' => check['output'],
104
+ 'occurrences' => event['occurrences']
105
+ }.to_json).callback do
123
106
  event['action'] = 'create'
124
107
  handle_event(event)
125
108
  end
@@ -167,15 +150,18 @@ module Sensu
167
150
  result = {'client' => client['name'], 'check' => {'name' => 'keepalive', 'issued' => Time.now.to_i}}
168
151
  case
169
152
  when time_since_last_check >= 180
170
- result['check'].merge!({'status' => 2, 'output' => 'No keep-alive sent from host in over 180 seconds'})
153
+ result['check']['status'] = 2
154
+ result['check']['output'] = 'No keep-alive sent from host in over 180 seconds'
171
155
  @result_queue.publish(result.to_json)
172
156
  when time_since_last_check >= 120
173
- result['check'].merge!({'status' => 1, 'output' => 'No keep-alive sent from host in over 120 seconds'})
157
+ result['check']['status'] = 1
158
+ result['check']['output'] = 'No keep-alive sent from host in over 120 seconds'
174
159
  @result_queue.publish(result.to_json)
175
160
  else
176
161
  @redis.hexists('events:' + client_id, 'keepalive').callback do |exists|
177
162
  if exists == 1
178
- result['check'].merge!({'status' => 0, 'output' => 'Keep-alive sent from host'})
163
+ result['check']['status'] = 0
164
+ result['check']['output'] = 'Keep-alive sent from host'
179
165
  @result_queue.publish(result.to_json)
180
166
  end
181
167
  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.13"
3
+ s.version = "0.5.14"
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.13
5
+ version: 0.5.14
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-22 00:00:00 Z
14
+ date: 2011-09-26 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: amqp