sensu 0.7.2-x86-mingw32 → 0.8.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sensu (0.7.0)
4
+ sensu (0.8.0)
5
5
  amqp (= 0.7.4)
6
6
  async_sinatra
7
7
  em-hiredis
8
8
  em-syslog
9
9
  hashie
10
10
  json
11
+ rack (~> 1.3.4)
11
12
  thin
12
13
  uuidtools
13
14
 
@@ -30,12 +31,12 @@ GEM
30
31
  callsite (~> 0.0.5)
31
32
  eventmachine
32
33
  eventmachine (0.12.10)
33
- hashie (1.1.0)
34
+ hashie (1.2.0)
34
35
  hiredis (0.3.2)
35
36
  json (1.6.1)
36
37
  mime-types (1.16)
37
- minitest (2.6.0)
38
- rack (1.3.4)
38
+ minitest (2.7.0)
39
+ rack (1.3.5)
39
40
  rack-protection (1.1.4)
40
41
  rack
41
42
  rake (0.9.2)
@@ -57,7 +58,7 @@ PLATFORMS
57
58
 
58
59
  DEPENDENCIES
59
60
  em-ventually
60
- minitest
61
+ minitest (~> 2.7.0)
61
62
  rake
62
63
  rest-client
63
64
  sensu!
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
2
 
4
3
  task :default => 'test'
5
4
 
6
- Rake::TestTask.new do |test|
7
- test.pattern = 'test/*_test.rb'
5
+ desc "Run tests"
6
+ task :test do
7
+ require File.join(File.dirname(__FILE__), 'test', 'helper')
8
+ Dir['test/*_test.rb'].each do |test|
9
+ require File.join(File.dirname(__FILE__), test)
10
+ end
8
11
  end
9
12
 
10
13
  desc "Build Sensu for Windows"
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/sensu/client.rb CHANGED
@@ -9,13 +9,15 @@ module Sensu
9
9
  client.setup_keepalives
10
10
  client.setup_subscriptions
11
11
  client.setup_queue_monitor
12
+ client.setup_socket
12
13
 
13
- Signal.trap('INT') do
14
- EM.stop
15
- end
16
-
17
- Signal.trap('TERM') do
18
- EM.stop
14
+ %w[INT TERM].each do |signal|
15
+ Signal.trap(signal) do
16
+ EM.warning('[process] -- ' + signal + ' -- stopping sensu client')
17
+ EM.add_timer(1) do
18
+ EM.stop
19
+ end
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -23,24 +25,32 @@ module Sensu
23
25
  def initialize(options={})
24
26
  config = Sensu::Config.new(:config_file => options[:config_file])
25
27
  @settings = config.settings
28
+ EM.syslog_setup(@settings.syslog.host, @settings.syslog.port)
26
29
  end
27
30
 
28
31
  def setup_amqp
32
+ EM.debug("[amqp] -- connecting to rabbitmq")
29
33
  connection = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
30
34
  @amq = MQ.new(connection)
31
35
  end
32
36
 
37
+ def publish_keepalive
38
+ EM.debug('[keepalive] -- publishing keepalive -- ' + @settings.client.timestamp.to_s)
39
+ @keepalive_queue ||= @amq.queue('keepalives')
40
+ @keepalive_queue.publish(@settings.client.to_json)
41
+ end
42
+
33
43
  def setup_keepalives
34
- keepalive_queue = @amq.queue('keepalives')
35
44
  @settings.client.timestamp = Time.now.to_i
36
- keepalive_queue.publish(@settings.client.to_json)
45
+ publish_keepalive
37
46
  EM.add_periodic_timer(30) do
38
47
  @settings.client.timestamp = Time.now.to_i
39
- keepalive_queue.publish(@settings.client.to_json)
48
+ publish_keepalive
40
49
  end
41
50
  end
42
51
 
43
52
  def publish_result(check)
53
+ EM.info('[result] -- publishing check result -- ' + check.name)
44
54
  @result_queue ||= @amq.queue('results')
