sensu 0.22.2-java → 0.23.0.beta-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f441f12eaa29a2a1e6c78a85a59f9e493831348d
4
- data.tar.gz: 20cf8ae1262ca4e44dbce41e918175b603421be3
3
+ metadata.gz: 405cb44986cc3e6267c5dc1829a92a98528d6cd3
4
+ data.tar.gz: cd4b7efb2a34f8d794713150284254237f7049a8
5
5
  SHA512:
6
- metadata.gz: a9e8c6031a34a771eb4151feaff489de935fc5d369beaeb31578a1c91cb9f2fb700b32eeaddfc0bc7c8a4949f368d85119b632841b50f846a12d1a6169427893
7
- data.tar.gz: ae14b0070639620f67dfedcfb4b2bc0a14d9650fa8270cc4f099848294671c1b0e40580eeaaf4918ff5ae705ff1da4517afe45162840f0bf76104b35331ee522
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Sonian Inc.
1
+ Copyright (c) 2016 Sonian Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -22,17 +22,20 @@ module Sensu
22
22
  bootstrap(options)
23
23
  setup_process(options)
24
24
  EM::run do
25
- start
26
- setup_signal_traps
25
+ setup_connections do
26
+ start
27
+ setup_signal_traps
28
+ end
27
29
  end
28
30
  end
29
31
 
30
- def on_reactor_run
31
- EM::next_tick do
32
- setup_redis
33
- set :redis, @redis
34
- setup_transport
35
- set :transport, @transport
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
- @redis.close
87
- @transport.close
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
- start
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!(MultiJson.dump(:issued => Time.now.to_i))
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 = MultiJson.load(env["rack.input"].read)
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 MultiJson::ParseError
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"] = MultiJson.dump(
205
+ headers["X-Pagination"] = Sensu::JSON.dump(
202
206
  :limit => limit,
203
207
  :offset => offset,
204
- :total => items.size
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", MultiJson.dump(payload)) do |info|
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 = MultiJson.load(event_json)
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, MultiJson.dump(payload))
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 MultiJson.dump(response)
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]}", MultiJson.dump(data)) do
362
+ settings.redis.set("client:#{data[:name]}", Sensu::JSON.dump(data)) do
359
363
  settings.redis.sadd("clients", data[:name]) do
360
- created!(MultiJson.dump(:name => data[:name]))
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 << MultiJson.load(client_json)
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.size - 1
380
- body MultiJson.dump(response)
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 MultiJson.dump(response)
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 = MultiJson.load(result_json)
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.size - 1
427
- body MultiJson.dump(response)
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 MultiJson.dump(response)
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 MultiJson.dump(settings.all_checks)
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 MultiJson.dump(response)
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 << MultiJson.load(event_json)
522
+ response << Sensu::JSON.load(event_json)
519
523
  end
520
- if index == clients.size - 1
521
- body MultiJson.dump(response)
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 MultiJson.dump(response)
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 << MultiJson.load(event_json)
539
+ response << Sensu::JSON.load(event_json)
536
540
  end
537
- body MultiJson.dump(response)
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.size - 1
596
- body MultiJson.dump(response)
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 MultiJson.dump(response)
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 MultiJson.dump(pagination(aggregates))
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 = MultiJson.load(check_json)
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 MultiJson.dump(response)
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}", MultiJson.dump(data)) do
686
+ settings.redis.set("stash:#{path}", Sensu::JSON.dump(data)) do
683
687
  settings.redis.sadd("stashes", path) do
684
- created!(MultiJson.dump(:path => path))
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 => MultiJson.load(stash_json),
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.size - 1
732
- body MultiJson.dump(pagination(response))
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 MultiJson.dump(response)
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, MultiJson.dump(data[:content])) do
755
+ settings.redis.set(stash_key, Sensu::JSON.dump(data[:content])) do
752
756
  settings.redis.sadd("stashes", data[:path]) do
753
- response = MultiJson.dump(:path => data[:path])
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 = MultiJson.load(result_json)
794
+ check = Sensu::JSON.load(result_json)
791
795
  response << {:client => client_name, :check => check}
792
796
  end
793
- if client_index == clients.size - 1 && check_index == checks.size - 1
794
- body MultiJson.dump(response)
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.size - 1
799
- body MultiJson.dump(response)
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 MultiJson.dump(response)
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 = MultiJson.load(result_json)
821
+ check = Sensu::JSON.load(result_json)
818
822
  response << {:client => client_name, :check => check}
819
823
  end
820
- if check_index == checks.size - 1
821
- body MultiJson.dump(response)
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 = MultiJson.load(result_json)
839
+ check = Sensu::JSON.load(result_json)
836
840
  response = {:client => client_name, :check => check}
837
- body MultiJson.dump(response)
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
@@ -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", MultiJson.dump(payload)) do |info|
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", MultiJson.dump(payload)) do |info|
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 = substitute_check_command_tokens(check)
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 = MultiJson.load(message)
240
+ check = Sensu::JSON.load(message)
277
241
  @logger.info("received check request", :check => check)
278
242
  process_check_request(check)
279
- rescue MultiJson::ParseError => error
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
- setup_sockets
417
- bootstrap
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
@@ -1,4 +1,4 @@
1
- require "multi_json"
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", MultiJson.dump(payload))
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 = MultiJson.load(data)
172
+ check = Sensu::JSON.load(data)
173
173
  cancel_watchdog
174
174
  process_check_result(check)
175
- rescue MultiJson::ParseError, ArgumentError => error
175
+ rescue Sensu::JSON::ParseError, ArgumentError => error
176
176
  if @protocol == :tcp
177
177
  @parse_error = error.to_s
178
178
  else
@@ -1,7 +1,7 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
3
  # Sensu release version.
4
- VERSION = "0.22.2".freeze
4
+ VERSION = "0.23.0.beta".freeze
5
5
 
6
6
  # Sensu check severities.
7
7
  SEVERITIES = %w[ok warning critical unknown].freeze