sensu 0.9.0.beta → 0.9.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/sensu-api CHANGED
@@ -4,5 +4,4 @@ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE_
4
4
  require 'sensu/api'
5
5
 
6
6
  options = Sensu::Config.read_arguments(ARGV)
7
- options['type'] = 'api'
8
7
  Sensu::API.run(options)
data/bin/sensu-client CHANGED
@@ -4,5 +4,4 @@ $: << 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'
8
7
  Sensu::Client.run(options)
data/bin/sensu-server CHANGED
@@ -4,5 +4,4 @@ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE_
4
4
  require 'sensu/server'
5
5
 
6
6
  options = Sensu::Config.read_arguments(ARGV)
7
- options['type'] = 'server'
8
7
  Sensu::Server.run(options)
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.9.0.beta"
2
+ VERSION = "0.9.0.beta.1"
3
3
  end
data/lib/sensu/api.rb CHANGED
@@ -25,7 +25,7 @@ module Sensu
25
25
  def self.setup(options={})
26
26
  config = Sensu::Config.new(options)
27
27
  $settings = config.settings
28
- $logger = config.open_log
28
+ $logger = config.logger || config.open_log
29
29
  if options[:daemonize]
30
30
  Process.daemonize
31
31
  end
data/lib/sensu/client.rb CHANGED
@@ -26,7 +26,7 @@ module Sensu
26
26
  def initialize(options={})
27
27
  config = Sensu::Config.new(options)
28
28
  @settings = config.settings
29
- @logger = config.open_log
29
+ @logger = config.logger || config.open_log
30
30
  end
31
31
 
32
32
  def stop(signal)
data/lib/sensu/config.rb CHANGED
@@ -17,6 +17,8 @@ module Sensu
17
17
  class Config
18
18
  attr_accessor :settings, :logger
19
19
 
