sensu 0.13.0.alpha.2-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ module Sensu
2
+ class Socket < EM::Connection
3
+ attr_accessor :logger, :settings, :transport, :reply
4
+
5
+ def respond(data)
6
+ unless @reply == false
7
+ send_data(data)
8
+ end
9
+ end
10
+
11
+ def receive_data(data)
12
+ if data =~ /[\x80-\xff]/n
13
+ @logger.warn('socket received non-ascii characters')
14
+ respond('invalid')
15
+ elsif data.strip == 'ping'
16
+ @logger.debug('socket received ping')
17
+ respond('pong')
18
+ else
19
+ @logger.debug('socket received data', {
20
+ :data => data
21
+ })
22
+ begin
23
+ check = MultiJson.load(data)
24
+ check[:issued] = Time.now.to_i
25
+ check[:status] ||= 0
26
+ validates = [
27
+ check[:name] =~ /^[\w\.-]+$/,
28
+ check[:output].is_a?(String),
29
+ check[:status].is_a?(Integer)
30
+ ].all?
31
+ if validates
32
+ payload = {
33
+ :client => @settings[:client][:name],
34
+ :check => check
35
+ }
36
+ @logger.info('publishing check result', {
37
+ :payload => payload
38
+ })
39
+ @transport.publish(:direct, 'results', MultiJson.dump(payload))
40
+ respond('ok')
41
+ else
42
+ @logger.warn('invalid check result', {
43
+ :check => check
44
+ })
45
+ respond('invalid')
46
+ end
47
+ rescue MultiJson::ParseError => error
48
+ @logger.warn('check result must be valid json', {
49
+ :data => data,
50
+ :error => error.to_s
51
+ })
52
+ respond('invalid')
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ class SocketHandler < EM::Connection
59
+ attr_accessor :on_success, :on_error
60
+
61
+ def connection_completed
62
+ @connected_at = Time.now.to_f
63
+ @inactivity_timeout = comm_inactivity_timeout
64
+ end
65
+
66
+ def unbind
67
+ if @connected_at
68
+ elapsed_time = Time.now.to_f - @connected_at
69
+ if elapsed_time >= @inactivity_timeout
70
+ @on_error.call('socket inactivity timeout')
71
+ else
72
+ @on_success.call('wrote to socket')
73
+ end
74
+ else
75
+ @on_error.call('failed to connect to socket')
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,60 @@
1
+ gem 'uuidtools', '2.1.4'
2
+
3
+ require 'uuidtools'
4
+
5
+ module Sensu
6
+ module Utilities
7
+ def testing?
8
+ File.basename($0) == 'rspec'
9
+ end
10
+
11
+ def retry_until_true(wait=0.5, &block)
12
+ EM::Timer.new(wait) do
13
+ unless block.call
14
+ retry_until_true(wait, &block)
15
+ end
16
+ end
17
+ end
18
+
19
+ def deep_merge(hash_one, hash_two)
20
+ merged = hash_one.dup
21
+ hash_two.each do |key, value|
22
+ merged[key] = case
23
+ when hash_one[key].is_a?(Hash) && value.is_a?(Hash)
24
+ deep_merge(hash_one[key], value)
25
+ when hash_one[key].is_a?(Array) && value.is_a?(Array)
26
+ hash_one[key].concat(value).uniq
27
+ else
28
+ value
29
+ end
30
+ end
31
+ merged
32
+ end
33
+
34
+ def random_uuid
35
+ UUIDTools::UUID.random_create.to_s
36
+ end
37
+
38
+ def redact_sensitive(hash, keys=nil)
39
+ keys ||= %w[
40
+ password passwd pass
41
+ api_key api_token
42
+ access_key secret_key private_key
43
+ secret
44
+ ]
45
+ hash = hash.dup
46
+ hash.each do |key, value|
47
+ if keys.include?(key.to_s)
48
+ hash[key] = "REDACTED"
49
+ elsif value.is_a?(Hash)
50
+ hash[key] = redact_sensitive(value, keys)
51
+ elsif value.is_a?(Array)
52
+ hash[key] = value.map do |item|
53
+ item.is_a?(Hash) ? redact_sensitive(item, keys) : item
54
+ end
55
+ end
56
+ end
57
+ hash
58
+ end
59
+ end
60
+ end
data/sensu.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'lib', 'sensu', 'constants')
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'sensu'
6
+ s.version = Sensu::VERSION
7
+ s.platform = RUBY_PLATFORM =~ /java/ ? Gem::Platform::JAVA : Gem::Platform::RUBY
8
+ s.authors = ['Sean Porter', 'Justin Kolberg']
9
+ s.email = ['portertech@gmail.com', 'justin.kolberg@sonian.net']
10
+ s.homepage = 'https://github.com/sensu/sensu'
11
+ s.summary = 'A monitoring framework'
12
+ s.description = 'A monitoring framework that aims to be simple, malleable, and scalable. Uses the publish/subscribe model.'
13
+ s.license = 'MIT'
14
+ s.has_rdoc = false
15
+
16
+ s.add_dependency('json') if RUBY_VERSION < "1.9"
17
+ s.add_dependency('multi_json', '1.10.1')
18
+ s.add_dependency('uuidtools', '2.1.4')
19
+ s.add_dependency('sensu-em', '2.0.0')
20
+ s.add_dependency('sensu-logger', '0.0.1')
21
+ s.add_dependency('sensu-settings', '0.0.5')
22
+ s.add_dependency('sensu-extension', '0.0.3')
23
+ s.add_dependency('sensu-extensions', '0.0.5')
24
+ s.add_dependency('sensu-transport', '0.0.2')
25
+ s.add_dependency('sensu-spawn', '0.0.3')
26
+ s.add_dependency('em-redis-unified', '0.5.0')
27
+ s.add_dependency('sinatra', '1.3.5')
28
+ s.add_dependency('async_sinatra', '1.0.0')
29
+ s.add_dependency('thin', '1.5.0') unless RUBY_PLATFORM =~ /java/
30
+
31
+ s.add_development_dependency('rake')
32
+ s.add_development_dependency('rspec')
33
+ s.add_development_dependency('em-http-request')
34
+
35
+ s.files = Dir.glob('{bin,lib}/**/*') + %w[sensu.gemspec README.md CHANGELOG.md MIT-LICENSE.txt]
36
+ s.executables = Dir.glob('bin/**/*').map { |file| File.basename(file) }
37
+ s.require_paths = ['lib']
38
+ end
metadata ADDED
@@ -0,0 +1,277 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.13.0.alpha.2
5
+ platform: java
6
+ authors:
7
+ - Sean Porter
8
+ - Justin Kolberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.10.1
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - '='
24
+ - !ruby/object:Gem::Version
25
+ version: 1.10.1
26
+ prerelease: false
27
+ type: :runtime
28
+ - !ruby/object:Gem::Dependency
29
+ name: uuidtools
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.4
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 2.1.4
40
+ prerelease: false
41
+ type: :runtime
42
+ - !ruby/object:Gem::Dependency
43
+ name: sensu-em
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 2.0.0
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.0
54
+ prerelease: false
55
+ type: :runtime
56
+ - !ruby/object:Gem::Dependency
57
+ name: sensu-logger
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.0.1
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '='
66
+ - !ruby/object:Gem::Version
67
+ version: 0.0.1
68
+ prerelease: false
69
+ type: :runtime
70
+ - !ruby/object:Gem::Dependency
71
+ name: sensu-settings
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '='
75
+ - !ruby/object:Gem::Version
76
+ version: 0.0.5
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '='
80
+ - !ruby/object:Gem::Version
81
+ version: 0.0.5
82
+ prerelease: false
83
+ type: :runtime
84
+ - !ruby/object:Gem::Dependency
85
+ name: sensu-extension
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '='
89
+ - !ruby/object:Gem::Version
90
+ version: 0.0.3
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '='
94
+ - !ruby/object:Gem::Version
95
+ version: 0.0.3
96
+ prerelease: false
97
+ type: :runtime
98
+ - !ruby/object:Gem::Dependency
99
+ name: sensu-extensions
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '='
103
+ - !ruby/object:Gem::Version
104
+ version: 0.0.5
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.0.5
110
+ prerelease: false
111
+ type: :runtime
112
+ - !ruby/object:Gem::Dependency
113
+ name: sensu-transport
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '='
117
+ - !ruby/object:Gem::Version
118
+ version: 0.0.2
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '='
122
+ - !ruby/object:Gem::Version
123
+ version: 0.0.2
124
+ prerelease: false
125
+ type: :runtime
126
+ - !ruby/object:Gem::Dependency
127
+ name: sensu-spawn
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '='
131
+ - !ruby/object:Gem::Version
132
+ version: 0.0.3
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '='
136
+ - !ruby/object:Gem::Version
137
+ version: 0.0.3
138
+ prerelease: false
139
+ type: :runtime
140
+ - !ruby/object:Gem::Dependency
141
+ name: em-redis-unified
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '='
145
+ - !ruby/object:Gem::Version
146
+ version: 0.5.0
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '='
150
+ - !ruby/object:Gem::Version
151
+ version: 0.5.0
152
+ prerelease: false
153
+ type: :runtime
154
+ - !ruby/object:Gem::Dependency
155
+ name: sinatra
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '='
159
+ - !ruby/object:Gem::Version
160
+ version: 1.3.5
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '='
164
+ - !ruby/object:Gem::Version
165
+ version: 1.3.5
166
+ prerelease: false
167
+ type: :runtime
168
+ - !ruby/object:Gem::Dependency
169
+ name: async_sinatra
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - '='
173
+ - !ruby/object:Gem::Version
174
+ version: 1.0.0
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '='
178
+ - !ruby/object:Gem::Version
179
+ version: 1.0.0
180
+ prerelease: false
181
+ type: :runtime
182
+ - !ruby/object:Gem::Dependency
183
+ name: rake
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ prerelease: false
195
+ type: :development
196
+ - !ruby/object:Gem::Dependency
197
+ name: rspec
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - '>='
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ prerelease: false
209
+ type: :development
210
+ - !ruby/object:Gem::Dependency
211
+ name: em-http-request
212
+ version_requirements: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ prerelease: false
223
+ type: :development
224
+ description: A monitoring framework that aims to be simple, malleable, and scalable. Uses the publish/subscribe model.
225
+ email:
226
+ - portertech@gmail.com
227
+ - justin.kolberg@sonian.net
228
+ executables:
229
+ - sensu-api
230
+ - sensu-client
231
+ - sensu-server
232
+ extensions: []
233
+ extra_rdoc_files: []
234
+ files:
235
+ - CHANGELOG.md
236
+ - MIT-LICENSE.txt
237
+ - README.md
238
+ - bin/sensu-api
239
+ - bin/sensu-client
240
+ - bin/sensu-server
241
+ - lib/sensu.rb
242
+ - lib/sensu/api.rb
243
+ - lib/sensu/cli.rb
244
+ - lib/sensu/client.rb
245
+ - lib/sensu/constants.rb
246
+ - lib/sensu/daemon.rb
247
+ - lib/sensu/redis.rb
248
+ - lib/sensu/sandbox.rb
249
+ - lib/sensu/server.rb
250
+ - lib/sensu/socket.rb
251
+ - lib/sensu/utilities.rb
252
+ - sensu.gemspec
253
+ homepage: https://github.com/sensu/sensu
254
+ licenses:
255
+ - MIT
256
+ metadata: {}
257
+ post_install_message:
258
+ rdoc_options: []
259
+ require_paths:
260
+ - lib
261
+ required_ruby_version: !ruby/object:Gem::Requirement
262
+ requirements:
263
+ - - '>='
264
+ - !ruby/object:Gem::Version
265
+ version: '0'
266
+ required_rubygems_version: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - '>'
269
+ - !ruby/object:Gem::Version
270
+ version: 1.3.1
271
+ requirements: []
272
+ rubyforge_project:
273
+ rubygems_version: 2.2.2
274
+ signing_key:
275
+ specification_version: 4
276
+ summary: A monitoring framework
277
+ test_files: []