sumo-search 0.1.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cane +0 -0
- data/.gitignore +0 -2
- data/.travis.yml +7 -0
- data/README.md +54 -27
- data/Rakefile +8 -3
- data/bin/sumo +2 -69
- data/lib/sumo/cli.rb +43 -0
- data/lib/sumo/client.rb +82 -0
- data/lib/sumo/collection.rb +97 -0
- data/lib/sumo/config.rb +11 -14
- data/lib/sumo/error.rb +8 -11
- data/lib/sumo/search.rb +69 -0
- data/lib/sumo/version.rb +9 -2
- data/lib/sumo.rb +52 -18
- data/spec/fixtures/sumo-creds +1 -0
- data/spec/lib/sumo/client_spec.rb +136 -0
- data/spec/lib/sumo/config_spec.rb +55 -74
- data/spec/lib/sumo/search_spec.rb +106 -0
- data/spec/lib/sumo_spec.rb +0 -30
- data/spec/spec_helper.rb +5 -7
- data/spec/support/vcr.rb +41 -5
- data/spec/vcr/Sumo_Search/_create/sets_the_id_and_client.yml +42 -0
- data/spec/vcr/Sumo_Search/_delete_/deletes_the_search.yml +102 -0
- data/spec/vcr/Sumo_Search/_messages/returns_an_Enumerator_of_each_message_in_the_search.yml +2579 -0
- data/spec/vcr/Sumo_Search/_records/returns_an_Enumerator_of_each_record_in_the_search.yml +2348 -0
- data/spec/vcr/Sumo_Search/_status/returns_the_status_of_the_search.yml +71 -0
- data/sumo-search.gemspec +5 -6
- metadata +62 -57
- data/lib/sumo/formatter.rb +0 -21
- data/lib/sumo/query_builder.rb +0 -61
- data/spec/fixtures/sumo_creds +0 -1
- data/spec/lib/sumo/formatter_spec.rb +0 -51
- data/spec/lib/sumo/query_builder_spec.rb +0 -128
- data/spec/vcr/Sumo/_search/when_the_credentials_can_be_found/and_the_query_is_valid/parses_the_response.yml +0 -49
- data/spec/vcr/Sumo/_search/when_the_credentials_can_be_found/but_the_query_is_invalid/raises_an_error.yml +0 -43
- data/spec/vcr/Sumo_QueryBuilder/integration/when_the_request_is_invalid/raises_an_error.yml +0 -43
- data/spec/vcr/Sumo_QueryBuilder/integration/when_the_request_is_valid/compiles_and_sends_the_query_to_the_server.yml +0 -49
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Sumo::QueryBuilder do
|
4
|
-
subject { Sumo::QueryBuilder.new('fake-creds') }
|
5
|
-
|
6
|
-
describe '.new' do
|
7
|
-
context 'when the correct types of arguments are supplied' do
|
8
|
-
subject { Sumo::QueryBuilder.new('auth', 'q' => 'error') }
|
9
|
-
|
10
|
-
it 'creates a new QueryBuilder' do
|
11
|
-
subject.creds.should == 'auth'
|
12
|
-
subject.opts.should == { 'q' => 'error' }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when invalid arguments are supplied' do
|
17
|
-
it 'raises an error' do
|
18
|
-
expect { Sumo::QueryBuilder.new(:symbol, 1) }
|
19
|
-
.to raise_error(Sumo::Error::TypeError)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#query' do
|
25
|
-
it 'adds a query to the request' do
|
26
|
-
subject.query('alpha').opts.should == { 'q' => 'alpha' }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#to' do
|
31
|
-
it 'adds an end time to the request' do
|
32
|
-
subject.to('now').opts.should == { 'to' => 'now' }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#from' do
|
37
|
-
it 'adds an end time to the request' do
|
38
|
-
subject.from('-15m').opts.should == { 'from' => '-15m' }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#time_zone' do
|
43
|
-
it 'adds a time zone to the request' do
|
44
|
-
subject.time_zone('UTC').opts.should == { 'tz' => 'UTC' }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#format' do
|
49
|
-
it 'adds a format to the request' do
|
50
|
-
subject.format('JSON').opts.should == { 'format' => 'JSON' }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#execute' do
|
55
|
-
let(:creds) { 'user@example.com:pass' }
|
56
|
-
let(:encoded) { Base64.encode64(creds) }
|
57
|
-
let(:conn) { double(:connection) }
|
58
|
-
let(:query) {
|
59
|
-
{
|
60
|
-
'q' => 'production',
|
61
|
-
'from' => '-30m',
|
62
|
-
'to' => '-15m',
|
63
|
-
'tz' => 'UTC',
|
64
|
-
'format' => 'json'
|
65
|
-
}
|
66
|
-
}
|
67
|
-
subject {
|
68
|
-
Sumo::QueryBuilder.new(creds).query('production')
|
69
|
-
.from('-30m')
|
70
|
-
.to('-15m')
|
71
|
-
.time_zone('UTC')
|
72
|
-
.format('json')
|
73
|
-
}
|
74
|
-
|
75
|
-
before do
|
76
|
-
subject.stub(:connection).and_return(conn)
|
77
|
-
conn.stub(:get)
|
78
|
-
.with(:path => '/api/v1/logs/search',
|
79
|
-
:query => query,
|
80
|
-
:headers => { 'Authorization' => "Basic #{encoded}" })
|
81
|
-
.and_return(resp)
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'when the server responds' do
|
85
|
-
let(:resp) { double(:response, :body => '{}', :status => 200) }
|
86
|
-
|
87
|
-
it 'parses the response' do
|
88
|
-
subject.execute.should == '{}'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when the server does not respond' do
|
93
|
-
let(:resp) { double(:response, :body => nil, :status => 504) }
|
94
|
-
|
95
|
-
it 'raises an error' do
|
96
|
-
expect { subject.execute }.to raise_error(Sumo::Error::RequestError)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'integration', :vcr do
|
102
|
-
# WARNING: If you are going to change this VCR, modify the credentials so
|
103
|
-
# that they are valid, record the VCR, remove the credentials from it, and
|
104
|
-
# change the below variable back to its original form.
|
105
|
-
let(:creds) { 'aladdin@swipely.com:open sesame' }
|
106
|
-
|
107
|
-
context 'when the request is valid' do
|
108
|
-
let(:result) { JSON.parse(subject.execute) }
|
109
|
-
subject { Sumo::QueryBuilder.new(creds).query('nginx') }
|
110
|
-
|
111
|
-
it 'compiles and sends the query to the server' do
|
112
|
-
result.length.should_not be_zero
|
113
|
-
result.should be_all { |hash|
|
114
|
-
%w(_sourcecategory _raw _sourcehost _receipttime _sourcename
|
115
|
-
_messagetime).all? { |key| hash.has_key?(key) }
|
116
|
-
}
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when the request is invalid' do
|
121
|
-
subject { Sumo::QueryBuilder.new(creds).query('nginx').to('nonsense') }
|
122
|
-
|
123
|
-
it 'raises an error' do
|
124
|
-
expect { subject.execute }.to raise_error(Sumo::Error::RequestError)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.sumologic.com/api/v1/logs/search?q=rails
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
User-Agent:
|
11
|
-
- excon/0.31.0
|
12
|
-
Authorization:
|
13
|
-
- |
|
14
|
-
Basic YWxhZGRpbkBzd2lwZWx5LmNvbTpvcGVuIHNlc2FtZQ==
|
15
|
-
response:
|
16
|
-
status:
|
17
|
-
code: 200
|
18
|
-
message:
|
19
|
-
headers:
|
20
|
-
Cache-control:
|
21
|
-
- no-cache="set-cookie"
|
22
|
-
Content-Type:
|
23
|
-
- application/json; charset=ISO-8859-1
|
24
|
-
Date:
|
25
|
-
- Tue, 07 Jan 2014 18:32:15 GMT
|
26
|
-
Expires:
|
27
|
-
- Thu, 01-Jan-1970 00:00:00 GMT
|
28
|
-
Set-Cookie:
|
29
|
-
- JSESSIONID=p8dhtx823tvbbxs578ipt3mn;Path=/api, AWSELB=D5C1176F0665104977B708B0B48E6FFEC09E311CD1473A91FD800B5F0A2443FAC23088ACED0D807762BB3B769CEAADA14ED5C9BC9C86BA1749DC556A5C1B04944D462E0D92;PATH=/
|
30
|
-
Content-Length:
|
31
|
-
- '1052'
|
32
|
-
Connection:
|
33
|
-
- Close
|
34
|
-
body:
|
35
|
-
encoding: UTF-8
|
36
|
-
string: |-
|
37
|
-
[
|
38
|
-
{
|
39
|
-
"_sourcecategory" : "all",
|
40
|
-
"_raw" : "{\"@source\":\"syslog://\",\"@tags\":[\"railslog\"],\"@fields\":{\"facility\":\"local0\",\"severity\":[\"notice\",\"D\"],\"program\":\"swipely-ledger-delayed-1\",\"processid\":\"-\",\"sslsubject\":[\"/C=US/ST=Rhode Island/O=Swipely/OU=Engineering/CN=s-ledger\",\"/C=US/ST=Rhode Island/O=Swipely/OU=Engineering/CN=s-ledger\"],\"host\":[\"s-ledger\"],\"timestamp\":[\"140107-18:26:50.605\"],\"thread_id\":[\"8_15364200\"],\"msg\":[\"** [Honeybadger] Environment Info: [Ruby: 1.9.3] [Rails: 3.2.11] [Env: staging]\"]},\"@timestamp\":\"2014-01-07T18:26:54.159449+00:00\",\"@source_host\":\"ip-10-244-158-144\",\"@message\":\"Jan 7 18:26:54 swipely-ledger-delayed-1:D 140107-18:26:50.605 8_15364200: ** [Honeybadger] Environment Info: [Ruby: 1.9.3] [Rails: 3.2.11] [Env: staging]\",\"@type\":\"syslog\"}",
|
41
|
-
"_sourcehost" : "logs.example.com",
|
42
|
-
"_receipttime" : 1389119226829,
|
43
|
-
"_sourcename" : "/media/ephemeral0/logs/swipely/s-ledger-2014-01-07.log",
|
44
|
-
"_messagetime" : 1389119214159
|
45
|
-
}
|
46
|
-
]
|
47
|
-
http_version:
|
48
|
-
recorded_at: Tue, 07 Jan 2014 18:32:19 GMT
|
49
|
-
recorded_with: VCR 2.8.0
|
@@ -1,43 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.sumologic.com/api/v1/logs/search?from=never&q=Rails
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
User-Agent:
|
11
|
-
- excon/0.31.0
|
12
|
-
Authorization:
|
13
|
-
- |
|
14
|
-
Basic YWxhZGRpbkBzd2lwZWx5LmNvbTpvcGVuIHNlc2FtZQ==
|
15
|
-
response:
|
16
|
-
status:
|
17
|
-
code: 400
|
18
|
-
message:
|
19
|
-
headers:
|
20
|
-
Cache-control:
|
21
|
-
- no-cache="set-cookie"
|
22
|
-
Content-Type:
|
23
|
-
- application/json; charset=ISO-8859-1
|
24
|
-
Date:
|
25
|
-
- Tue, 07 Jan 2014 18:30:35 GMT
|
26
|
-
Set-Cookie:
|
27
|
-
- AWSELB=D5C1176F0665104977B708B0B48E6FFEC09E311CD1473A91FD800B5F0A2443FAC23088ACED0D807762BB3B769CEAADA14ED5C9BC9C86BA1749DC556A5C1B04944D462E0D92;PATH=/
|
28
|
-
Content-Length:
|
29
|
-
- '154'
|
30
|
-
Connection:
|
31
|
-
- Close
|
32
|
-
body:
|
33
|
-
encoding: UTF-8
|
34
|
-
string: |-
|
35
|
-
{
|
36
|
-
"status" : 400,
|
37
|
-
"id" : "9IJJK-HJQ9G-H09X3",
|
38
|
-
"code" : "search.invalid.timestamp.from",
|
39
|
-
"message" : "The 'from' field contains an invalid time."
|
40
|
-
}
|
41
|
-
http_version:
|
42
|
-
recorded_at: Tue, 07 Jan 2014 18:30:39 GMT
|
43
|
-
recorded_with: VCR 2.8.0
|
@@ -1,43 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.sumologic.com/api/v1/logs/search?q=nginx&to=nonsense
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
User-Agent:
|
11
|
-
- excon/0.31.0
|
12
|
-
Authorization:
|
13
|
-
- |
|
14
|
-
Basic YWxhZGRpbkBzd2lwZWx5LmNvbTpvcGVuIHNlc2FtZQ==
|
15
|
-
response:
|
16
|
-
status:
|
17
|
-
code: 400
|
18
|
-
message:
|
19
|
-
headers:
|
20
|
-
Cache-control:
|
21
|
-
- no-cache="set-cookie"
|
22
|
-
Content-Type:
|
23
|
-
- application/json; charset=ISO-8859-1
|
24
|
-
Date:
|
25
|
-
- Tue, 07 Jan 2014 15:52:16 GMT
|
26
|
-
Set-Cookie:
|
27
|
-
- AWSELB=D5C1176F0665104977B708B0B48E6FFEC09E311CD10EE26CC6F86FEAE76E4BBB3D728D261CADA16D6256329826144A742E70346FDF2C8592D1FAF5BF2ABFF69B2FDD5A38FA;PATH=/
|
28
|
-
Content-Length:
|
29
|
-
- '150'
|
30
|
-
Connection:
|
31
|
-
- Close
|
32
|
-
body:
|
33
|
-
encoding: UTF-8
|
34
|
-
string: |-
|
35
|
-
{
|
36
|
-
"status" : 400,
|
37
|
-
"id" : "ELTN2-7BBZF-ZCZQ8",
|
38
|
-
"code" : "search.invalid.timestamp.to",
|
39
|
-
"message" : "The 'to' field contains an invalid time."
|
40
|
-
}
|
41
|
-
http_version:
|
42
|
-
recorded_at: Tue, 07 Jan 2014 15:52:18 GMT
|
43
|
-
recorded_with: VCR 2.8.0
|
@@ -1,49 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.sumologic.com/api/v1/logs/search?q=nginx
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
User-Agent:
|
11
|
-
- excon/0.31.0
|
12
|
-
Authorization:
|
13
|
-
- |
|
14
|
-
Basic YWxhZGRpbkBzd2lwZWx5LmNvbTpvcGVuIHNlc2FtZQ==
|
15
|
-
response:
|
16
|
-
status:
|
17
|
-
code: 200
|
18
|
-
message:
|
19
|
-
headers:
|
20
|
-
Cache-control:
|
21
|
-
- no-cache="set-cookie"
|
22
|
-
Content-Type:
|
23
|
-
- application/json; charset=ISO-8859-1
|
24
|
-
Date:
|
25
|
-
- Tue, 07 Jan 2014 15:49:55 GMT
|
26
|
-
Expires:
|
27
|
-
- Thu, 01-Jan-1970 00:00:00 GMT
|
28
|
-
Set-Cookie:
|
29
|
-
- JSESSIONID=1dybd1qub96gu13g5a9qh9dyqc;Path=/api, AWSELB=D5C1176F0665104977B708B0B48E6FFEC09E311CD1473A91FD800B5F0A2443FAC23088ACEDDBBB8C99D44C2403D82B59D74368F2FCC1FFB75ECAF9255D4A40FE87F45B4364;PATH=/
|
30
|
-
transfer-encoding:
|
31
|
-
- ''
|
32
|
-
Connection:
|
33
|
-
- Close
|
34
|
-
body:
|
35
|
-
encoding: UTF-8
|
36
|
-
string: |-
|
37
|
-
[
|
38
|
-
{
|
39
|
-
"_sourcecategory" : "all",
|
40
|
-
"_raw" : "nonsense result",
|
41
|
-
"_sourcehost" : "ls01.logs.swipely.com",
|
42
|
-
"_receipttime" : 1389109434302,
|
43
|
-
"_sourcename" : "/media/ephemeral0/logs/swipely/p-ledger-lb-2014-01-07.log",
|
44
|
-
"_messagetime" : 1389109430911
|
45
|
-
}
|
46
|
-
]
|
47
|
-
http_version:
|
48
|
-
recorded_at: Tue, 07 Jan 2014 15:49:59 GMT
|
49
|
-
recorded_with: VCR 2.8.0
|