sensu 0.9.12.beta.5 → 0.9.12.beta.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2 -0
- data/lib/sensu/api.rb +63 -27
- data/lib/sensu/constants.rb +1 -1
- data/sensu.gemspec +1 -0
- metadata +28 -12
data/CHANGELOG.md
CHANGED
data/lib/sensu/api.rb
CHANGED
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), 'base')
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'redis')
|
3
3
|
|
4
4
|
gem 'thin', '1.5.0'
|
5
|
+
gem 'sinatra', '1.3.5'
|
5
6
|
gem 'async_sinatra', '1.0.0'
|
6
7
|
|
7
8
|
require 'thin'
|
@@ -136,6 +137,22 @@ module Sensu
|
|
136
137
|
env['rack.input'].rewind
|
137
138
|
end
|
138
139
|
|
140
|
+
def pagination(items)
|
141
|
+
limit = params[:limit] =~ /^[0-9]+$/ ? params[:limit].to_i : 0
|
142
|
+
offset = params[:offset] =~ /^[0-9]+$/ ? params[:offset].to_i : 0
|
143
|
+
unless limit == 0
|
144
|
+
headers['X-Pagination'] = Oj.dump(
|
145
|
+
:limit => limit,
|
146
|
+
:offset => offset,
|
147
|
+
:total => items.size
|
148
|
+
)
|
149
|
+
paginated = items.slice(offset, limit)
|
150
|
+
Array(paginated)
|
151
|
+
else
|
152
|
+
items
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
139
156
|
def bad_request!
|
140
157
|
ahalt 400
|
141
158
|
end
|
@@ -154,6 +171,10 @@ module Sensu
|
|
154
171
|
body response
|
155
172
|
end
|
156
173
|
|
174
|
+
def issued!
|
175
|
+
accepted!(Oj.dump(:issued => Time.now.to_i))
|
176
|
+
end
|
177
|
+
|
157
178
|
def no_content!
|
158
179
|
status 204
|
159
180
|
body ''
|
@@ -228,6 +249,7 @@ module Sensu
|
|
228
249
|
aget '/clients' do
|
229
250
|
response = Array.new
|
230
251
|
$redis.smembers('clients') do |clients|
|
252
|
+
clients = pagination(clients)
|
231
253
|
unless clients.empty?
|
232
254
|
clients.each_with_index do |client_name, index|
|
233
255
|
$redis.get('client:' + client_name) do |client_json|
|
@@ -309,7 +331,7 @@ module Sensu
|
|
309
331
|
$redis.del('history:' + client_name)
|
310
332
|
end
|
311
333
|
end
|
312
|
-
|
334
|
+
issued!
|
313
335
|
end
|
314
336
|
else
|
315
337
|
not_found!
|
@@ -334,7 +356,7 @@ module Sensu
|
|
334
356
|
begin
|
335
357
|
post_body = Oj.load(request.body.read)
|
336
358
|
check_name = post_body[:check]
|
337
|
-
subscribers = post_body[:subscribers]
|
359
|
+
subscribers = post_body[:subscribers]
|
338
360
|
if check_name.is_a?(String) && subscribers.is_a?(Array)
|
339
361
|
if $settings.check_exists?(check_name)
|
340
362
|
check = $settings[:checks][check_name]
|
@@ -353,7 +375,7 @@ module Sensu
|
|
353
375
|
subscribers.uniq.each do |exchange_name|
|
354
376
|
$amq.fanout(exchange_name).publish(Oj.dump(payload))
|
355
377
|
end
|
356
|
-
|
378
|
+
issued!
|
357
379
|
else
|
358
380
|
not_found!
|
359
381
|
end
|
@@ -410,7 +432,7 @@ module Sensu
|
|
410
432
|
$redis.hgetall('events:' + client_name) do |events|
|
411
433
|
if events.include?(check_name)
|
412
434
|
resolve_event(event_hash(events[check_name], client_name, check_name))
|
413
|
-
|
435
|
+
issued!
|
414
436
|
else
|
415
437
|
not_found!
|
416
438
|
end
|
@@ -426,7 +448,7 @@ module Sensu
|
|
426
448
|
$redis.hgetall('events:' + client_name) do |events|
|
427
449
|
if events.include?(check_name)
|
428
450
|
resolve_event(event_hash(events[check_name], client_name, check_name))
|
429
|
-
|
451
|
+
issued!
|
430
452
|
else
|
431
453
|
not_found!
|
432
454
|
end
|
@@ -445,6 +467,9 @@ module Sensu
|
|
445
467
|
unless checks.empty?
|
446
468
|
checks.each_with_index do |check_name, index|
|
447
469
|
$redis.smembers('aggregates:' + check_name) do |aggregates|
|
470
|
+
aggregates.map! do |issued|
|
471
|
+
issued.to_i
|
472
|
+
end
|
448
473
|
item = {
|
449
474
|
:check => check_name,
|
450
475
|
:issued => aggregates.sort.reverse
|
@@ -464,27 +489,23 @@ module Sensu
|
|
464
489
|
aget %r{/aggregates/([\w\.-]+)$} do |check_name|
|
465
490
|
$redis.smembers('aggregates:' + check_name) do |aggregates|
|
466
491
|
unless aggregates.empty?
|
492
|
+
aggregates.map! do |issued|
|
493
|
+
issued.to_i
|
494
|
+
end
|
467
495
|
valid_request = true
|
468
496
|
if params[:age]
|
469
497
|
if params[:age] =~ /^[0-9]+$/
|
470
498
|
timestamp = Time.now.to_i - params[:age].to_i
|
471
499
|
aggregates.reject! do |issued|
|
472
|
-
issued
|
500
|
+
issued > timestamp
|
473
501
|
end
|
474
502
|
else
|
475
503
|
valid_request = false
|
476
504
|
end
|
477
505
|
end
|
478
|
-
limit = 10
|
479
|
-
if params[:limit]
|
480
|
-
if params[:limit] =~ /^[0-9]+$/
|
481
|
-
limit = params[:limit].to_i
|
482
|
-
else
|
483
|
-
valid_request = false
|
484
|
-
end
|
485
|
-
end
|
486
506
|
if valid_request
|
487
|
-
|
507
|
+
aggregates = pagination(aggregates.sort.reverse)
|
508
|
+
body Oj.dump(aggregates)
|
488
509
|
else
|
489
510
|
bad_request!
|
490
511
|
end
|
@@ -552,7 +573,7 @@ module Sensu
|
|
552
573
|
post_body = Oj.load(request.body.read)
|
553
574
|
$redis.set('stash:' + path, Oj.dump(post_body)) do
|
554
575
|
$redis.sadd('stashes', path) do
|
555
|
-
created!(Oj.dump(
|
576
|
+
created!(Oj.dump(:path => path))
|
556
577
|
end
|
557
578
|
end
|
558
579
|
rescue Oj::ParseError
|
@@ -585,24 +606,39 @@ module Sensu
|
|
585
606
|
end
|
586
607
|
|
587
608
|
aget '/stashes' do
|
609
|
+
response = Array.new
|
588
610
|
$redis.smembers('stashes') do |stashes|
|
589
|
-
|
611
|
+
stashes = pagination(stashes)
|
612
|
+
unless stashes.empty?
|
613
|
+
stashes.each_with_index do |path, index|
|
614
|
+
$redis.get('stash:' + path) do |stash_json|
|
615
|
+
unless stash_json.nil?
|
616
|
+
item = {
|
617
|
+
:path => path,
|
618
|
+
:content => Oj.load(stash_json)
|
619
|
+
}
|
620
|
+
response << item
|
621
|
+
end
|
622
|
+
if index == stashes.size - 1
|
623
|
+
body Oj.dump(response)
|
624
|
+
end
|
625
|
+
end
|
626
|
+
end
|
627
|
+
else
|
628
|
+
body Oj.dump(response)
|
629
|
+
end
|
590
630
|
end
|
591
631
|
end
|
592
632
|
|
593
633
|
apost '/stashes' do
|
594
634
|
begin
|
595
635
|
post_body = Oj.load(request.body.read)
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
end
|
603
|
-
if index == post_body.size - 1
|
604
|
-
body Oj.dump(response)
|
605
|
-
end
|
636
|
+
path = post_body[:path]
|
637
|
+
content = post_body[:content]
|
638
|
+
if path.is_a?(String) && content.is_a?(Hash)
|
639
|
+
$redis.set('stash:' + path, Oj.dump(content)) do
|
640
|
+
$redis.sadd('stashes', path) do
|
641
|
+
created!(Oj.dump(:path => path))
|
606
642
|
end
|
607
643
|
end
|
608
644
|
else
|
data/lib/sensu/constants.rb
CHANGED
data/sensu.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency('amqp', '0.9.10')
|
19
19
|
s.add_dependency('em-redis-unified', '0.4.1')
|
20
20
|
s.add_dependency('thin', '1.5.0')
|
21
|
+
s.add_dependency('sinatra', '1.3.5')
|
21
22
|
s.add_dependency('async_sinatra', '1.0.0')
|
22
23
|
|
23
24
|
s.add_development_dependency('rake')
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -2966743116
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
9
|
- 12
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.9.12.beta.
|
11
|
+
- 6
|
12
|
+
version: 0.9.12.beta.6
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Sean Porter
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2013-03-
|
21
|
+
date: 2013-03-24 00:00:00 -07:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -102,9 +102,25 @@ dependencies:
|
|
102
102
|
type: :runtime
|
103
103
|
version_requirements: *id005
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
105
|
+
name: sinatra
|
106
106
|
prerelease: false
|
107
107
|
requirement: &id006 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - "="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 17
|
113
|
+
segments:
|
114
|
+
- 1
|
115
|
+
- 3
|
116
|
+
- 5
|
117
|
+
version: 1.3.5
|
118
|
+
type: :runtime
|
119
|
+
version_requirements: *id006
|
120
|
+
- !ruby/object:Gem::Dependency
|
121
|
+
name: async_sinatra
|
122
|
+
prerelease: false
|
123
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
108
124
|
none: false
|
109
125
|
requirements:
|
110
126
|
- - "="
|
@@ -116,11 +132,11 @@ dependencies:
|
|
116
132
|
- 0
|
117
133
|
version: 1.0.0
|
118
134
|
type: :runtime
|
119
|
-
version_requirements: *
|
135
|
+
version_requirements: *id007
|
120
136
|
- !ruby/object:Gem::Dependency
|
121
137
|
name: rake
|
122
138
|
prerelease: false
|
123
|
-
requirement: &
|
139
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
124
140
|
none: false
|
125
141
|
requirements:
|
126
142
|
- - ">="
|
@@ -130,11 +146,11 @@ dependencies:
|
|
130
146
|
- 0
|
131
147
|
version: "0"
|
132
148
|
type: :development
|
133
|
-
version_requirements: *
|
149
|
+
version_requirements: *id008
|
134
150
|
- !ruby/object:Gem::Dependency
|
135
151
|
name: rspec
|
136
152
|
prerelease: false
|
137
|
-
requirement: &
|
153
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
138
154
|
none: false
|
139
155
|
requirements:
|
140
156
|
- - ">="
|
@@ -144,11 +160,11 @@ dependencies:
|
|
144
160
|
- 0
|
145
161
|
version: "0"
|
146
162
|
type: :development
|
147
|
-
version_requirements: *
|
163
|
+
version_requirements: *id009
|
148
164
|
- !ruby/object:Gem::Dependency
|
149
165
|
name: em-http-request
|
150
166
|
prerelease: false
|
151
|
-
requirement: &
|
167
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
152
168
|
none: false
|
153
169
|
requirements:
|
154
170
|
- - ">="
|
@@ -158,7 +174,7 @@ dependencies:
|
|
158
174
|
- 0
|
159
175
|
version: "0"
|
160
176
|
type: :development
|
161
|
-
version_requirements: *
|
177
|
+
version_requirements: *id010
|
162
178
|
description: A monitoring framework that aims to be simple, malleable, and scalable. Uses the publish/subscribe model.
|
163
179
|
email:
|
164
180
|
- portertech@gmail.com
|