sensu 0.24.1-java → 0.25.0.beta-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ require "sensu/api/utilities/publish_check_result"
2
+
3
+ module Sensu
4
+ module API
5
+ module Utilities
6
+ module ResolveEvent
7
+ include PublishCheckResult
8
+
9
+ # Resolve an event. This method publishes a check result with
10
+ # a check status of `0` (OK) to resolve the event. The
11
+ # published check result uses `force_resolve` to ensure the
12
+ # event is resolved and removed from the registry, even if the
13
+ # current event has an event action of `flapping` etc.
14
+ #
15
+ # @param event_json [String] JSON formatted event data.
16
+ def resolve_event(event_json)
17
+ event = Sensu::JSON.load(event_json)
18
+ check = event[:check].merge(
19
+ :output => "Resolving on request of the API",
20
+ :status => 0,
21
+ :force_resolve => true
22
+ )
23
+ check.delete(:history)
24
+ publish_check_result(event[:client][:name], check)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ module Sensu
2
+ module API
3
+ module Utilities
4
+ module TransportInfo
5
+ # Retreive the Sensu Transport info, if the API is connected
6
+ # to it, keepalive messages and consumers, and results
7
+ # messages and consumers.
8
+ #
9
+ # @yield [Hash] passes Transport info to the callback/block.
10
+ def transport_info
11
+ info = {
12
+ :keepalives => {
13
+ :messages => nil,
14
+ :consumers => nil
15
+ },
16
+ :results => {
17
+ :messages => nil,
18
+ :consumers => nil
19
+ },
20
+ :connected => @transport.connected?
21
+ }
22
+ if @transport.connected?
23
+ @transport.stats("keepalives") do |stats|
24
+ info[:keepalives] = stats
25
+ @transport.stats("results") do |stats|
26
+ info[:results] = stats
27
+ yield(info)
28
+ end
29
+ end
30
+ else
31
+ yield(info)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -373,6 +373,31 @@ module Sensu
373
373
  end
374
374
  end
375
375
 
376
+ # Create a check result intended for deregistering a client.
377
+ # Client definitions may contain `:deregistration` configuration,
378
+ # containing custom attributes and handler information. By
379
+ # default, the deregistration check result sets the `:handler` to
380
+ # `deregistration`. If the client provides its own `:deregistration`
381
+ # configuration, it's deep merged with the defaults. The
382
+ # check `:name`, `:output`, `:status`, `:issued`, and
383
+ # `:executed` values are always overridden to guard against
384
+ # an invalid definition.
385
+ def deregister
386
+ check = {:handler => "deregistration", :interval => 1}
387
+ if @settings[:client].has_key?(:deregistration)
388
+ check = deep_merge(check, @settings[:client][:deregistration])
389
+ end
390
+ timestamp = Time.now.to_i
391
+ overrides = {
392
+ :name => "deregistration",
393
+ :output => "client initiated deregistration",
394
+ :status => 1,
395
+ :issued => timestamp,
396
+ :executed => timestamp
397
+ }
398
+ publish_check_result(check.merge(overrides))
399
+ end
400
+
376
401
  # Close the Sensu client TCP and UDP sockets. This method
377
402
  # iterates through `@sockets`, which contains socket server
378
403
  # signatures (Fixnum) and connection objects. A signature
@@ -448,10 +473,12 @@ module Sensu
448
473
  # Stop the Sensu client process, pausing it, completing check
449
474
  # executions in progress, closing the transport connection, and
450
475
  # exiting the process (exit 0). After pausing the process, the
451
- # process/daemon `@state` is set to `:stopping`.
476
+ # process/daemon `@state` is set to `:stopping`. Also sends
477
+ # deregistration check result if configured to do so.
452
478
  def stop
453
479
  @logger.warn("stopping")
454
480
  pause
481
+ deregister if @settings[:client][:deregister] == true
455
482
  @state = :stopping
456
483
  complete_checks_in_progress do
457
484
  close_sockets
@@ -244,7 +244,7 @@ module Sensu
244
244
  when :udp
245
245
  process_data(data)
246
246
  when :tcp
247
- if EM.reactor_running?
247
+ if EM::reactor_running?
248
248
  reset_watchdog
249
249
  end
250
250
  @data_buffer << data
@@ -1,7 +1,7 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
3
  # Sensu release version.
4
- VERSION = "0.24.1".freeze
4
+ VERSION = "0.25.0.beta".freeze
5
5
 
