sensu 0.9.13.beta → 0.9.13.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu/client.rb CHANGED
@@ -78,9 +78,13 @@ module Sensu
78
78
  def substitute_command_tokens(check)
79
79
  unmatched_tokens = Array.new
80
80
  substituted = check[:command].gsub(/:::(.*?):::/) do
81
- token = $1.to_s
81
+ token, default = $1.to_s.split('|')
82
82
  matched = token.split('.').inject(@settings[:client]) do |client, attribute|
83
- client[attribute].nil? ? break : client[attribute]
83
+ if client[attribute].nil?
84
+ default.nil? ? break : default
85
+ else
86
+ client[attribute]
87
+ end
84
88
  end
85
89
  if matched.nil?
86
90
  unmatched_tokens << token
@@ -99,6 +103,7 @@ module Sensu
99
103
  command, unmatched_tokens = substitute_command_tokens(check)
100
104
  check[:executed] = Time.now.to_i
101
105
  if unmatched_tokens.empty?
106
+ check[:command_executed] = command
102
107
  execute = Proc.new do
103
108
  @logger.debug('executing check command', {
104
109
  :check => check
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
- VERSION = '0.9.13.beta'
3
+ VERSION = '0.9.13.beta.1'
4
4
 
5
5
  LOG_LEVELS = [:debug, :info, :warn, :error, :fatal]
6
6
 
data/lib/sensu/server.rb CHANGED
@@ -508,6 +508,9 @@ module Sensu
508
508
  result[:check][:output].is_a?(String) &&
509
509
  result[:check][:status].is_a?(Integer)
510
510
  else
511
+ @logger.warn('invalid result', {
512
+ :result => result
513
+ })
511
514
  false
512
515
  end
513
516
  end
@@ -523,10 +526,6 @@ module Sensu
523
526
  })
524
527
  if valid_result?(result)
525
528
  process_result(result)
526
- else
527
- @logger.warn('invalid result', {
528
- :result => result
529
- })
530
529
  end
531
530
  EM::next_tick do
532
531
  header.ack
@@ -599,40 +598,42 @@ module Sensu
599
598
  @redis.smembers('clients') do |clients|
600
599
  clients.each do |client_name|
601
600
  @redis.get('client:' + client_name) do |client_json|
602
- client = Oj.load(client_json)
603
- check = {
604
- :name => 'keepalive',
605
- :issued => Time.now.to_i,
606
- :executed => Time.now.to_i
607
- }
608
- thresholds = {
609
- :warning => 120,
610
- :critical => 180
611
- }
612
- if client.has_key?(:keepalive)
613
- if client[:keepalive].has_key?(:handler) || client[:keepalive].has_key?(:handlers)
614
- check[:handlers] = Array(client[:keepalive][:handlers] || client[:keepalive][:handler])
601
+ unless client_json.nil?
602
+ client = Oj.load(client_json)
603
+ check = {
604
+ :name => 'keepalive',
605
+ :issued => Time.now.to_i,
606
+ :executed => Time.now.to_i
607
+ }
608
+ thresholds = {
609
+ :warning => 120,
610
+ :critical => 180
611
+ }
612
+ if client.has_key?(:keepalive)
613
+ if client[:keepalive].has_key?(:handler) || client[:keepalive].has_key?(:handlers)
614
+ check[:handlers] = Array(client[:keepalive][:handlers] || client[:keepalive][:handler])
615
+ end
616
+ if client[:keepalive].has_key?(:thresholds)
617
+ thresholds.merge!(client[:keepalive][:thresholds])
618
+ end
615
619
  end
616
- if client[:keepalive].has_key?(:thresholds)
617
- thresholds.merge!(client[:keepalive][:thresholds])
620
+ time_since_last_keepalive = Time.now.to_i - client[:timestamp]
621
+ case
622
+ when time_since_last_keepalive >= thresholds[:critical]
623
+ check[:output] = 'No keep-alive sent from client in over '
624
+ check[:output] << thresholds[:critical].to_s + ' seconds'
625
+ check[:status] = 2
626
+ when time_since_last_keepalive >= thresholds[:warning]
627
+ check[:output] = 'No keep-alive sent from client in over '
628
+ check[:output] << thresholds[:warning].to_s + ' seconds'
629
+ check[:status] = 1
630
+ else
631
+ check[:output] = 'Keep-alive sent from client less than '
632
+ check[:output] << thresholds[:warning].to_s + ' seconds ago'
633
+ check[:status] = 0
618
634
  end
635
+ publish_result(client, check)
619
636
  end
620
- time_since_last_keepalive = Time.now.to_i - client[:timestamp]
621
- case
622
- when time_since_last_keepalive >= thresholds[:critical]
623
- check[:output] = 'No keep-alive sent from client in over '
624
- check[:output] << thresholds[:critical].to_s + ' seconds'
625
- check[:status] = 2
626
- when time_since_last_keepalive >= thresholds[:warning]
627
- check[:output] = 'No keep-alive sent from client in over '
628
- check[:output] << thresholds[:warning].to_s + ' seconds'
629
- check[:status] = 1
630
- else
631
- check[:output] = 'Keep-alive sent from client less than '
632
- check[:output] << thresholds[:warning].to_s + ' seconds ago'
633
- check[:status] = 0
634
- end
635
- publish_result(client, check)
636
637
  end
637
638
  end
638
639
  end
@@ -210,7 +210,10 @@ module Sensu
210
210
  end
211
211
 
212
212
  def validate_check(check)
213
- unless check[:interval].is_a?(Integer) && check[:interval] > 0
213
+ unless check[:name] =~ /^[\w-]+$/
214
+ invalid_check(check, 'check name cannot contain spaces or special characters')
215
+ end
216
+ unless (check[:interval].is_a?(Integer) && check[:interval] > 0) || !check[:publish]
214
217
  invalid_check(check, 'check is missing interval')
215
218
  end
216
219
  unless check[:command].is_a?(String)
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: -799367686
4
+ hash: 1864401177
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 13
10
10
  - beta
11
- version: 0.9.13.beta
11
+ - 1
12
+ version: 0.9.13.beta.1
12
13
  platform: ruby
13
14
  authors:
14
15
  - Sean Porter
@@ -17,7 +18,7 @@ autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2013-04-19 00:00:00 -07:00
21
+ date: 2013-05-18 00:00:00 -07:00
21
22
  default_executable:
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency