sensu 0.5.7 → 0.5.8

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.
@@ -74,9 +74,13 @@ module Sensu
74
74
  @settings['client']['subscriptions'].each do |exchange|
75
75
  uniq_queue.bind(@amq.fanout(exchange))
76
76
  end
77
- uniq_queue.subscribe do |check_json|
78
- check = JSON.parse(check_json)
79
- execute_check(check)
77
+ EM.add_periodic_timer(0.5) do
78
+ unless uniq_queue.subscribed?
79
+ uniq_queue.subscribe do |check_json|
80
+ check = JSON.parse(check_json)
81
+ execute_check(check)
82
+ end
83
+ end
80
84
  end
81
85
  end
82
86
  end
@@ -48,10 +48,15 @@ module Sensu
48
48
  end
49
49
 
50
50
  def setup_keep_alives
51
- @amq.queue('keepalives').subscribe do |keepalive_json|
52
- client = JSON.parse(keepalive_json)['name']
53
- @redis.set('client:' + client, keepalive_json).callback do
54
- @redis.sadd('clients', client)
51
+ keepalive_queue = @amq.queue('keepalives')
52
+ EM.add_periodic_timer(0.5) do
53
+ unless keepalive_queue.subscribed?
54
+ keepalive_queue.subscribe do |keepalive_json|
55
+ client = JSON.parse(keepalive_json)['name']
56
+ @redis.set('client:' + client, keepalive_json).callback do
57
+ @redis.sadd('clients', client)
58
+ end
59
+ end
55
60
  end
56
61
  end
57
62
  end
@@ -91,35 +96,32 @@ module Sensu
91
96
  @handler_queue.push(event)
92
97
  end
93
98
 
94
- def setup_results
95
- @amq.queue('results').subscribe do |result_json|
96
- result = JSON.parse(result_json)
97
- @redis.get('client:' + result['client']).callback do |client_json|
98
- unless client_json.nil?
99
- client = JSON.parse(client_json)
100
- check = result['check']
101
- check.merge!(@settings['checks'][check['name']]) if @settings['checks'].has_key?(check['name'])
102
- check['handler'] = 'default' unless check['handler']
103
- event = {'client' => client, 'check' => check}
104
- if check['type'] == 'metric'
105
- handle_event(event)
106
- else
107
- @redis.hget('events:' + client['name'], check['name']).callback do |event_json|
108
- previous_event = event_json ? JSON.parse(event_json) : nil
109
- if previous_event && check['status'] == 0
110
- @redis.hdel('events:' + client['name'], check['name'])
111
- event['action'] = 'resolve'
99
+ def process_result(result)
100
+ @redis.get('client:' + result['client']).callback do |client_json|
101
+ unless client_json.nil?
102
+ client = JSON.parse(client_json)
103
+ check = result['check']
104
+ check.merge!(@settings['checks'][check['name']]) if @settings['checks'].has_key?(check['name'])
105
+ check['handler'] = 'default' unless check['handler']
106
+ event = {'client' => client, 'check' => check}
107
+ if check['type'] == 'metric'
108
+ handle_event(event)
109
+ else
110
+ @redis.hget('events:' + client['name'], check['name']).callback do |event_json|
111
+ previous_event = event_json ? JSON.parse(event_json) : nil
112
+ if previous_event && check['status'] == 0
113
+ @redis.hdel('events:' + client['name'], check['name'])
114
+ event['action'] = 'resolve'
115
+ handle_event(event)
116
+ elsif check['status'] > 0
117
+ occurrences = 1
118
+ if previous_event && check['status'] == previous_event['status']
119
+ occurrences = previous_event['occurrences'] += 1
120
+ end
121
+ @redis.hset('events:' + client['name'], check['name'], {'status' => check['status'], 'output' => check['output'], 'occurrences' => occurrences}.to_json).callback do
122
+ event['occurrences'] = occurrences
123
+ event['action'] = 'create'
112
124
  handle_event(event)
113
- elsif check['status'] > 0
114
- occurrences = 1
115
- if previous_event && check['status'] == previous_event['status']
116
- occurrences = previous_event['occurrences'] += 1
117
- end
118
- @redis.hset('events:' + client['name'], check['name'], {'status' => check['status'], 'output' => check['output'], 'occurrences' => occurrences}.to_json).callback do
119
- event['occurrences'] = occurrences
120
- event['action'] = 'create'
121
- handle_event(event)
122
- end
123
125
  end
124
126
  end
125
127
  end
@@ -128,6 +130,18 @@ module Sensu
128
130
  end
129
131
  end
130
132
 
133
+ def setup_results
134
+ result_queue = @amq.queue('results')
135
+ EM.add_periodic_timer(0.5) do
136
+ unless result_queue.subscribed?
137
+ result_queue.subscribe do |result_json|
138
+ result = JSON.parse(result_json)
139
+ process_result(result)
140
+ end
141
+ end
142
+ end
143
+ end
144
+
131
145
  def setup_publisher(options={})
132
146
  exchanges = Hash.new
133
147
  stagger = options[:test] ? 0 : 7
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sensu"
3
- s.version = "0.5.7"
3
+ s.version = "0.5.8"
4
4
  s.authors = ["Sean Porter", "Justin Kolberg"]
5
5
  s.email = ["sean.porter@sonian.net", "justin.kolberg@sonian.net"]
6
6
  s.homepage = "https://github.com/sonian/sensu"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.7
5
+ version: 0.5.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sean Porter