6
6
  # Sensu check severities.
7
7
  SEVERITIES = %w[ok warning critical unknown].freeze
data/lib/sensu/daemon.rb CHANGED
@@ -37,9 +37,10 @@ module Sensu
37
37
  attr_reader :start_time
38
38
 
39
39
  # Initialize the Sensu process. Set the start time, initial
40
- # service state, set up the logger, load settings, load
41
- # extensions, and optionally daemonize the process and/or create a
42
- # PID file. A subclass may override this method.
40
+ # service state, set up the logger, and load settings. This method
41
+ # will load extensions and setup Sensu Spawn if the Sensu process
42
+ # is not the Sensu API. This method can and optionally daemonize
43
+ # the process and/or create a PID file.
43
44
  #
44
45
  # @param options [Hash]
45
46
  def initialize(options={})
@@ -48,8 +49,10 @@ module Sensu
48
49
  @timers = {:run => []}
49
50
  setup_logger(options)
50
51
  load_settings(options)
51
- load_extensions(options)
52
- setup_spawn
52
+ unless sensu_service_name == "api"
53
+ load_extensions(options)
54
+ setup_spawn
55
+ end
53
56
  setup_process(options)
54
57
  end
55
58
 
@@ -164,7 +167,7 @@ module Sensu
164
167
  @logger.info("configuring sensu spawn", :settings => @settings[:sensu][:spawn])
165
168
  threadpool_size = @settings[:sensu][:spawn][:limit] + 10
166
169
  @logger.debug("setting eventmachine threadpool size", :size => threadpool_size)
167
- EM.threadpool_size = threadpool_size
170
+ EM::threadpool_size = threadpool_size
168
171
  Spawn.setup(@settings[:sensu][:spawn])
169
172
  end
170
173
 
@@ -264,7 +267,7 @@ module Sensu
264
267
  @logger.info("reconnected to transport")
265
268
  resume
266
269
  end
267
- yield(@transport)
270
+ yield(@transport) if block_given?
268
271
  end
269
272
  end
270
273
 
@@ -295,12 +298,19 @@ module Sensu
295
298
  @logger.info("reconnected to redis")
296
299
  resume
297
300
  end
298
- yield(@redis)
301
+ yield(@redis) if block_given?
299
302
  end
300
303
  end
301
304
 
302
305
  private
303
306
 
307
+ # Get the Sensu service name.
308
+ #
309
+ # @return [String] Sensu service name.
310
+ def sensu_service_name
311
+ File.basename($0).split("-").last
312
+ end
313
+
304
314
  # Write the current process ID (PID) to a file (PID file). This
305
315
  # method will cause the Sensu service to exit (2) if the PID file
306
316
  # cannot be written to.
@@ -619,15 +619,16 @@ module Sensu
619
619
  end
620
620
  end
621
621
 
622
- # Determine the Sensu transport publish options for a
623
- # subscription. If a subscription begins with a transport pipe
622
+ # Determine the Sensu Transport publish options for a
623
+ # subscription. If a subscription begins with a Transport pipe
624
624
  # type, either "direct:" or "roundrobin:", the subscription uses
625
- # a direct transport pipe. If a subscription does not specify a
626
- # transport pipe type, a fanout transport pipe is used.
625
+ # a direct Transport pipe. If a subscription does not specify a
626
+ # Transport pipe type, a fanout Transport pipe is used.
627
627
  #
628
628
  # @param subscription [String]
629
- # @return [Array] containing the transport publish options:
630
- # the transport pipe type, pipe, and the message to be
629
+ # @param message [String]
630
+ # @return [Array] containing the Transport publish options:
631
+ # the Transport pipe type, pipe, and the message to be
631
632
  # published.
632
633
  def transport_publish_options(subscription, message)
633
634
  _, raw_type = subscription.split(":", 2).reverse
@@ -639,13 +640,13 @@ module Sensu
639
640
  end
640
641
  end
641
642
 
642
- # Publish a check request to the transport. A check request is
643
+ # Publish a check request to the Transport. A check request is
643
644
  # composed of a check `:name`, an `:issued` timestamp, a check
644
645
  # `:command` if available, and a check `:extension if available.
645
- # The check request is published to a transport pipe, for each
646
+ # The check request is published to a Transport pipe, for each
646
647
  # of the check `:subscribers` in its definition, eg. "webserver".
647
648
  # JSON serialization is used when publishing the check request
648
- # payload to the transport pipes. Transport errors are logged.
649
+ # payload to the Transport pipes. Transport errors are logged.
649
650
  #
650
651
  # @param check [Hash] definition.
651
652
  def publish_check_request(check)
@@ -727,12 +728,12 @@ module Sensu
727
728
  schedule_check_executions(standard_checks + extension_checks)
728
729
  end
729
730
 
730
- # Publish a check result to the transport for processing. A
731
+ # Publish a check result to the Transport for processing. A
731
732
  # check result is composed of a client name and a check
732
733
  # definition, containing check `:output` and `:status`. A client
733
734
  # signature is added to the check result payload if one is
734
735
  # registered for the client. JSON serialization is used when
735
- # publishing the check result payload to the transport pipe.
736
+ # publishing the check result payload to the Transport pipe.
736
737
  # Transport errors are logged.
737
738
  #
738
739
  # @param client_name [String]
@@ -1076,7 +1077,7 @@ module Sensu
1076
1077
  end
1077
1078
 
1078
1079
  # Start the Sensu server process, connecting to Redis, the
1079
- # transport, and calling the `bootstrap()` method.
1080
+ # Transport, and calling the `bootstrap()` method.
1080
1081
  def start
1081
1082
  setup_connections do
1082
1083
  bootstrap
data/sensu.gemspec CHANGED
@@ -22,9 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "sensu-transport", "6.0.0"
23
23
  s.add_dependency "sensu-spawn", "2.2.0"
24
24
  s.add_dependency "sensu-redis", "1.4.0"
25
- s.add_dependency "sinatra", "1.4.6"
26
- s.add_dependency "async_sinatra", "1.2.0"
27
- s.add_dependency "thin", "1.6.4" unless RUBY_PLATFORM =~ /java/
25
+ s.add_dependency "em-http-server", "0.1.8"
28
26
 
29
27
  s.add_development_dependency "rake", "10.5.0"
30
28
  s.add_development_dependency "rspec", "~> 3.0.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.1
4
+ version: 0.25.0.beta
5
5
  platform: java
6
6
  authors:
7
7
  - Sean Porter
@@ -9,218 +9,204 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-06-07 00:00:00.000000000 Z
12
+ date: 2016-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 1.2.0.1
20
15
  name: eventmachine
21
- prerelease: false
22
- type: :runtime
23
16
  version_requirements: !ruby/object:Gem::Requirement
24
17
  requirements:
25
18
  - - '='
26
19
  - !ruby/object:Gem::Version
27
20
  version: 1.2.0.1
28
- - !ruby/object:Gem::Dependency
29
21
  requirement: !ruby/object:Gem::Requirement
30
22
  requirements:
31
23
  - - '='
32
24
  - !ruby/object:Gem::Version
33
- version: 2.0.0
34
- name: sensu-json
25
+ version: 1.2.0.1
35
26
  prerelease: false
36
27
  type: :runtime
28
+ - !ruby/object:Gem::Dependency
29
+ name: sensu-json
37
30
  version_requirements: !ruby/object:Gem::Requirement
38
31
  requirements:
39
32
  - - '='
40
33
  - !ruby/object:Gem::Version
41
34
  version: 2.0.0
42
- - !ruby/object:Gem::Dependency
43
35
  requirement: !ruby/object:Gem::Requirement
44
36
  requirements:
45
37
  - - '='
46
38
  - !ruby/object:Gem::Version
47
- version: 1.2.0
48
- name: sensu-logger
39
+ version: 2.0.0
49
40
  prerelease: false
50
41
  type: :runtime
42
+ - !ruby/object:Gem::Dependency
43
+ name: sensu-logger
51
44
  version_requirements: !ruby/object:Gem::Requirement
52
45
  requirements:
53
46
  - - '='
54
47
  - !ruby/object:Gem::Version
55
48
  version: 1.2.0
56
- - !ruby/object:Gem::Dependency
57
49
  requirement: !ruby/object:Gem::Requirement
58
50
  requirements:
59
51
  - - '='
60
52
  - !ruby/object:Gem::Version
61
- version: 5.2.0
62
- name: sensu-settings
53
+ version: 1.2.0
63
54
  prerelease: false
64
55
  type: :runtime
56
+ - !ruby/object:Gem::Dependency
57
+ name: sensu-settings
65
58
  version_requirements: !ruby/object:Gem::Requirement
66
59
  requirements:
67
60
  - - '='
68
61
  - !ruby/object:Gem::Version
69
62
  version: 5.2.0
