sensu 0.9.0.beta → 0.9.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sensu-api +0 -1
- data/bin/sensu-client +0 -1
- data/bin/sensu-server +0 -1
- data/lib/sensu.rb +1 -1
- data/lib/sensu/api.rb +1 -1
- data/lib/sensu/client.rb +1 -1
- data/lib/sensu/config.rb +32 -15
- data/lib/sensu/helpers/ruby.rb +7 -2
- data/lib/sensu/server.rb +1 -1
- metadata +4 -3
data/bin/sensu-api
CHANGED
data/bin/sensu-client
CHANGED
data/bin/sensu-server
CHANGED
data/lib/sensu.rb
CHANGED
data/lib/sensu/api.rb
CHANGED
data/lib/sensu/client.rb
CHANGED
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
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
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
|
-
|
92
|
+
if @logger
|
93
|
+
@logger.debug('[config] -- validating configuration')
|
94
|
+
end
|
78
95
|
has_keys(%w[rabbitmq])
|
79
|
-
case
|
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 @
|
141
|
-
@logger.debug('[config] -- configuration valid -- running ' +
|
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
|
data/lib/sensu/helpers/ruby.rb
CHANGED
@@ -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
|
-
|
67
|
-
|
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
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:
|
4
|
+
hash: 62196273
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
|
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
|
+
date: 2011-12-22 00:00:00 -08:00
|
21
22
|
default_executable:
|
22
23
|
dependencies:
|
23
24
|
- !ruby/object:Gem::Dependency
|