sensu 0.8.0-x86-mingw32 → 0.8.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  pkg/*
2
2
  *~
3
+ *.vagrant
3
4
  \#*
4
5
  dump.rdb
5
6
  .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ branches:
2
+ except:
3
+ - hacking
4
+ notifications:
5
+ irc:
6
+ - "irc.freenode.net#sensu"
7
+ env:
8
+ - RACK_ENV=development
9
+ rvm:
10
+ - 1.8.7
11
+ - 1.9.2
12
+ - 1.9.3
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sensu (0.8.0)
4
+ sensu (0.8.3)
5
5
  amqp (= 0.7.4)
6
6
  async_sinatra
7
+ cabin (= 0.1.7)
7
8
  em-hiredis
8
- em-syslog
9
9
  hashie
10
10
  json
11
11
  rack (~> 1.3.4)
@@ -20,32 +20,39 @@ GEM
20
20
  async_sinatra (0.5.0)
21
21
  rack (>= 1.2.1)
22
22
  sinatra (>= 1.0)
23
- callsite (0.0.6)
24
- bundler (~> 1.0.0)
23
+ bacon (1.1.0)
24
+ cabin (0.1.7)
25
+ json
25
26
  daemons (1.1.4)
27
+ diff-lcs (1.1.3)
26
28
  em-hiredis (0.1.0)
27
29
  hiredis (~> 0.3.0)
28
- em-syslog (0.0.2)
29
- eventmachine
30
- em-ventually (0.1.2)
31
- callsite (~> 0.0.5)
30
+ em-spec (0.2.5)
31
+ bacon
32
32
  eventmachine
33
+ rspec (~> 2.6.0)
34
+ test-unit
33
35
  eventmachine (0.12.10)
34
36
  hashie (1.2.0)
35
37
  hiredis (0.3.2)
36
38
  json (1.6.1)
37
- mime-types (1.16)
38
- minitest (2.7.0)
39
39
  rack (1.3.5)
40
40
  rack-protection (1.1.4)
41
41
  rack
42
42
  rake (0.9.2)
43
- rest-client (1.6.7)
44
- mime-types (>= 1.16)
43
+ rspec (2.6.0)
44
+ rspec-core (~> 2.6.0)
45
+ rspec-expectations (~> 2.6.0)
46
+ rspec-mocks (~> 2.6.0)
47
+ rspec-core (2.6.4)
48
+ rspec-expectations (2.6.0)
49
+ diff-lcs (~> 1.1.2)
50
+ rspec-mocks (2.6.0)
45
51
  sinatra (1.3.1)
46
52
  rack (~> 1.3, >= 1.3.4)
47
53
  rack-protection (~> 1.1, >= 1.1.2)
48
54
  tilt (~> 1.3, >= 1.3.3)
55
+ test-unit (2.4.0)
49
56
  thin (1.2.11)
50
57
  daemons (>= 1.0.9)
51
58
  eventmachine (>= 0.12.6)
@@ -57,8 +64,6 @@ PLATFORMS
57
64
  ruby
58
65
 
59
66
  DEPENDENCIES
60
- em-ventually
61
- minitest (~> 2.7.0)
67
+ em-spec
62
68
  rake
63
- rest-client
64
69
  sensu!
data/README.org CHANGED
@@ -1,28 +1,35 @@
1
1
  * Welcome to Sensu
2
- Sensu is a monitoring system framework.
2
+ Sensu, a monitoring framework that aims to be simple, malleable, and scalable.
3
3
 
4
4
  [[https://github.com/sonian/sensu/raw/master/sensu-logo.png]]
5
5
 
6
- Checks can utilize user created plugins, returning an exit status code and outputting to STDOUT.
6
+ [[http://portertech.ca/2011/11/01/sensu-a-monitoring-framework][Blog post]]
7
7
 
8
- Check results are handled by user created handlers, receiving JSON formatted event data from STDIN.
8
+ [[http://www.sonian.com/cloud-tools/cloud-monitoring-sensu/][Homepage]]
9
9
  * Documentation
10
- Documentation can be found [[https://github.com/sonian/sensu/wiki][HERE]].
10
+ Find it [[https://github.com/sonian/sensu/wiki][HERE]].
11
+ * Other Projects
12
+ - [[https://github.com/sonian/sensu-plugins][Sensu Community Plugins]]
13
+ - [[https://github.com/sonian/sensu-dashboard][Sensu Dashboard]]
11
14
  * License
12
15
  Sensu is released under the [[https://github.com/sonian/sensu/blob/master/MIT-LICENSE.txt][MIT license]].
13
16
  * Contributing
14
- - [[http://help.github.com/fork-a-repo/][Fork]] [[https://github.com/sonian/sensu][Sensu]]
17
+ - [[http://help.github.com/fork-a-repo/][Fork]] Sensu
15
18
  - Use a [[https://github.com/dchelimsky/rspec/wiki/Topic-Branches][topic branch]]
16
19
  - Create a [[http://help.github.com/send-pull-requests/][pull request]]
17
20
 
18
21
  Keep it simple.
19
22
  ** Testing
20
- *** Requirements
23
+ *** Travis CI
24
+ [[https://secure.travis-ci.org/sonian/sensu.png]]
25
+ *** System Dependencies
26
+ - Ruby (MRI) & Rubygems
21
27
  - RabbitMQ
22
28
  - Redis
23
29
  *** Running
24
30
  : bundle install
25
- : rake test
31
+ : rake
26
32
  * Contributors
27
- - Sean Porter ([[https://twitter.com/#!/portertech][@portertech]])
28
- - Justin Kolberg ([[https://twitter.com/#!/amdprophet][@amdprophet]])
33
+ - [[http://twitter.com/portertech][Sean Porter]]
34
+ - [[http://twitter.com/amdprophet][Justin Kolberg]]
35
+ - [[http://twitter.com/kartar][James Turnbull]]
data/bin/sensu-client CHANGED
@@ -4,4 +4,5 @@ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE_
4
4
  require 'sensu/client'
5
5
 
6
6
  options = Sensu::Config.read_arguments(ARGV)
7
+ options['type'] = 'client'
7
8
  Sensu::Client.run(options)
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.4"
3
3
  end
data/lib/sensu/client.rb CHANGED
@@ -13,34 +13,39 @@ module Sensu
13
13
 
14
14
  %w[INT TERM].each do |signal|
15
15
  Signal.trap(signal) do
16
- EM.warning('[process] -- ' + signal + ' -- stopping sensu client')
17
- EM.add_timer(1) do
18
- EM.stop
19
- end
16
+ client.stop(signal)
20
17
  end
21
18
  end
22
19
  end
23
20
  end
24
21
 
25
22
  def initialize(options={})
26
- config = Sensu::Config.new(:config_file => options[:config_file])
23
+ config = Sensu::Config.new(options)
27
24
  @settings = config.settings
28
- EM.syslog_setup(@settings.syslog.host, @settings.syslog.port)
25
+ @logger = config.logger
26
+ end
27
+
28
+ def stop(signal)
29
+ @logger.warn('[process] -- ' + signal + ' -- stopping sensu client')
30
+ EM.add_timer(1) do
31
+ EM.stop
32
+ end
29
33
  end
30
34
 
31
35
  def setup_amqp
32
- EM.debug("[amqp] -- connecting to rabbitmq")
36
+ @logger.debug('[amqp] -- connecting to rabbitmq')
33
37
  connection = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
34
38
  @amq = MQ.new(connection)
35
39
  end
36
40
 
37
41
  def publish_keepalive
38
- EM.debug('[keepalive] -- publishing keepalive -- ' + @settings.client.timestamp.to_s)
42
+ @logger.debug('[keepalive] -- publishing keepalive -- ' + @settings.client.timestamp.to_s)
39
43
  @keepalive_queue ||= @amq.queue('keepalives')
40
44
  @keepalive_queue.publish(@settings.client.to_json)
41
45
  end
42
46
 
43
47
  def setup_keepalives
48
+ @logger.debug('[keepalive] -- setup keepalives')
44
49
  @settings.client.timestamp = Time.now.to_i
45
50
  publish_keepalive
46
51
  EM.add_periodic_timer(30) do
@@ -50,7 +55,7 @@ module Sensu
50
55
  end
51
56
 
52
57
  def publish_result(check)
53
- EM.info('[result] -- publishing check result -- ' + check.name)
58
+ @logger.info('[result] -- publishing check result -- ' + check.name)
54
59
  @result_queue ||= @amq.queue('results')
55
60
  @result_queue.publish({
56
61
  :client => @settings.client.name,
@@ -59,6 +64,7 @@ module Sensu
59
64
  end
60
65
 
61
66
  def execute_check(check)
67
+ @logger.debug('[execute] -- executing check -- ' + check.name)
62
68
  @checks_in_progress ||= Array.new
63
69
  if @settings.checks.key?(check.name)
64
70
  unless @checks_in_progress.include?(check.name)
@@ -82,7 +88,7 @@ module Sensu
82
88
  end
83
89
  EM.defer(execute, publish)
84
90
  else
85
- EM.warning('[execute] -- missing client attributes -- ' + unmatched_tokens.join(', ') + ' -- ' + check.name)
91
+ @logger.warn('[execute] -- missing client attributes -- ' + unmatched_tokens.join(', ') + ' -- ' + check.name)
86
92
  check.status = 3
87
93
  check.output = 'Missing client attributes: ' + unmatched_tokens.join(', ')
88
94
  check.internal = true
@@ -91,7 +97,7 @@ module Sensu
91
97
  end
92
98
  end
93
99
  else
94
- EM.warning('[execute] -- unkown check -- ' + check.name)
100
+ @logger.warn('[execute] -- unkown check -- ' + check.name)
95
101
  check.status = 3
96
102
  check.output = 'Unknown check'
97
103
  check.internal = true
@@ -101,22 +107,24 @@ module Sensu
101
107
  end
102
108
 
103
109
  def setup_subscriptions
110
+ @logger.debug('[subscribe] -- setup subscriptions')
104
111
  @check_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
105
112
  @settings.client.subscriptions.each do |exchange|
106
- EM.debug('[subscribe] -- queue binding to exchange -- ' + exchange)
113
+ @logger.debug('[subscribe] -- queue binding to exchange -- ' + exchange)
107
114
  @check_queue.bind(@amq.fanout(exchange))
108
115
  end
109
116
  @check_queue.subscribe do |check_json|
110
117
  check = Hashie::Mash.new(JSON.parse(check_json))
111
- EM.info('[subscribe] -- received check -- ' + check.name)
118
+ @logger.info('[subscribe] -- received check -- ' + check.name)
112
119
  execute_check(check)
113
120
  end
114
121
  end
115
122
 
116
123
  def setup_queue_monitor
124
+ @logger.debug('[monitor] -- setup queue monitor')
117
125
  EM.add_periodic_timer(5) do
118
126
  unless @check_queue.subscribed?
119
- EM.warning('[monitor] -- reconnecting to rabbitmq')
127
+ @logger.warn('[monitor] -- reconnecting to rabbitmq')
120
128
  @check_queue.delete
121
129
  EM.add_timer(1) do
122
130
  setup_subscriptions
@@ -126,8 +134,9 @@ module Sensu
126
134
  end
127
135
 
128
136
  def setup_socket
129
- EM.debug('[socket] -- starting up socket server')
137
+ @logger.debug('[socket] -- starting up socket server')
130
138
  EM.start_server('127.0.0.1', 3030, ClientSocket) do |socket|
139
+ socket.logger = @logger
131
140
  socket.client_name = @settings.client.name
132
141
  socket.result_queue = @amq.queue('results')
133
142
  end
@@ -135,35 +144,32 @@ module Sensu
135
144
  end
136
145
 
137
146
  class ClientSocket < EM::Connection
138
- attr_accessor :client_name, :result_queue
139
-
140
- def post_init
141
- EM.debug('[socket] -- client connected')
142
- end
147
+ attr_accessor :logger, :client_name, :result_queue
143
148
 
144
149
  def receive_data(data)
150
+ @logger.debug('[socket] -- client connected')
145
151
  begin
146
152
  check = Hashie::Mash.new(JSON.parse(data))
147
153
  validates = %w[name status output].all? do |key|
148
154
  check.key?(key)
149
155
  end
150
156
  if validates
151
- EM.info('[socket] -- publishing check result -- ' + check.name)
157
+ @logger.info('[socket] -- publishing check result -- ' + check.name)
152
158
  @result_queue.publish({
153
159
  :client => @client_name,
154
160
  :check => check.to_hash
155
161
  }.to_json)
156
162
  else
157
- EM.warning('[socket] -- a check name, exit status, and output are required -- e.g. {name: x, status: 0, output: "y"}')
163
+ @logger.warn('[socket] -- a check name, exit status, and output are required -- e.g. {name: x, status: 0, output: "y"}')
158
164
  end
159
165
  rescue JSON::ParserError
160
- EM.warning('[socket] -- could not parse check result -- expecting JSON')
166
+ @logger.warn('[socket] -- could not parse check result -- expecting JSON')
161
167
  end
162
168
  close_connection
163
169
  end
164
170
 
165
171
  def unbind
166
- EM.debug('[socket] -- client disconnected')
172
+ @logger.debug('[socket] -- client disconnected')
167
173
  end
168
174
  end
169
175
  end
data/lib/sensu/config.rb CHANGED
@@ -4,42 +4,83 @@ require 'json'
4
4
  require 'hashie'
5
5
  require 'uuidtools'
6
6
  require 'amqp'
7
- require 'em/syslog'
7
+ require 'cabin'
8
+ require 'cabin/outputs/em-stdlib-logger'
8
9
  require File.join(File.dirname(__FILE__), 'helpers')
9
10
 
10
11
  module Sensu
11
12
  class Config
12
- attr_accessor :settings
13
+ attr_accessor :settings, :logger
13
14
 
14
15
  def initialize(options={})
15
16
  config_file = options[:config_file] || '/etc/sensu/config.json'
16
- @settings = Hashie::Mash.new(JSON.parse(File.open(config_file, 'r').read))
17
- validate_config
17
+ if File.readable?(config_file)
18
+ begin
19
+ @settings = Hashie::Mash.new(JSON.parse(File.open(config_file, 'r').read))
20
+ rescue JSON::ParserError => e
21
+ invalid_config('configuration file must be valid JSON: ' + e)
22
+ end
23
+ else
24
+ invalid_config('configuration file does not exist or is not readable: ' + config_file)
25
+ end
26
+ @logger = Cabin::Channel.new
27
+ log_dir = File.writable?('/var/log') ? '/var/log' : '/tmp'
28
+ ruby_logger = Logger.new(File.join(log_dir, 'sensu.log'))
29
+ @logger.subscribe(Cabin::Outputs::EmStdlibLogger.new(ruby_logger))
30
+ @logger.level = options[:verbose] ? 'debug' : 'info'
31
+ validate_config(options['type'])
18
32
  end
19
33
 
20
- def validate_config
34
+ def validate_config(type)
35
+ @logger.debug('[config] -- validating configuration')
36
+ has_keys(%w[rabbitmq])
37
+ case type
38
+ when 'server'
39
+ has_keys(%w[redis handlers checks])
40
+ when 'api'
41
+ has_keys(%w[redis api])
42
+ when 'client'
43
+ has_keys(%w[client checks])
44
+ end
21
45
  @settings.checks.each do |name, details|
22
46
  unless details.interval.is_a?(Integer) && details.interval > 0
23
- raise 'configuration invalid, missing interval for check ' + name
47
+ invalid_config('missing interval for check ' + name)
24
48
  end
25
49
  unless details.command.is_a?(String)
26
- raise 'configuration invalid, missing command for check ' + name
50
+ invalid_config('missing command for check ' + name)
27
51
  end
28
52
  unless details.subscribers.is_a?(Array) && details.subscribers.count > 0
29
- raise 'configuration invalid, missing subscribers for check ' + name
53
+ invalid_config('missing subscribers for check ' + name)
30
54
  end
31
55
  end
32
56
  unless @settings.client.name.is_a?(String)
33
- raise 'configuration invalid, client must have a name'
57
+ invalid_config('client must have a name')
34
58
  end
35
59
  unless @settings.client.address.is_a?(String)
36
- raise 'configuration invalid, client must have an address (ip or hostname)'
60
+ invalid_config('client must have an address (ip or hostname)')
37
61
  end
38
62
  unless @settings.client.subscriptions.is_a?(Array) && @settings.client.subscriptions.count > 0
39
- raise 'configuration invalid, client must have subscriptions'
63
+ invalid_config('client must have subscriptions')
64
+ end
65
+ if type
66
+ @logger.debug('[config] -- configuration valid -- running ' + type)
67
+ puts 'configuration valid -- running ' + type
40
68
  end
41
69
  end
42
70
 
71
+ def has_keys(keys)
72
+ keys.each do |key|
73
+ unless @settings.key?(key)
74
+ invalid_config('missing the following key: ' + key)
75
+ end
76
+ end
77
+ end
78
+
79
+ def invalid_config(message)
80
+ @logger.error('[config] -- configuration invalid -- ' + message)
81
+ raise 'configuration invalid, ' + message
82
+ end
83
+
43
84
  def self.read_arguments(arguments)
44
85
  options = Hash.new
45
86
  optparse = OptionParser.new do |opts|
@@ -54,10 +95,12 @@ module Sensu
54
95
  options[:worker] = true
55
96
  end
56
97
  end
57
- options[:config_file] = nil
58
98
  opts.on('-c', '--config FILE', 'Sensu JSON config FILE (default: /etc/sensu/config.json)') do |file|
59
99
  options[:config_file] = file
60
100
  end
101
+ opts.on('-v', '--verbose', 'Enable verbose logging') do
102
+ options[:verbose] = true
103
+ end
61
104
  end
62
105
  optparse.parse!(arguments)
63
106
  options
data/sensu.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.authors = ["Sean Porter", "Justin Kolberg"]
8
8
  s.email = ["sean.porter@sonian.net", "justin.kolberg@sonian.net"]
9
9
  s.homepage = "https://github.com/sonian/sensu"
10
- s.summary = %q{A server monitoring framework}
11
- s.description = %q{A server monitoring framework using the publish-subscribe model}
10
+ s.summary = %q{A monitoring framework}
11
+ s.description = %q{A monitoring framework that aims to be simple, malleable, and scalable. Uses the publish/subscribe model.}
12
12
  s.license = "MIT"
13
13
  s.has_rdoc = false
14
14
 
@@ -16,16 +16,14 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency("json")
17
17
  s.add_dependency("hashie")
18
18
  s.add_dependency("uuidtools")
19
- s.add_dependency("em-syslog")
19
+ s.add_dependency("cabin", "0.1.7")
20
20
  s.add_dependency("em-hiredis")
21
21
  s.add_dependency("rack", "~> 1.3.4")
22
22
  s.add_dependency("async_sinatra")
23
23
  s.add_dependency("thin")
24
24
 
25
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")
26
+ s.add_development_dependency("em-spec")
29
27
 
30
28
  s.files = `git ls-files`.split("\n").reject {|f| f =~ /(dist|test|png)/}
31
29
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
data/sensu.windows CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.authors = ["Sean Porter", "Justin Kolberg"]
7
7
  s.email = ["sean.porter@sonian.net", "justin.kolberg@sonian.net"]
8
8
  s.homepage = "https://github.com/sonian/sensu"
9
- s.summary = %q{A server monitoring framework}
10
- s.description = %q{A server monitoring framework using the publish-subscribe model}
9
+ s.summary = %q{A monitoring framework}
10
+ s.description = %q{A monitoring framework that aims to be simple, malleable, and scalable. Uses the publish/subscribe model.}
11
11
  s.license = "MIT"
12
12
  s.has_rdoc = false
13
13
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency("json")
24
24
  s.add_dependency("hashie")
25
25
  s.add_dependency("uuidtools")
26
- s.add_dependency("em-syslog")
26
+ s.add_dependency("cabin", "0.1.7")
27
27
 
28
28
  s.files = `git ls-files`.split("\n").reject {|f| f =~ /(dist|test|server|api|png)/}
29
29
  s.executables = "sensu-client"
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: 63
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 4
10
+ version: 0.8.4
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-31 00:00:00 -07:00
19
+ date: 2011-11-09 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -97,20 +97,22 @@ dependencies:
97
97
  type: :runtime
98
98
  version_requirements: *id005
99
99
  - !ruby/object:Gem::Dependency
100
- name: em-syslog
100
+ name: cabin
101
101
  prerelease: false
102
102
  requirement: &id006 !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
105
- - - ">="
105
+ - - "="
106
106
  - !ruby/object:Gem::Version
107
- hash: 3
107
+ hash: 21
108
108
  segments:
109
109
  - 0
110
- version: "0"
110
+ - 1
111
+ - 7
112
+ version: 0.1.7
111
113
  type: :runtime
112
114
  version_requirements: *id006
113
- description: A server monitoring framework using the publish-subscribe model
115
+ description: A monitoring framework that aims to be simple, malleable, and scalable. Uses the publish/subscribe model.
114
116
  email:
115
117
  - sean.porter@sonian.net
116
118
  - justin.kolberg@sonian.net
@@ -122,6 +124,7 @@ extra_rdoc_files: []
122
124
 
123
125
  files:
124
126
  - .gitignore
127
+ - .travis.yml
125
128
  - Gemfile
126
129
  - Gemfile.lock
127
130
  - MIT-LICENSE.txt
@@ -167,6 +170,6 @@ rubyforge_project:
167
170
  rubygems_version: 1.3.7
168
171
  signing_key:
169
172
  specification_version: 3
170
- summary: A server monitoring framework
173
+ summary: A monitoring framework
171
174
  test_files: []
172
175