sensu 0.22.2-java → 0.23.0.beta-java
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/MIT-LICENSE.txt +1 -1
- data/lib/sensu/api/process.rb +69 -65
- data/lib/sensu/cli.rb +3 -0
- data/lib/sensu/client/process.rb +9 -44
- data/lib/sensu/client/socket.rb +4 -4
- data/lib/sensu/constants.rb +1 -1
- data/lib/sensu/daemon.rb +69 -40
- data/lib/sensu/server/filter.rb +63 -24
- data/lib/sensu/server/mutate.rb +1 -1
- data/lib/sensu/server/process.rb +68 -54
- data/lib/sensu/server/sandbox.rb +4 -4
- data/lib/sensu/utilities.rb +40 -4
- data/sensu.gemspec +7 -9
- metadata +21 -36
- data/lib/sensu/redis.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 405cb44986cc3e6267c5dc1829a92a98528d6cd3
|
4
|
+
data.tar.gz: cd4b7efb2a34f8d794713150284254237f7049a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae4fd3a2bf582ec78266574d96ce8afbafe7813d6a0297c3ab3bfb92d36ae73f103c4f5f47dd599eedac9a27f15b12c329fcc56fa3958a47320ec5779e02fac8
|
7
|
+
data.tar.gz: c47ad23db2c4cbd2bda7f212e5211f0ef88a7ae0f8122299708797467b2cabfa964523f184755da4eadf850d1c4b66960ead7004f10cfeda3c24357b0696ea7b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
+
## 0.23.0 - 2016-03-29
|
2
|
+
|
3
|
+
### Important
|
4
|
+
|
5
|
+
Dropped support for Rubies < 2.0.0, as they have long been EOL and have
|
6
|
+
proven to be a hindrance and security risk.
|
7
|
+
|
8
|
+
The Sensu Transport API changed. Transports are now a deferrable, they
|
9
|
+
must call `succeed()` once they have fully initialized. Sensu now waits
|
10
|
+
for its transport to fully initialize before taking other actions.
|
11
|
+
|
12
|
+
### Features
|
13
|
+
|
14
|
+
Redis Sentinel support for HA Redis. Sensu services can now be configured
|
15
|
+
to query one or more instances of Redis Sentinel for a Redis master. This
|
16
|
+
feature eliminates the last need for HAProxy in highly available Sensu
|
17
|
+
configurations. To configure Sensu services to use Redis Sentinel, hosts
|
18
|
+
and ports of one or more Sentinel instances must be provided, e.g.
|
19
|
+
`"sentinels": [{"host": "10.0.1.23", "port": 26479}]`.
|
20
|
+
|
21
|
+
Added a CLI option/argument to cause the Sensu service to print (output to
|
22
|
+
STDOUT) its compiled configuration settings and exit. The CLI option is
|
23
|
+
`--print_config` or `-P`.
|
24
|
+
|
25
|
+
Added token substitution to filter eval attributes, providing access to
|
26
|
+
event data, e.g. `"occurrences": "eval: value == :::check.occurrences:::"`.
|
27
|
+
|
28
|
+
The Sensu 0.23 packages use Ruby 2.3.
|
29
|
+
|
30
|
+
### Other
|
31
|
+
|
32
|
+
Performance improvements. Dropped MultiJson in favour of Sensu JSON, a
|
33
|
+
lighter weight JSON parser abstraction that supports platform specific
|
34
|
+
parsers for Sensu Core and Enterprise. The Oj JSON parser is once again
|
35
|
+
used for Sensu Core. Used https://github.com/JuanitoFatas/fast-ruby and
|
36
|
+
benchmarks as a guide to further changes.
|
37
|
+
|
38
|
+
Using EventMachine 1.2.0, which brings several changes and improvements:
|
39
|
+
https://github.com/eventmachine/eventmachine/blob/master/CHANGELOG.md#1201-march-15-2016
|
40
|
+
|
1
41
|
## 0.22.2 - 2016-03-16
|
2
42
|
|
3
43
|
### Fixes
|
data/MIT-LICENSE.txt
CHANGED
data/lib/sensu/api/process.rb
CHANGED
@@ -22,17 +22,20 @@ module Sensu
|
|
22
22
|
bootstrap(options)
|
23
23
|
setup_process(options)
|
24
24
|
EM::run do
|
25
|
-
|
26
|
-
|
25
|
+
setup_connections do
|
26
|
+
start
|
27
|
+
setup_signal_traps
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def setup_connections
|
33
|
+
setup_redis do |redis|
|
34
|
+
set :redis, redis
|
35
|
+
setup_transport do |transport|
|
36
|
+
set :transport, transport
|
37
|
+
yield if block_given?
|
38
|
+
end
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
@@ -49,8 +52,6 @@ module Sensu
|
|
49
52
|
"Credentials" => "true",
|
50
53
|
"Headers" => "Origin, X-Requested-With, Content-Type, Accept, Authorization"
|
51
54
|
}
|
52
|
-
on_reactor_run
|
53
|
-
self
|
54
55
|
end
|
55
56
|
|
56
57
|
def start_server
|
@@ -83,15 +84,18 @@ module Sensu
|
|
83
84
|
def stop
|
84
85
|
@logger.warn("stopping")
|
85
86
|
stop_server do
|
86
|
-
|
87
|
-
|
87
|
+
settings.redis.close
|
88
|
+
settings.transport.close
|
88
89
|
super
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
93
|
def test(options={})
|
93
94
|
bootstrap(options)
|
94
|
-
|
95
|
+
setup_connections do
|
96
|
+
start
|
97
|
+
yield
|
98
|
+
end
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
@@ -163,7 +167,7 @@ module Sensu
|
|
163
167
|
end
|
164
168
|
|
165
169
|
def issued!
|
166
|
-
accepted!(
|
170
|
+
accepted!(Sensu::JSON.dump(:issued => Time.now.to_i))
|
167
171
|
end
|
168
172
|
|
169
173
|
def no_content!
|
@@ -173,7 +177,7 @@ module Sensu
|
|
173
177
|
|
174
178
|
def read_data(rules={})
|
175
179
|
begin
|
176
|
-
data =
|
180
|
+
data = Sensu::JSON.load(env["rack.input"].read)
|
177
181
|
valid = rules.all? do |key, rule|
|
178
182
|
value = data[key]
|
179
183
|
(value.is_a?(rule[:type]) || (rule[:nil_ok] && value.nil?)) &&
|
@@ -185,7 +189,7 @@ module Sensu
|
|
185
189
|
else
|
186
190
|
bad_request!
|
187
191
|
end
|
188
|
-
rescue
|
192
|
+
rescue Sensu::JSON::ParseError
|
189
193
|
bad_request!
|
190
194
|
end
|
191
195
|
end
|
@@ -198,10 +202,10 @@ module Sensu
|
|
198
202
|
limit = integer_parameter(params[:limit])
|
199
203
|
offset = integer_parameter(params[:offset]) || 0
|
200
204
|
unless limit.nil?
|
201
|
-
headers["X-Pagination"] =
|
205
|
+
headers["X-Pagination"] = Sensu::JSON.dump(
|
202
206
|
:limit => limit,
|
203
207
|
:offset => offset,
|
204
|
-
:total => items.
|
208
|
+
:total => items.length
|
205
209
|
)
|
206
210
|
paginated = items.slice(offset, limit)
|
207
211
|
Array(paginated)
|
@@ -244,7 +248,7 @@ module Sensu
|
|
244
248
|
:check => check
|
245
249
|
}
|
246
250
|
settings.logger.info("publishing check result", :payload => payload)
|
247
|
-
settings.transport.publish(:direct, "results",
|
251
|
+
settings.transport.publish(:direct, "results", Sensu::JSON.dump(payload)) do |info|
|
248
252
|
if info[:error]
|
249
253
|
settings.logger.error("failed to publish check result", {
|
250
254
|
:payload => payload,
|
@@ -255,7 +259,7 @@ module Sensu
|
|
255
259
|
end
|
256
260
|
|
257
261
|
def resolve_event(event_json)
|
258
|
-
event =
|
262
|
+
event = Sensu::JSON.load(event_json)
|
259
263
|
check = event[:check].merge(
|
260
264
|
:output => "Resolving on request of the API",
|
261
265
|
:status => 0,
|
@@ -282,7 +286,7 @@ module Sensu
|
|
282
286
|
:subscribers => check[:subscribers]
|
283
287
|
})
|
284
288
|
check[:subscribers].each do |subscription|
|
285
|
-
options = transport_publish_options(subscription.to_s,
|
289
|
+
options = transport_publish_options(subscription.to_s, Sensu::JSON.dump(payload))
|
286
290
|
settings.transport.publish(*options) do |info|
|
287
291
|
if info[:error]
|
288
292
|
settings.logger.error("failed to publish check request", {
|
@@ -320,7 +324,7 @@ module Sensu
|
|
320
324
|
:connected => settings.redis.connected?
|
321
325
|
}
|
322
326
|
}
|
323
|
-
body
|
327
|
+
body Sensu::JSON.dump(response)
|
324
328
|
end
|
325
329
|
end
|
326
330
|
|
@@ -355,9 +359,9 @@ module Sensu
|
|
355
359
|
data[:keepalives] = false
|
356
360
|
data[:version] = VERSION
|
357
361
|
data[:timestamp] = Time.now.to_i
|
358
|
-
settings.redis.set("client:#{data[:name]}",
|
362
|
+
settings.redis.set("client:#{data[:name]}", Sensu::JSON.dump(data)) do
|
359
363
|
settings.redis.sadd("clients", data[:name]) do
|
360
|
-
created!(
|
364
|
+
created!(Sensu::JSON.dump(:name => data[:name]))
|
361
365
|
end
|
362
366
|
end
|
363
367
|
end
|
@@ -371,18 +375,18 @@ module Sensu
|
|
371
375
|
clients.each_with_index do |client_name, index|
|
372
376
|
settings.redis.get("client:#{client_name}") do |client_json|
|
373
377
|
unless client_json.nil?
|
374
|
-
response <<
|
378
|
+
response << Sensu::JSON.load(client_json)
|
375
379
|
else
|
376
380
|
settings.logger.error("client data missing from registry", :client_name => client_name)
|
377
381
|
settings.redis.srem("clients", client_name)
|
378
382
|
end
|
379
|
-
if index == clients.
|
380
|
-
body
|
383
|
+
if index == clients.length - 1
|
384
|
+
body Sensu::JSON.dump(response)
|
381
385
|
end
|
382
386
|
end
|
383
387
|
end
|
384
388
|
else
|
385
|
-
body
|
389
|
+
body Sensu::JSON.dump(response)
|
386
390
|
end
|
387
391
|
end
|
388
392
|
end
|
@@ -410,7 +414,7 @@ module Sensu
|
|
410
414
|
end
|
411
415
|
settings.redis.get("result:#{result_key}") do |result_json|
|
412
416
|
unless result_json.nil?
|
413
|
-
result =
|
417
|
+
result = Sensu::JSON.load(result_json)
|
414
418
|
last_execution = result[:executed]
|
415
419
|
unless history.empty? || last_execution.nil?
|
416
420
|
item = {
|
@@ -423,14 +427,14 @@ module Sensu
|
|
423
427
|
response << item
|
424
428
|
end
|
425
429
|
end
|
426
|
-
if index == checks.
|
427
|
-
body
|
430
|
+
if index == checks.length - 1
|
431
|
+
body Sensu::JSON.dump(response)
|
428
432
|
end
|
429
433
|
end
|
430
434
|
end
|
431
435
|
end
|
432
436
|
else
|
433
|
-
body
|
437
|
+
body Sensu::JSON.dump(response)
|
434
438
|
end
|
435
439
|
end
|
436
440
|
end
|
@@ -477,13 +481,13 @@ module Sensu
|
|
477
481
|
end
|
478
482
|
|
479
483
|
aget "/checks/?" do
|
480
|
-
body
|
484
|
+
body Sensu::JSON.dump(settings.all_checks)
|
481
485
|
end
|
482
486
|
|
483
487
|
aget %r{^/checks?/([\w\.-]+)/?$} do |check_name|
|
484
488
|
if settings.checks[check_name]
|
485
489
|
response = settings.checks[check_name].merge(:name => check_name)
|
486
|
-
body
|
490
|
+
body Sensu::JSON.dump(response)
|
487
491
|
else
|
488
492
|
not_found!
|
489
493
|
end
|
@@ -515,15 +519,15 @@ module Sensu
|
|
515
519
|
clients.each_with_index do |client_name, index|
|
516
520
|
settings.redis.hgetall("events:#{client_name}") do |events|
|
517
521
|
events.each do |check_name, event_json|
|
518
|
-
response <<
|
522
|
+
response << Sensu::JSON.load(event_json)
|
519
523
|
end
|
520
|
-
if index == clients.
|
521
|
-
body
|
524
|
+
if index == clients.length - 1
|
525
|
+
body Sensu::JSON.dump(response)
|
522
526
|
end
|
523
527
|
end
|
524
528
|
end
|
525
529
|
else
|
526
|
-
body
|
530
|
+
body Sensu::JSON.dump(response)
|
527
531
|
end
|
528
532
|
end
|
529
533
|
end
|
@@ -532,9 +536,9 @@ module Sensu
|
|
532
536
|
response = Array.new
|
533
537
|
settings.redis.hgetall("events:#{client_name}") do |events|
|
534
538
|
events.each do |check_name, event_json|
|
535
|
-
response <<
|
539
|
+
response << Sensu::JSON.load(event_json)
|
536
540
|
end
|
537
|
-
body
|
541
|
+
body Sensu::JSON.dump(response)
|
538
542
|
end
|
539
543
|
end
|
540
544
|
|
@@ -592,13 +596,13 @@ module Sensu
|
|
592
596
|
:issued => aggregates
|
593
597
|
}
|
594
598
|
response << item
|
595
|
-
if index == checks.
|
596
|
-
body
|
599
|
+
if index == checks.length - 1
|
600
|
+
body Sensu::JSON.dump(response)
|
597
601
|
end
|
598
602
|
end
|
599
603
|
end
|
600
604
|
else
|
601
|
-
body
|
605
|
+
body Sensu::JSON.dump(response)
|
602
606
|
end
|
603
607
|
end
|
604
608
|
end
|
@@ -617,7 +621,7 @@ module Sensu
|
|
617
621
|
issued > timestamp
|
618
622
|
end
|
619
623
|
end
|
620
|
-
body
|
624
|
+
body Sensu::JSON.dump(pagination(aggregates))
|
621
625
|
else
|
622
626
|
not_found!
|
623
627
|
end
|
@@ -653,7 +657,7 @@ module Sensu
|
|
653
657
|
end
|
654
658
|
settings.redis.hgetall("aggregation:#{result_set}") do |results|
|
655
659
|
parsed_results = results.inject(Array.new) do |parsed, (client_name, check_json)|
|
656
|
-
check =
|
660
|
+
check = Sensu::JSON.load(check_json)
|
657
661
|
parsed << check.merge(:client => client_name)
|
658
662
|
end
|
659
663
|
if params[:summarize]
|
@@ -669,7 +673,7 @@ module Sensu
|
|
669
673
|
if params[:results]
|
670
674
|
response[:results] = parsed_results
|
671
675
|
end
|
672
|
-
body
|
676
|
+
body Sensu::JSON.dump(response)
|
673
677
|
end
|
674
678
|
else
|
675
679
|
not_found!
|
@@ -679,9 +683,9 @@ module Sensu
|
|
679
683
|
|
680
684
|
apost %r{^/stash(?:es)?/(.*)/?} do |path|
|
681
685
|
read_data do |data|
|
682
|
-
settings.redis.set("stash:#{path}",
|
686
|
+
settings.redis.set("stash:#{path}", Sensu::JSON.dump(data)) do
|
683
687
|
settings.redis.sadd("stashes", path) do
|
684
|
-
created!(
|
688
|
+
created!(Sensu::JSON.dump(:path => path))
|
685
689
|
end
|
686
690
|
end
|
687
691
|
end
|
@@ -721,21 +725,21 @@ module Sensu
|
|
721
725
|
unless stash_json.nil?
|
722
726
|
item = {
|
723
727
|
:path => path,
|
724
|
-
:content =>
|
728
|
+
:content => Sensu::JSON.load(stash_json),
|
725
729
|
:expire => ttl
|
726
730
|
}
|
727
731
|
response << item
|
728
732
|
else
|
729
733
|
settings.redis.srem("stashes", path)
|
730
734
|
end
|
731
|
-
if index == stashes.
|
732
|
-
body
|
735
|
+
if index == stashes.length - 1
|
736
|
+
body Sensu::JSON.dump(pagination(response))
|
733
737
|
end
|
734
738
|
end
|
735
739
|
end
|
736
740
|
end
|
737
741
|
else
|
738
|
-
body
|
742
|
+
body Sensu::JSON.dump(response)
|
739
743
|
end
|
740
744
|
end
|
741
745
|
end
|
@@ -748,9 +752,9 @@ module Sensu
|
|
748
752
|
}
|
749
753
|
read_data(rules) do |data|
|
750
754
|
stash_key = "stash:#{data[:path]}"
|
751
|
-
settings.redis.set(stash_key,
|
755
|
+
settings.redis.set(stash_key, Sensu::JSON.dump(data[:content])) do
|
752
756
|
settings.redis.sadd("stashes", data[:path]) do
|
753
|
-
response =
|
757
|
+
response = Sensu::JSON.dump(:path => data[:path])
|
754
758
|
if data[:expire]
|
755
759
|
settings.redis.expire(stash_key, data[:expire]) do
|
756
760
|
created!(response)
|
@@ -787,21 +791,21 @@ module Sensu
|
|
787
791
|
result_key = "result:#{client_name}:#{check_name}"
|
788
792
|
settings.redis.get(result_key) do |result_json|
|
789
793
|
unless result_json.nil?
|
790
|
-
check =
|
794
|
+
check = Sensu::JSON.load(result_json)
|
791
795
|
response << {:client => client_name, :check => check}
|
792
796
|
end
|
793
|
-
if client_index == clients.
|
794
|
-
body
|
797
|
+
if client_index == clients.length - 1 && check_index == checks.length - 1
|
798
|
+
body Sensu::JSON.dump(response)
|
795
799
|
end
|
796
800
|
end
|
797
801
|
end
|
798
|
-
elsif client_index == clients.
|
799
|
-
body
|
802
|
+
elsif client_index == clients.length - 1
|
803
|
+
body Sensu::JSON.dump(response)
|
800
804
|
end
|
801
805
|
end
|
802
806
|
end
|
803
807
|
else
|
804
|
-
body
|
808
|
+
body Sensu::JSON.dump(response)
|
805
809
|
end
|
806
810
|
end
|
807
811
|
end
|
@@ -814,11 +818,11 @@ module Sensu
|
|
814
818
|
result_key = "result:#{client_name}:#{check_name}"
|
815
819
|
settings.redis.get(result_key) do |result_json|
|
816
820
|
unless result_json.nil?
|
817
|
-
check =
|
821
|
+
check = Sensu::JSON.load(result_json)
|
818
822
|
response << {:client => client_name, :check => check}
|
819
823
|
end
|
820
|
-
if check_index == checks.
|
821
|
-
body
|
824
|
+
if check_index == checks.length - 1
|
825
|
+
body Sensu::JSON.dump(response)
|
822
826
|
end
|
823
827
|
end
|
824
828
|
end
|
@@ -832,9 +836,9 @@ module Sensu
|
|
832
836
|
result_key = "result:#{client_name}:#{check_name}"
|
833
837
|
settings.redis.get(result_key) do |result_json|
|
834
838
|
unless result_json.nil?
|
835
|
-
check =
|
839
|
+
check = Sensu::JSON.load(result_json)
|
836
840
|
response = {:client => client_name, :check => check}
|
837
|
-
body
|
841
|
+
body Sensu::JSON.dump(response)
|
838
842
|
else
|
839
843
|
not_found!
|
840
844
|
end
|
data/lib/sensu/cli.rb
CHANGED
@@ -26,6 +26,9 @@ module Sensu
|
|
26
26
|
opts.on("-d", "--config_dir DIR[,DIR]", "DIR or comma-delimited DIR list for Sensu JSON config files") do |dir|
|
27
27
|
options[:config_dirs] = dir.split(",")
|
28
28
|
end
|
29
|
+
opts.on("-P", "--print_config", "Print the compiled configuration and exit") do
|
30
|
+
options[:print_config] = true
|
31
|
+
end
|
29
32
|
opts.on("-e", "--extension_dir DIR", "DIR for Sensu extensions") do |dir|
|
30
33
|
options[:extension_dir] = dir
|
31
34
|
end
|
data/lib/sensu/client/process.rb
CHANGED
@@ -51,7 +51,7 @@ module Sensu
|
|
51
51
|
def publish_keepalive
|
52
52
|
payload = keepalive_payload
|
53
53
|
@logger.debug("publishing keepalive", :payload => payload)
|
54
|
-
@transport.publish(:direct, "keepalives",
|
54
|
+
@transport.publish(:direct, "keepalives", Sensu::JSON.dump(payload)) do |info|
|
55
55
|
if info[:error]
|
56
56
|
@logger.error("failed to publish keepalive", {
|
57
57
|
:payload => payload,
|
@@ -89,7 +89,7 @@ module Sensu
|
|
89
89
|
}
|
90
90
|
payload[:signature] = @settings[:client][:signature] if @settings[:client][:signature]
|
91
91
|
@logger.info("publishing check result", :payload => payload)
|
92
|
-
@transport.publish(:direct, "results",
|
92
|
+
@transport.publish(:direct, "results", Sensu::JSON.dump(payload)) do |info|
|
93
93
|
if info[:error]
|
94
94
|
@logger.error("failed to publish check result", {
|
95
95
|
:payload => payload,
|
@@ -99,42 +99,6 @@ module Sensu
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
# Traverse the Sensu client definition (hash) for an attribute
|
103
|
-
# value, with a fallback default value if nil.
|
104
|
-
#
|
105
|
-
# @param tree [Hash] to traverse.
|
106
|
-
# @param path [Array] of attribute keys.
|
107
|
-
# @param default [Object] value if attribute value is nil.
|
108
|
-
# @return [Object] attribute or fallback default value.
|
109
|
-
def find_client_attribute(tree, path, default)
|
110
|
-
attribute = tree[path.shift]
|
111
|
-
if attribute.is_a?(Hash)
|
112
|
-
find_client_attribute(attribute, path, default)
|
113
|
-
else
|
114
|
-
attribute.nil? ? default : attribute
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Substitue check command tokens (eg. :::db.name|production:::)
|
119
|
-
# with the associated client definition attribute value. Command
|
120
|
-
# tokens can provide a fallback default value, following a pipe.
|
121
|
-
#
|
122
|
-
# @param check [Hash]
|
123
|
-
# @return [Array] containing the check command string with
|
124
|
-
# tokens substituted and an array of unmatched command tokens.
|
125
|
-
def substitute_check_command_tokens(check)
|
126
|
-
unmatched_tokens = []
|
127
|
-
substituted = check[:command].gsub(/:::([^:].*?):::/) do
|
128
|
-
token, default = $1.to_s.split("|", -1)
|
129
|
-
matched = find_client_attribute(@settings[:client], token.split("."), default)
|
130
|
-
if matched.nil?
|
131
|
-
unmatched_tokens << token
|
132
|
-
end
|
133
|
-
matched
|
134
|
-
end
|
135
|
-
[substituted, unmatched_tokens]
|
136
|
-
end
|
137
|
-
|
138
102
|
# Execute a check command, capturing its output (STDOUT/ERR),
|
139
103
|
# exit status code, execution duration, timestamp, and publish
|
140
104
|
# the result. This method guards against multiple executions for
|
@@ -149,7 +113,7 @@ module Sensu
|
|
149
113
|
@logger.debug("attempting to execute check command", :check => check)
|
150
114
|
unless @checks_in_progress.include?(check[:name])
|
151
115
|
@checks_in_progress << check[:name]
|
152
|
-
command, unmatched_tokens =
|
116
|
+
command, unmatched_tokens = substitute_tokens(check[:command], @settings[:client])
|
153
117
|
if unmatched_tokens.empty?
|
154
118
|
check[:executed] = Time.now.to_i
|
155
119
|
started = Time.now.to_f
|
@@ -273,10 +237,10 @@ module Sensu
|
|
273
237
|
options = transport_subscribe_options(subscription)
|
274
238
|
@transport.subscribe(*options) do |message_info, message|
|
275
239
|
begin
|
276
|
-
check =
|
240
|
+
check = Sensu::JSON.load(message)
|
277
241
|
@logger.info("received check request", :check => check)
|
278
242
|
process_check_request(check)
|
279
|
-
rescue
|
243
|
+
rescue Sensu::JSON::ParseError => error
|
280
244
|
@logger.error("failed to parse the check request payload", {
|
281
245
|
:message => message,
|
282
246
|
:error => error.to_s
|
@@ -412,9 +376,10 @@ module Sensu
|
|
412
376
|
# transport connection, the sockets, and calling the
|
413
377
|
# `bootstrap()` method.
|
414
378
|
def start
|
415
|
-
setup_transport
|
416
|
-
|
417
|
-
|
379
|
+
setup_transport do
|
380
|
+
setup_sockets
|
381
|
+
bootstrap
|
382
|
+
end
|
418
383
|
end
|
419
384
|
|
420
385
|
# Pause the Sensu client process, unless it is being paused or
|
data/lib/sensu/client/socket.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "sensu/json"
|
2
2
|
|
3
3
|
module Sensu
|
4
4
|
module Client
|
@@ -145,7 +145,7 @@ module Sensu
|
|
145
145
|
:check => check.merge(:issued => Time.now.to_i)
|
146
146
|
}
|
147
147
|
@logger.info("publishing check result", :payload => payload)
|
148
|
-
@transport.publish(:direct, "results",
|
148
|
+
@transport.publish(:direct, "results", Sensu::JSON.dump(payload))
|
149
149
|
end
|
150
150
|
|
151
151
|
# Process a check result. Set check result attribute defaults,
|
@@ -169,10 +169,10 @@ module Sensu
|
|
169
169
|
# @param [String] data to parse for a check result.
|
170
170
|
def parse_check_result(data)
|
171
171
|
begin
|
172
|
-
check =
|
172
|
+
check = Sensu::JSON.load(data)
|
173
173
|
cancel_watchdog
|
174
174
|
process_check_result(check)
|
175
|
-
rescue
|
175
|
+
rescue Sensu::JSON::ParseError, ArgumentError => error
|
176
176
|
if @protocol == :tcp
|
177
177
|
@parse_error = error.to_s
|
178
178
|
else
|