sensu 0.5.2 → 0.5.3
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/api.rb +8 -12
- data/lib/sensu/client.rb +7 -18
- data/lib/sensu/server.rb +30 -33
- data/sensu.gemspec +1 -1
- metadata +2 -2
data/lib/sensu/api.rb
CHANGED
@@ -87,15 +87,11 @@ module Sensu
|
|
87
87
|
conn.redis.exists('events:' + client).callback do |events_exist|
|
88
88
|
unless events_exist == 0
|
89
89
|
conn.redis.hgetall('events:' + client).callback do |events|
|
90
|
-
Hash[*events].keys.each do |
|
91
|
-
|
92
|
-
|
93
|
-
'client' => client,
|
94
|
-
'status' => 0,
|
95
|
-
'output' => 'client is being removed...'
|
96
|
-
}.to_json)
|
90
|
+
Hash[*events].keys.each do |check_name|
|
91
|
+
check = {'name' => check_name, 'issued' => Time.now.to_i, 'status' => 0, 'output' => 'client is being removed...'}
|
92
|
+
conn.amq.queue('results').publish({'client' => client, 'check' => check}.to_json)
|
97
93
|
end
|
98
|
-
EM.add_timer(
|
94
|
+
EM.add_timer(8) do
|
99
95
|
conn.redis.srem('clients', client)
|
100
96
|
conn.redis.del('events:' + client)
|
101
97
|
conn.redis.del('client:' + client)
|
@@ -117,15 +113,15 @@ module Sensu
|
|
117
113
|
end
|
118
114
|
|
119
115
|
apost '/test/client' do
|
120
|
-
|
116
|
+
attributes = '{
|
121
117
|
"name": "test",
|
122
|
-
"address": "
|
118
|
+
"address": "localhost",
|
123
119
|
"subscriptions": [
|
124
120
|
"foo",
|
125
121
|
"bar"
|
126
122
|
]
|
127
123
|
}'
|
128
|
-
conn.redis.set('client:test',
|
124
|
+
conn.redis.set('client:test', attributes).callback do
|
129
125
|
conn.redis.sadd('clients', 'test')
|
130
126
|
status 201
|
131
127
|
body ''
|
@@ -133,7 +129,7 @@ module Sensu
|
|
133
129
|
end
|
134
130
|
|
135
131
|
apost '/test/event' do
|
136
|
-
conn.redis.hset('events:test', 'test', {'status' => 2, 'output' => 'CRITICAL :: test'}.to_json).callback do
|
132
|
+
conn.redis.hset('events:test', 'test', {'status' => 2, 'output' => 'CRITICAL :: test', 'occurrences' => 1}.to_json).callback do
|
137
133
|
status 201
|
138
134
|
body ''
|
139
135
|
end
|
data/lib/sensu/client.rb
CHANGED
@@ -43,6 +43,7 @@ module Sensu
|
|
43
43
|
if @settings['checks'].has_key?(check['name'])
|
44
44
|
unless @checks_in_progress.include?(check['name'])
|
45
45
|
@checks_in_progress.push(check['name'])
|
46
|
+
result = {'client' => @settings['client']['name'], 'check' => check}
|
46
47
|
unmatched_tokens = Array.new
|
47
48
|
command = @settings['checks'][check['name']]['command'].gsub(/:::(.*?):::/) do
|
48
49
|
key = $1.to_s
|
@@ -51,31 +52,19 @@ module Sensu
|
|
51
52
|
end
|
52
53
|
if unmatched_tokens.empty?
|
53
54
|
EM.system('sh', '-c', command + ' 2>&1') do |output, status|
|
54
|
-
|
55
|
-
|
56
|
-
'client' => @settings['client']['name'],
|
57
|
-
'status' => status.exitstatus,
|
58
|
-
'output' => output
|
59
|
-
}.to_json)
|
55
|
+
result['check'].merge!({'status' => status.exitstatus, 'output' => output})
|
56
|
+
@result_queue.publish(result.to_json)
|
60
57
|
@checks_in_progress.delete(check['name'])
|
61
58
|
end
|
62
59
|
else
|
63
|
-
|
64
|
-
|
65
|
-
'client' => @settings['client']['name'],
|
66
|
-
'status' => 3,
|
67
|
-
'output' => 'Missing client attributes: ' + unmatched_tokens.join(', ')
|
68
|
-
}.to_json)
|
60
|
+
result['check'].merge!({'status' => 3, 'output' => 'Missing client attributes: ' + unmatched_tokens.join(', ')})
|
61
|
+
@result_queue.publish(result.to_json)
|
69
62
|
@checks_in_progress.delete(check['name'])
|
70
63
|
end
|
71
64
|
end
|
72
65
|
else
|
73
|
-
|
74
|
-
|
75
|
-
'client' => @settings['client']['name'],
|
76
|
-
'status' => 3,
|
77
|
-
'output' => 'Unknown check'
|
78
|
-
}.to_json)
|
66
|
+
result['check'].merge!({'status' => 3, 'output' => 'Unknown check'})
|
67
|
+
@result_queue.publish(result.to_json)
|
79
68
|
@checks_in_progress.delete(check['name'])
|
80
69
|
end
|
81
70
|
end
|
data/lib/sensu/server.rb
CHANGED
@@ -98,30 +98,38 @@ module Sensu
|
|
98
98
|
@redis.get('client:' + result['client']).callback do |client_json|
|
99
99
|
unless client_json.nil?
|
100
100
|
client = JSON.parse(client_json)
|
101
|
-
check =
|
102
|
-
check.merge!(@settings['checks'][
|
101
|
+
check = result['check']
|
102
|
+
check.merge!(@settings['checks'][check['name']]) if @settings['checks'].has_key?(check['name'])
|
103
103
|
check['handler'] = 'default' unless check['handler']
|
104
104
|
event = {
|
105
105
|
'client' => client,
|
106
|
-
'check' => check
|
107
|
-
'status' => result['status'],
|
108
|
-
'output' => result['output']
|
106
|
+
'check' => check
|
109
107
|
}
|
110
|
-
if check['
|
108
|
+
if check['type'] == 'metric'
|
111
109
|
handle_event(event)
|
112
110
|
else
|
113
111
|
if result['status'] == 0
|
114
|
-
@redis.hexists('events:' + client['name'],
|
112
|
+
@redis.hexists('events:' + client['name'], check['name']).callback do |exists|
|
115
113
|
if exists == 1
|
116
|
-
@redis.hdel('events:' + client['name'],
|
114
|
+
@redis.hdel('events:' + client['name'], check['name'])
|
117
115
|
event['action'] = 'resolve'
|
118
116
|
handle_event(event)
|
119
117
|
end
|
120
118
|
end
|
121
119
|
else
|
122
|
-
@redis.
|
123
|
-
|
124
|
-
|
120
|
+
@redis.hget('events:' + client['name'], check['name']).callback do |event_json|
|
121
|
+
occurrences = 1
|
122
|
+
unless event_json.nil?
|
123
|
+
previous_event = JSON.parse(event_json)
|
124
|
+
if previous_event['status'] == check['status']
|
125
|
+
occurrences = previous_event['occurrences'] += 1
|
126
|
+
end
|
127
|
+
end
|
128
|
+
@redis.hset('events:' + client['name'], check['name'], {'status' => check['status'], 'output' => check['output'], 'occurrences' => occurrences}.to_json).callback do
|
129
|
+
event['occurrences'] = occurrences
|
130
|
+
event['action'] = 'create'
|
131
|
+
handle_event(event)
|
132
|
+
end
|
125
133
|
end
|
126
134
|
end
|
127
135
|
end
|
@@ -138,7 +146,7 @@ module Sensu
|
|
138
146
|
if exchanges[exchange].nil?
|
139
147
|
exchanges[exchange] = @amq.fanout(exchange)
|
140
148
|
end
|
141
|
-
exchanges[exchange].publish({'name' => check['name']}.to_json)
|
149
|
+
exchanges[exchange].publish({'name' => check['name'], 'issued' => Time.now.to_i}.to_json)
|
142
150
|
EM.debug('published :: ' + exchange + ' :: ' + check['name'])
|
143
151
|
end
|
144
152
|
end
|
@@ -146,10 +154,10 @@ module Sensu
|
|
146
154
|
|
147
155
|
def setup_populator
|
148
156
|
check_queue = @amq.queue('checks')
|
149
|
-
@settings['checks'].each_with_index do |(name,
|
157
|
+
@settings['checks'].each_with_index do |(name, details), index|
|
150
158
|
EM.add_timer(7*index) do
|
151
|
-
EM.add_periodic_timer(
|
152
|
-
check_queue.publish({'name' => name, 'subscribers' =>
|
159
|
+
EM.add_periodic_timer(details['interval']) do
|
160
|
+
check_queue.publish({'name' => name, 'subscribers' => details['subscribers']}.to_json)
|
153
161
|
end
|
154
162
|
end
|
155
163
|
end
|
@@ -163,30 +171,19 @@ module Sensu
|
|
163
171
|
@redis.get('client:' + client_id).callback do |client_json|
|
164
172
|
client = JSON.parse(client_json)
|
165
173
|
time_since_last_check = Time.now.to_i - client['timestamp']
|
174
|
+
result = {'client' => client['name'], 'check' => {'name' => 'keepalive', 'issued' => Time.now.to_i}}
|
166
175
|
case
|
167
176
|
when time_since_last_check >= 180
|
168
|
-
|
169
|
-
|
170
|
-
'client' => client['name'],
|
171
|
-
'status' => 2,
|
172
|
-
'output' => 'No keep-alive sent from host in over 180 seconds'
|
173
|
-
}.to_json)
|
177
|
+
result['check'].merge!({'status' => 2, 'output' => 'No keep-alive sent from host in over 180 seconds'})
|
178
|
+
result_queue.publish(result.to_json)
|
174
179
|
when time_since_last_check >= 120
|
175
|
-
|
176
|
-
|
177
|
-
'client' => client['name'],
|
178
|
-
'status' => 1,
|
179
|
-
'output' => 'No keep-alive sent from host in over 120 seconds'
|
180
|
-
}.to_json)
|
180
|
+
result['check'].merge!({'status' => 1, 'output' => 'No keep-alive sent from host in over 120 seconds'})
|
181
|
+
result_queue.publish(result.to_json)
|
181
182
|
else
|
182
183
|
@redis.hexists('events:' + client_id, 'keepalive').callback do |exists|
|
183
184
|
if exists == 1
|
184
|
-
|
185
|
-
|
186
|
-
'client' => client['name'],
|
187
|
-
'status' => 0,
|
188
|
-
'output' => 'Keep-alive sent from host'
|
189
|
-
}.to_json)
|
185
|
+
result['check'].merge!({'status' => 0, 'output' => 'Keep-alive sent from host'})
|
186
|
+
result_queue.publish(result.to_json)
|
190
187
|
end
|
191
188
|
end
|
192
189
|
end
|
data/sensu.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sensu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sean Porter
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-09-
|
14
|
+
date: 2011-09-15 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: amqp
|