45
55
  @result_queue.publish({
46
56
  :client => @settings.client.name,
@@ -72,6 +82,7 @@ module Sensu
72
82
  end
73
83
  EM.defer(execute, publish)
74
84
  else
85
+ EM.warning('[execute] -- missing client attributes -- ' + unmatched_tokens.join(', ') + ' -- ' + check.name)
75
86
  check.status = 3
76
87
  check.output = 'Missing client attributes: ' + unmatched_tokens.join(', ')
77
88
  check.internal = true
@@ -80,6 +91,7 @@ module Sensu
80
91
  end
81
92
  end
82
93
  else
94
+ EM.warning('[execute] -- unkown check -- ' + check.name)
83
95
  check.status = 3
84
96
  check.output = 'Unknown check'
85
97
  check.internal = true
@@ -91,10 +103,12 @@ module Sensu
91
103
  def setup_subscriptions
92
104
  @check_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
93
105
  @settings.client.subscriptions.each do |exchange|
106
+ EM.debug('[subscribe] -- queue binding to exchange -- ' + exchange)
94
107
  @check_queue.bind(@amq.fanout(exchange))
95
108
  end
96
109
  @check_queue.subscribe do |check_json|
97
110
  check = Hashie::Mash.new(JSON.parse(check_json))
111
+ EM.info('[subscribe] -- received check -- ' + check.name)
98
112
  execute_check(check)
99
113
  end
100
114
  end
@@ -102,6 +116,7 @@ module Sensu
102
116
  def setup_queue_monitor
103
117
  EM.add_periodic_timer(5) do
104
118
  unless @check_queue.subscribed?
119
+ EM.warning('[monitor] -- reconnecting to rabbitmq')
105
120
  @check_queue.delete
106
121
  EM.add_timer(1) do
107
122
  setup_subscriptions
@@ -109,5 +124,46 @@ module Sensu
109
124
  end
110
125
  end
111
126
  end
127
+
128
+ def setup_socket
129
+ EM.debug('[socket] -- starting up socket server')
130
+ EM.start_server('127.0.0.1', 3030, ClientSocket) do |socket|
131
+ socket.client_name = @settings.client.name
132
+ socket.result_queue = @amq.queue('results')
133
+ end
134
+ end
135
+ end
136
+
137
+ class ClientSocket < EM::Connection
138
+ attr_accessor :client_name, :result_queue
139
+
140
+ def post_init
141
+ EM.debug('[socket] -- client connected')
142
+ end
143
+
144
+ def receive_data(data)
145
+ begin
146
+ check = Hashie::Mash.new(JSON.parse(data))
147
+ validates = %w[name status output].all? do |key|
148
+ check.key?(key)
149
+ end
150
+ if validates
151
+ EM.info('[socket] -- publishing check result -- ' + check.name)
152
+ @result_queue.publish({
153
+ :client => @client_name,
154
+ :check => check.to_hash
155
+ }.to_json)
156
+ else
157
+ EM.warning('[socket] -- a check name, exit status, and output are required -- e.g. {name: x, status: 0, output: "y"}')
158
+ end
159
+ rescue JSON::ParserError
160
+ EM.warning('[socket] -- could not parse check result -- expecting JSON')
161
+ end
162
+ close_connection
163
+ end
164
+
165
+ def unbind
166
+ EM.debug('[socket] -- client disconnected')
167
+ end
112
168
  end
113
169
  end
data/lib/sensu/config.rb CHANGED
@@ -48,7 +48,7 @@ module Sensu
48
48
  exit
49
49
  end
50
50
  current_process = $0.split('/').last
51
- if current_process == 'sensu-server' || current_process == 'rake_test_loader.rb'
51
+ if current_process == 'sensu-server' || current_process == 'rake'
52
52
  options[:worker] = false
53
53
  opts.on('-w', '--worker', 'Only consume jobs, no check publishing (default: false)') do
54
54
  options[:worker] = true
data/sensu.gemspec CHANGED
@@ -18,13 +18,14 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency("uuidtools")
19
19
  s.add_dependency("em-syslog")
20
20
  s.add_dependency("em-hiredis")
21
+ s.add_dependency("rack", "~> 1.3.4")
21
22
  s.add_dependency("async_sinatra")
22
23
  s.add_dependency("thin")
23
24
 
24
- s.add_development_dependency('rake')
25
- s.add_development_dependency('minitest')
26
- s.add_development_dependency('em-ventually')
27
- s.add_development_dependency('rest-client')
25
+ s.add_development_dependency("rake")
26
+ s.add_development_dependency("minitest", "~> 2.7.0")
27
+ s.add_development_dependency("em-ventually")
28
+ s.add_development_dependency("rest-client")
28
29
 
29
30
  s.files = `git ls-files`.split("\n").reject {|f| f =~ /(dist|test|png)/}
30
31
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 2
10
- version: 0.7.2
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
11
  platform: x86-mingw32
12
12
  authors:
13
13
  - Sean Porter
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-14 00:00:00 -07:00
19
+ date: 2011-10-31 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency