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.
- data/lib/sensu/client.rb +7 -3
- data/lib/sensu/server.rb +46 -32
- data/sensu.gemspec +1 -1
- metadata +1 -1
data/lib/sensu/client.rb
CHANGED
@@ -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
|
-
|
78
|
-
|
79
|
-
|
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
|
data/lib/sensu/server.rb
CHANGED
@@ -48,10 +48,15 @@ module Sensu
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def setup_keep_alives
|
51
|
-
@amq.queue('keepalives')
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
95
|
-
@
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
event
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
data/sensu.gemspec
CHANGED