20
+ SERVICE = File.basename($0).split('-').last
21
+
20
22
  DEFAULT_OPTIONS = {
21
23
  :log_file => '/tmp/sensu.log',
22
24
  :config_file => '/etc/sensu/config.json',
@@ -28,16 +30,27 @@ module Sensu
28
30
 
29
31
  def initialize(options={})
30
32
  @options = DEFAULT_OPTIONS.merge(options)
33
+ if options[:log_file]
34
+ open_log
35
+ end
31
36
  read_config
32
- validate_config if @options[:validate]
37
+ if @options[:validate]
38
+ validate_config
39
+ end
33
40
  end
34
41
 
35
42
  def open_log
36
43
  @logger = Cabin::Channel.new
37
44
  if File.writable?(@options[:log_file]) || !File.exist?(@options[:log_file]) && File.writable?(File.dirname(@options[:log_file]))
38
- STDOUT.reopen(@options[:log_file], 'a')
39
- STDERR.reopen(STDOUT)
40
- ruby_logger = Logger.new(STDOUT)
45
+ ruby_logger = case SERVICE
46
+ when 'rake'
47
+ Logger.new(@options[:log_file])
48
+ else
49
+ STDOUT.reopen(@options[:log_file], 'a')
50
+ STDERR.reopen(STDOUT)
51
+ STDOUT.sync = true
52
+ Logger.new(STDOUT)
53
+ end
41
54
  else
42
55
  invalid_config('log file is not writable: ' + @options[:log_file])
43
56
  end
@@ -67,22 +80,29 @@ module Sensu
67
80
  invalid_config('configuration snippet file (' + snippet_file + ') must be valid JSON: ' + error.to_s)
68
81
  end
69
82
  merged_settings = @settings.to_hash.deep_merge(snippet_hash)
70
- @logger.warn('[settings] configuration snippet (' + snippet_file + ') applied changes: ' + @settings.deep_diff(merged_settings).to_json) if @logger
83
+ if @logger
84
+ @logger.warn('[settings] configuration snippet (' + snippet_file + ') applied changes: ' + @settings.deep_diff(merged_settings).to_json)
85
+ end
71
86
  @settings = Hashie::Mash.new(merged_settings)
72
87
  end
73
88
  end
74
89
  end
75
90
 
76
91
  def validate_config
77
- @logger.debug('[config] -- validating configuration') if @logger
92
+ if @logger
93
+ @logger.debug('[config] -- validating configuration')
94
+ end
78
95
  has_keys(%w[rabbitmq])
79
- case @options['type']
80
- when 'server'
96
+ case SERVICE
97
+ when 'server', 'rake'
81
98
  has_keys(%w[redis handlers checks])
82
99
  unless @settings.handlers.include?('default')
83
100
  invalid_config('missing default handler')
84
101
  end
85
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
86
106
  unless details.key?('type')
87
107
  invalid_config('missing type for handler ' + name)
88
108
  end
@@ -102,9 +122,9 @@ module Sensu
102
122
  invalid_config('unknown type for handler ' + name)
103
123
  end
104
124
  end
105
- when 'api'
125
+ when 'api', 'rake'
106
126
  has_keys(%w[redis api])
107
- when 'client'
127
+ when 'client', 'rake'
108
128
  has_keys(%w[client checks])
109
129
  unless @settings.client.name.is_a?(String)
110
130
  invalid_config('client must have a name')
@@ -137,9 +157,8 @@ module Sensu
137
157
  end
138
158
  end
139
159
  end
140
- if @options['type']
141
- @logger.debug('[config] -- configuration valid -- running ' + @options['type']) if @logger
142
- puts 'configuration valid -- running ' + @options['type']
160
+ if @logger
161
+ @logger.debug('[config] -- configuration valid -- running ' + SERVICE)
143
162
  end
144
163
  end
145
164
 
@@ -152,7 +171,6 @@ module Sensu
152
171
  end
153
172
 
154
173
  def invalid_config(message)
155
- @logger.error('[config] -- configuration invalid -- ' + message) if @logger
156
174
  raise 'configuration invalid, ' + message
157
175
  end
158
176
 
@@ -163,7 +181,6 @@ module Sensu
163
181
  puts opts
164
182
  exit
165
183
  end
166
- current_process = File.basename($0)
167
184
  opts.on('-c', '--config FILE', 'Sensu JSON config FILE (default: /etc/sensu/config.json)') do |file|
168
185
  options[:config_file] = file
169
186
  end
@@ -47,6 +47,9 @@ end
47
47
 
48
48
  module Process
49
49
  def self.write_pid(pid_file)
50
+ if pid_file.nil?
51
+ raise 'a pid file path must be provided'
52
+ end
50
53
  begin
51
54
  File.open(pid_file, 'w') do |file|
52
55
  file.write(self.pid.to_s + "\n")
@@ -63,8 +66,10 @@ module Process
63
66
  raise 'cannot detach from controlling terminal'
64
67
  end
65
68
  trap 'SIGHUP', 'IGNORE'
66
- exit if pid = fork
67
- Dir.chdir "/"
69
+ if pid = fork
70
+ exit
71
+ end
72
+ Dir.chdir('/')
68
73
  ObjectSpace.each_object(IO) do |io|
69
74
  unless [STDIN, STDOUT, STDERR].include?(io)
70
75
  begin
data/lib/sensu/server.rb CHANGED
@@ -34,7 +34,7 @@ module Sensu
34
34
  def initialize(options={})
35
35
  config = Sensu::Config.new(options)
36
36
  @settings = config.settings
37
- @logger = config.open_log
37
+ @logger = config.logger || config.open_log
38
38
  end
39
39
 
40
40
  def stop(signal)
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31098121
4
+ hash: 62196273
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 0
10
10
  - beta
11
- version: 0.9.0.beta
11
+ - 1
12
+ version: 0.9.0.beta.1
12
13
  platform: ruby
13
14
  authors:
14
15
  - Sean Porter
@@ -17,7 +18,7 @@ autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2011-12-21 00:00:00 -08:00
21
+ date: 2011-12-22 00:00:00 -08:00
21
22
  default_executable:
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency