sensu 0.24.1 → 0.25.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sensu/api/http_handler.rb +340 -0
- data/lib/sensu/api/process.rb +59 -947
- data/lib/sensu/api/routes.rb +72 -0
- data/lib/sensu/api/routes/aggregates.rb +191 -0
- data/lib/sensu/api/routes/checks.rb +25 -0
- data/lib/sensu/api/routes/clients.rb +152 -0
- data/lib/sensu/api/routes/events.rb +76 -0
- data/lib/sensu/api/routes/health.rb +34 -0
- data/lib/sensu/api/routes/info.rb +28 -0
- data/lib/sensu/api/routes/request.rb +33 -0
- data/lib/sensu/api/routes/resolve.rb +31 -0
- data/lib/sensu/api/routes/results.rb +116 -0
- data/lib/sensu/api/routes/stashes.rb +102 -0
- data/lib/sensu/api/utilities/publish_check_request.rb +57 -0
- data/lib/sensu/api/utilities/publish_check_result.rb +36 -0
- data/lib/sensu/api/utilities/resolve_event.rb +29 -0
- data/lib/sensu/api/utilities/transport_info.rb +37 -0
- data/lib/sensu/client/process.rb +28 -1
- data/lib/sensu/client/socket.rb +1 -1
- data/lib/sensu/constants.rb +1 -1
- data/lib/sensu/daemon.rb +18 -8
- data/lib/sensu/server/process.rb +13 -12
- data/sensu.gemspec +1 -4
- metadata +23 -35
@@ -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
|
data/lib/sensu/client/process.rb
CHANGED
@@ -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
|
data/lib/sensu/client/socket.rb
CHANGED
data/lib/sensu/constants.rb
CHANGED
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
|
41
|
-
# extensions
|
42
|
-
#
|
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
|
-
|
52
|
-
|
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
|
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.
|
data/lib/sensu/server/process.rb
CHANGED
@@ -619,15 +619,16 @@ module Sensu
|
|
619
619
|
end
|
620
620
|
end
|
621
621
|
|
622
|
-
# Determine the Sensu
|
623
|
-
# subscription. If a subscription begins with a
|
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
|
626
|
-
#
|
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
|
-
# @
|
630
|
-
#
|
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
|
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
|
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
|
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
|
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
|
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
|
-
#
|
1080
|
+
# Transport, and calling the `bootstrap()` method.
|
1080
1081
|
def start
|
1081
1082
|
setup_connections do
|
1082
1083
|
bootstrap
|
data/sensu.gemspec
CHANGED
@@ -4,7 +4,6 @@ require File.join(File.dirname(__FILE__), "lib", "sensu", "constants")
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "sensu"
|
6
6
|
s.version = Sensu::VERSION
|
7
|
-
s.platform = RUBY_PLATFORM =~ /java/ ? Gem::Platform::JAVA : Gem::Platform::RUBY
|
8
7
|
s.authors = ["Sean Porter", "Justin Kolberg"]
|
9
8
|
s.email = ["portertech@gmail.com", "amdprophet@gmail.com"]
|
10
9
|
s.homepage = "http://sensuapp.org"
|
@@ -22,9 +21,7 @@ Gem::Specification.new do |s|
|
|
22
21
|
s.add_dependency "sensu-transport", "6.0.0"
|
23
22
|
s.add_dependency "sensu-spawn", "2.2.0"
|
24
23
|
s.add_dependency "sensu-redis", "1.4.0"
|
25
|
-
s.add_dependency "
|
26
|
-
s.add_dependency "async_sinatra", "1.2.0"
|
27
|
-
s.add_dependency "thin", "1.6.4" unless RUBY_PLATFORM =~ /java/
|
24
|
+
s.add_dependency "em-http-server", "0.1.8"
|
28
25
|
|
29
26
|
s.add_development_dependency "rake", "10.5.0"
|
30
27
|
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.
|
4
|
+
version: 0.25.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-06-
|
12
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -138,47 +138,19 @@ dependencies:
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: 1.4.0
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
141
|
+
name: em-http-server
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - '='
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: 1.
|
146
|
+
version: 0.1.8
|
147
147
|
type: :runtime
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
151
|
- - '='
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: 1.
|
154
|
-
- !ruby/object:Gem::Dependency
|
155
|
-
name: async_sinatra
|
156
|
-
requirement: !ruby/object:Gem::Requirement
|
157
|
-
requirements:
|
158
|
-
- - '='
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
version: 1.2.0
|
161
|
-
type: :runtime
|
162
|
-
prerelease: false
|
163
|
-
version_requirements: !ruby/object:Gem::Requirement
|
164
|
-
requirements:
|
165
|
-
- - '='
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
version: 1.2.0
|
168
|
-
- !ruby/object:Gem::Dependency
|
169
|
-
name: thin
|
170
|
-
requirement: !ruby/object:Gem::Requirement
|
171
|
-
requirements:
|
172
|
-
- - '='
|
173
|
-
- !ruby/object:Gem::Version
|
174
|
-
version: 1.6.4
|
175
|
-
type: :runtime
|
176
|
-
prerelease: false
|
177
|
-
version_requirements: !ruby/object:Gem::Requirement
|
178
|
-
requirements:
|
179
|
-
- - '='
|
180
|
-
- !ruby/object:Gem::Version
|
181
|
-
version: 1.6.4
|
153
|
+
version: 0.1.8
|
182
154
|
- !ruby/object:Gem::Dependency
|
183
155
|
name: rake
|
184
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -255,7 +227,23 @@ files:
|
|
255
227
|
- exe/sensu-install
|
256
228
|
- exe/sensu-server
|
257
229
|
- lib/sensu.rb
|
230
|
+
- lib/sensu/api/http_handler.rb
|
258
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
|
259
247
|
- lib/sensu/api/validators.rb
|
260
248
|
- lib/sensu/cli.rb
|
261
249
|
- lib/sensu/client/process.rb
|
@@ -285,9 +273,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
285
273
|
version: '0'
|
286
274
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
287
275
|
requirements:
|
288
|
-
- - "
|
276
|
+
- - ">"
|
289
277
|
- !ruby/object:Gem::Version
|
290
|
-
version:
|
278
|
+
version: 1.3.1
|
291
279
|
requirements: []
|
292
280
|
rubyforge_project:
|
293
281
|
rubygems_version: 2.6.3
|