70
- - !ruby/object:Gem::Dependency
71
63
  requirement: !ruby/object:Gem::Requirement
72
64
  requirements:
73
65
  - - '='
74
66
  - !ruby/object:Gem::Version
75
- version: 1.5.0
76
- name: sensu-extension
67
+ version: 5.2.0
77
68
  prerelease: false
78
69
  type: :runtime
70
+ - !ruby/object:Gem::Dependency
71
+ name: sensu-extension
79
72
  version_requirements: !ruby/object:Gem::Requirement
80
73
  requirements:
81
74
  - - '='
82
75
  - !ruby/object:Gem::Version
83
76
  version: 1.5.0
84
- - !ruby/object:Gem::Dependency
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
79
  - - '='
88
80
  - !ruby/object:Gem::Version
89
81
  version: 1.5.0
90
- name: sensu-extensions
91
82
  prerelease: false
92
83
  type: :runtime
84
+ - !ruby/object:Gem::Dependency
85
+ name: sensu-extensions
93
86
  version_requirements: !ruby/object:Gem::Requirement
94
87
  requirements:
95
88
  - - '='
96
89
  - !ruby/object:Gem::Version
97
90
  version: 1.5.0
98
- - !ruby/object:Gem::Dependency
99
91
  requirement: !ruby/object:Gem::Requirement
100
92
  requirements:
101
93
  - - '='
102
94
  - !ruby/object:Gem::Version
103
- version: 6.0.0
104
- name: sensu-transport
95
+ version: 1.5.0
105
96
  prerelease: false
106
97
  type: :runtime
98
+ - !ruby/object:Gem::Dependency
99
+ name: sensu-transport
107
100
  version_requirements: !ruby/object:Gem::Requirement
108
101
  requirements:
109
102
  - - '='
110
103
  - !ruby/object:Gem::Version
111
104
  version: 6.0.0
112
- - !ruby/object:Gem::Dependency
113
105
  requirement: !ruby/object:Gem::Requirement
114
106
  requirements:
115
107
  - - '='
116
108
  - !ruby/object:Gem::Version
117
- version: 2.2.0
118
- name: sensu-spawn
109
+ version: 6.0.0
119
110
  prerelease: false
120
111
  type: :runtime
112
+ - !ruby/object:Gem::Dependency
113
+ name: sensu-spawn
121
114
  version_requirements: !ruby/object:Gem::Requirement
122
115
  requirements:
123
116
  - - '='
124
117
  - !ruby/object:Gem::Version
125
118
  version: 2.2.0
126
- - !ruby/object:Gem::Dependency
127
119
  requirement: !ruby/object:Gem::Requirement
128
120
  requirements:
129
121
  - - '='
130
122
  - !ruby/object:Gem::Version
131
- version: 1.4.0
132
- name: sensu-redis
123
+ version: 2.2.0
133
124
  prerelease: false
134
125
  type: :runtime
126
+ - !ruby/object:Gem::Dependency
127
+ name: sensu-redis
135
128
  version_requirements: !ruby/object:Gem::Requirement
136
129
  requirements:
137
130
  - - '='
138
131
  - !ruby/object:Gem::Version
139
132
  version: 1.4.0
140
- - !ruby/object:Gem::Dependency
141
133
  requirement: !ruby/object:Gem::Requirement
142
134
  requirements:
143
135
  - - '='
144
136
  - !ruby/object:Gem::Version
145
- version: 1.4.6
146
- name: sinatra
137
+ version: 1.4.0
147
138
  prerelease: false
148
139
  type: :runtime
140
+ - !ruby/object:Gem::Dependency
141
+ name: em-http-server
149
142
  version_requirements: !ruby/object:Gem::Requirement
150
143
  requirements:
151
144
  - - '='
152
145
  - !ruby/object:Gem::Version
153
- version: 1.4.6
154
- - !ruby/object:Gem::Dependency
146
+ version: 0.1.8
155
147
  requirement: !ruby/object:Gem::Requirement
156
148
  requirements:
157
149
  - - '='
158
150
  - !ruby/object:Gem::Version
159
- version: 1.2.0
160
- name: async_sinatra
151
+ version: 0.1.8
161
152
  prerelease: false
162
153
  type: :runtime
154
+ - !ruby/object:Gem::Dependency
155
+ name: rake
163
156
  version_requirements: !ruby/object:Gem::Requirement
164
157
  requirements:
165
158
  - - '='
166
159
  - !ruby/object:Gem::Version
167
- version: 1.2.0
168
- - !ruby/object:Gem::Dependency
160
+ version: 10.5.0
169
161
  requirement: !ruby/object:Gem::Requirement
170
162
  requirements:
171
163
  - - '='
172
164
  - !ruby/object:Gem::Version
173
165
  version: 10.5.0
174
- name: rake
175
166
  prerelease: false
176
167
  type: :development
168
+ - !ruby/object:Gem::Dependency
169
+ name: rspec
177
170
  version_requirements: !ruby/object:Gem::Requirement
178
171
  requirements:
179
- - - '='
172
+ - - "~>"
180
173
  - !ruby/object:Gem::Version
181
- version: 10.5.0
182
- - !ruby/object:Gem::Dependency
174
+ version: 3.0.0
183
175
  requirement: !ruby/object:Gem::Requirement
184
176
  requirements:
185
177
  - - "~>"
186
178
  - !ruby/object:Gem::Version
187
179
  version: 3.0.0
188
- name: rspec
189
180
  prerelease: false
190
181
  type: :development
182
+ - !ruby/object:Gem::Dependency
183
+ name: em-http-request
191
184
  version_requirements: !ruby/object:Gem::Requirement
192
185
  requirements:
193
186
  - - "~>"
194
187
  - !ruby/object:Gem::Version
195
- version: 3.0.0
196
- - !ruby/object:Gem::Dependency
188
+ version: '1.1'
197
189
  requirement: !ruby/object:Gem::Requirement
198
190
  requirements:
199
191
  - - "~>"
200
192
  - !ruby/object:Gem::Version
201
193
  version: '1.1'
202
- name: em-http-request
203
194
  prerelease: false
204
195
  type: :development
196
+ - !ruby/object:Gem::Dependency
197
+ name: addressable
205
198
  version_requirements: !ruby/object:Gem::Requirement
206
199
  requirements:
207
- - - "~>"
200
+ - - '='
208
201
  - !ruby/object:Gem::Version
209
- version: '1.1'
210
- - !ruby/object:Gem::Dependency
202
+ version: 2.3.8
211
203
  requirement: !ruby/object:Gem::Requirement
212
204
  requirements:
213
205
  - - '='
214
206
  - !ruby/object:Gem::Version
215
207
  version: 2.3.8
216
- name: addressable
217
208
  prerelease: false
218
209
  type: :development
219
- version_requirements: !ruby/object:Gem::Requirement
220
- requirements:
221
- - - '='
222
- - !ruby/object:Gem::Version
223
- version: 2.3.8
224
210
  description: A monitoring framework that aims to be simple, malleable, and scalable.
225
211
  email:
226
212
  - portertech@gmail.com
@@ -241,7 +227,23 @@ files:
241
227
  - exe/sensu-install
242
228
  - exe/sensu-server
243
229
  - lib/sensu.rb
230
+ - lib/sensu/api/http_handler.rb
244
231
  - lib/sensu/api/process.rb
232
+ - lib/sensu/api/routes.rb
233
+ - lib/sensu/api/routes/aggregates.rb
234
+ - lib/sensu/api/routes/checks.rb
235
+ - lib/sensu/api/routes/clients.rb
236
+ - lib/sensu/api/routes/events.rb
237
+ - lib/sensu/api/routes/health.rb
238
+ - lib/sensu/api/routes/info.rb
239
+ - lib/sensu/api/routes/request.rb
240
+ - lib/sensu/api/routes/resolve.rb
241
+ - lib/sensu/api/routes/results.rb
242
+ - lib/sensu/api/routes/stashes.rb
243
+ - lib/sensu/api/utilities/publish_check_request.rb
244
+ - lib/sensu/api/utilities/publish_check_result.rb
245
+ - lib/sensu/api/utilities/resolve_event.rb
246
+ - lib/sensu/api/utilities/transport_info.rb
245
247
  - lib/sensu/api/validators.rb
246
248
  - lib/sensu/cli.rb
247
249
  - lib/sensu/client/process.rb
@@ -271,9 +273,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
271
273
  version: '0'
272
274
  required_rubygems_version: !ruby/object:Gem::Requirement
273
275
  requirements:
274
- - - ">="
276
+ - - ">"
275
277
  - !ruby/object:Gem::Version
276
- version: '0'
278
+ version: 1.3.1
277
279
  requirements: []
278
280
  rubyforge_project:
279
281
  rubygems_version: 2.4.8