papertrail 0.10.0 → 0.11.1
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.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/bin/papertrail-add-group +1 -0
- data/bin/papertrail-add-system +1 -0
- data/bin/papertrail-join-group +1 -0
- data/bin/papertrail-leave-group +1 -0
- data/bin/papertrail-remove-system +1 -0
- data/lib/papertrail.rb +1 -1
- data/lib/papertrail/cli.rb +4 -1
- data/lib/papertrail/cli_add_group.rb +9 -8
- data/lib/papertrail/cli_add_system.rb +12 -11
- data/lib/papertrail/connection.rb +16 -3
- data/lib/papertrail/event.rb +1 -1
- data/lib/papertrail/http_client.rb +47 -45
- data/papertrail.gemspec +7 -2
- data/test/connection_test.rb +11 -0
- data/test/http_client_test.rb +46 -0
- data/test/test_helper.rb +7 -2
- metadata +35 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ffe54b3afcb866c1d80ccadf5deff840bbc2d8e9fb851ec2054f0869160eb565
|
4
|
+
data.tar.gz: 13e987776d80aedee04422b2490a09123e2045bdc0a220069931a2047e354009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13122c148a5417fe71ab68baf78c689ed52178d7c5176b7d194684167f0d1a95ada468666bef37d8a5bf3dccedacbaab93e5c40d44642af2f670b1f7580ddd8c
|
7
|
+
data.tar.gz: e5afab539b26cc93d45d3d44da399efa4d3547f2071451f5c765cdff093e4a212338b20c26ae402cee521e7158f27792cd26558dd07a3305b5f5bb59ea532bc3
|
data/README.md
CHANGED
@@ -298,7 +298,7 @@ to your enhancement.
|
|
298
298
|
[Papertrail]: http://papertrailapp.com/
|
299
299
|
[Connection]: https://github.com/papertrail/papertrail-cli/blob/master/lib/papertrail/connection.rb
|
300
300
|
[HTTP API]: http://help.papertrailapp.com/kb/how-it-works/http-api
|
301
|
-
[User Profile]: https://papertrailapp.com/
|
301
|
+
[User Profile]: https://papertrailapp.com/account/profile
|
302
302
|
[RubyGems]: https://rubygems.org/gems/papertrail-cli
|
303
303
|
[lnav]: http://lnav.org/
|
304
304
|
[escape characters]: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
data/bin/papertrail-add-group
CHANGED
data/bin/papertrail-add-system
CHANGED
data/bin/papertrail-join-group
CHANGED
data/bin/papertrail-leave-group
CHANGED
data/lib/papertrail.rb
CHANGED
data/lib/papertrail/cli.rb
CHANGED
@@ -95,6 +95,9 @@ module Papertrail
|
|
95
95
|
|
96
96
|
@connection = Papertrail::Connection.new(options)
|
97
97
|
|
98
|
+
# Use HTTP Keep-Alive unless delay is too long
|
99
|
+
connection.start if options[:delay] < 10
|
100
|
+
|
98
101
|
if options[:system]
|
99
102
|
query_options[:system_id] = connection.find_id_for_source(options[:system])
|
100
103
|
unless query_options[:system_id]
|
@@ -166,7 +169,7 @@ module Papertrail
|
|
166
169
|
|
167
170
|
idx = attribs.hash % 5
|
168
171
|
color = COLORS[idx]
|
169
|
-
pre = "#{event.received_at.strftime('%b %
|
172
|
+
pre = "#{event.received_at.strftime('%b %d %X')} #{event.data['hostname']} #{event.data['program']}:"
|
170
173
|
post = " #{event.data['message']}"
|
171
174
|
pre.ansi(color) + post
|
172
175
|
end
|
@@ -46,15 +46,16 @@ module Papertrail
|
|
46
46
|
|
47
47
|
raise OptionParser::MissingArgument, 'group' if options[:group].nil?
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
Papertrail::Connection.new(options).start do |connection|
|
50
|
+
# Bail if group already exists
|
51
|
+
existing = connection.show_group(options[:group])
|
52
|
+
if existing && existing['name'].upcase == options[:group].upcase
|
53
|
+
exit 0
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
if connection.create_group(options[:group], options[:wildcard])
|
57
|
+
exit 0
|
58
|
+
end
|
58
59
|
end
|
59
60
|
|
60
61
|
exit 1
|
@@ -84,19 +84,20 @@ module Papertrail
|
|
84
84
|
error 'Either --ip-address or --destination-port most be provided'
|
85
85
|
end
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
Papertrail::Connection.new(options).start do |connection|
|
88
|
+
# Bail if system already exists
|
89
|
+
existing = connection.show_source(options[:system])
|
90
|
+
if existing && existing['name'].upcase == options[:system].upcase
|
91
|
+
exit 0
|
92
|
+
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
if options[:destination_port] && !options[:hostname]
|
95
|
+
options[:hostname] = options[:system]
|
96
|
+
end
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
if connection.register_source(options[:system], options)
|
99
|
+
exit 0
|
100
|
+
end
|
100
101
|
end
|
101
102
|
|
102
103
|
exit 1
|
@@ -38,19 +38,32 @@ module Papertrail
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def start
|
42
|
+
if block_given?
|
43
|
+
@connection.start { yield self }
|
44
|
+
else
|
45
|
+
@connection.start
|
46
|
+
self
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def finish
|
51
|
+
@connection.finish
|
52
|
+
end
|
53
|
+
|
41
54
|
def find_id_for_source(name)
|
42
|
-
response = @connection.get('systems.json')
|
55
|
+
response = @connection.get('systems.json', :system_name => name)
|
43
56
|
|
44
57
|
find_id_for_item(response.body, name)
|
45
58
|
end
|
46
59
|
|
47
60
|
def find_id_for_group(name)
|
48
|
-
response = @connection.get('groups.json')
|
61
|
+
response = @connection.get('groups.json', :group_name => name)
|
49
62
|
find_id_for_item(response.body, name)
|
50
63
|
end
|
51
64
|
|
52
65
|
def find_search(name, group_id = nil)
|
53
|
-
response = @connection.get('searches.json')
|
66
|
+
response = @connection.get('searches.json', :search_name => name)
|
54
67
|
|
55
68
|
candidates = find_items_by_name(response.body, name)
|
56
69
|
return nil if candidates.empty?
|
data/lib/papertrail/event.rb
CHANGED
@@ -13,7 +13,7 @@ module Papertrail
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
"#{received_at.strftime('%b %
|
16
|
+
"#{received_at.strftime('%b %d %X')} #{data['hostname']} #{data['program']}: #{data['message']}"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -37,6 +37,19 @@ module Papertrail
|
|
37
37
|
@headers = {}
|
38
38
|
end
|
39
39
|
|
40
|
+
def start
|
41
|
+
if block_given?
|
42
|
+
https.start { yield self }
|
43
|
+
else
|
44
|
+
https.start
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def finish
|
50
|
+
https.finish
|
51
|
+
end
|
52
|
+
|
40
53
|
def basic_auth(login, pass)
|
41
54
|
@headers['Authorization'] = 'Basic ' + ["#{login}:#{pass}"].pack('m').delete("\r\n")
|
42
55
|
end
|
@@ -46,73 +59,62 @@ module Papertrail
|
|
46
59
|
end
|
47
60
|
|
48
61
|
def get(path, params = {})
|
49
|
-
|
50
|
-
path = "#{path}?cli_version=#{Papertrail::VERSION}&#{build_nested_query(params)}"
|
51
|
-
end
|
52
|
-
attempts = 0
|
53
|
-
begin
|
54
|
-
on_complete(https.get(request_uri(path), @headers))
|
55
|
-
rescue SystemCallError, Net::HTTPFatalError => e
|
56
|
-
sleep 5.0
|
57
|
-
attempts += 1
|
58
|
-
retry if (attempts < 3)
|
59
|
-
raise e
|
60
|
-
end
|
62
|
+
request(:get, path, params)
|
61
63
|
end
|
62
64
|
|
63
65
|
def put(path, params)
|
64
|
-
|
65
|
-
begin
|
66
|
-
on_complete(https.put(request_uri(path), build_nested_query(params), @headers))
|
67
|
-
rescue SystemCallError, Net::HTTPFatalError => e
|
68
|
-
attempts += 1
|
69
|
-
retry if (attempts < 3)
|
70
|
-
raise e
|
71
|
-
end
|
66
|
+
request(:put, path, params)
|
72
67
|
end
|
73
68
|
|
74
69
|
def post(path, params)
|
75
|
-
|
76
|
-
begin
|
77
|
-
on_complete(https.post(request_uri(path), build_nested_query(params), @headers))
|
78
|
-
rescue SystemCallError, Net::HTTPFatalError => e
|
79
|
-
attempts += 1
|
80
|
-
retry if (attempts < 3)
|
81
|
-
raise e
|
82
|
-
end
|
70
|
+
request(:post, path, params)
|
83
71
|
end
|
84
72
|
|
85
73
|
def delete(path)
|
74
|
+
request(:delete, path)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def request(http_method, path, params = {})
|
86
80
|
attempts = 0
|
81
|
+
uri = "#{request_uri(path)}?cli_version=#{Papertrail::VERSION}&"
|
87
82
|
begin
|
88
|
-
|
89
|
-
|
83
|
+
if http_method == :get || http_method == :delete
|
84
|
+
on_complete(https.send(http_method, uri + build_nested_query(params.merge(cli_version)), @headers))
|
85
|
+
else
|
86
|
+
on_complete(https.send(http_method, uri, build_nested_query(params), @headers))
|
87
|
+
end
|
88
|
+
rescue IOError, SystemCallError, Net::HTTPFatalError => e
|
90
89
|
attempts += 1
|
91
90
|
retry if (attempts < 3)
|
92
91
|
raise e
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
96
|
-
private
|
97
|
-
|
98
95
|
def request_uri(path)
|
99
96
|
path.start_with?('/api/v1/') ? path : "/api/v1/#{path}"
|
100
97
|
end
|
101
98
|
|
102
99
|
def https
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
100
|
+
@https ||= Net::HTTP.new('papertrailapp.com', 443).tap do |http|
|
101
|
+
http.use_ssl = true
|
102
|
+
http.verify_mode = ssl_verify_mode
|
103
|
+
http.cert_store = ssl_cert_store
|
104
|
+
|
105
|
+
http.cert = @ssl[:client_cert] if @ssl[:client_cert]
|
106
|
+
http.key = @ssl[:client_key] if @ssl[:client_key]
|
107
|
+
http.ca_file = @ssl[:ca_file] if @ssl[:ca_file]
|
108
|
+
http.ca_path = @ssl[:ca_path] if @ssl[:ca_path]
|
109
|
+
http.verify_depth = @ssl[:verify_depth] if @ssl[:verify_depth]
|
110
|
+
http.ssl_version = @ssl[:version] if @ssl[:version]
|
111
|
+
|
112
|
+
http.keep_alive_timeout = 10 if http.respond_to?(:keep_alive_timeout=)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def cli_version
|
117
|
+
{ :cli_version => Papertrail::VERSION }
|
116
118
|
end
|
117
119
|
|
118
120
|
def ssl_verify_mode
|
data/papertrail.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
## If your rubyforge_project name is different, then edit it and comment out
|
10
10
|
## the sub! line in the Rakefile
|
11
11
|
s.name = 'papertrail'
|
12
|
-
s.version = '0.
|
13
|
-
s.date = '
|
12
|
+
s.version = '0.11.1'
|
13
|
+
s.date = '2021-05-27'
|
14
14
|
s.rubyforge_project = 'papertrail'
|
15
15
|
|
16
16
|
## Make sure your summary is short. The description may be as long
|
@@ -55,6 +55,10 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.add_development_dependency('minitest')
|
56
56
|
s.add_development_dependency('mocha')
|
57
57
|
|
58
|
+
if RUBY_VERSION > '1.9'
|
59
|
+
s.add_development_dependency('addressable', '~> 2.4.0')
|
60
|
+
s.add_development_dependency('webmock', '~> 1.24.6')
|
61
|
+
end
|
58
62
|
if RUBY_VERSION > '2.2.4' # ruby_dep dependency
|
59
63
|
s.add_development_dependency('guard', '~> 2.14.0')
|
60
64
|
s.add_development_dependency('guard-minitest', '~> 2.4.6')
|
@@ -93,6 +97,7 @@ Gem::Specification.new do |s|
|
|
93
97
|
lib/papertrail/search_result.rb
|
94
98
|
papertrail.gemspec
|
95
99
|
test/connection_test.rb
|
100
|
+
test/http_client_test.rb
|
96
101
|
test/search_query_test.rb
|
97
102
|
test/test_helper.rb
|
98
103
|
]
|
data/test/connection_test.rb
CHANGED
@@ -4,6 +4,17 @@ class ConnectionTest < Minitest::Test
|
|
4
4
|
let(:connection_options) { { :token => 'dummy' } }
|
5
5
|
let(:connection) { Papertrail::Connection.new(connection_options) }
|
6
6
|
|
7
|
+
def test_start_finish
|
8
|
+
assert_same connection, connection.start
|
9
|
+
assert_nil connection.finish
|
10
|
+
|
11
|
+
block_args = nil
|
12
|
+
connection.start {|*args| block_args = args}
|
13
|
+
assert_equal [connection], block_args
|
14
|
+
|
15
|
+
assert_raises { connection.finish }
|
16
|
+
end
|
17
|
+
|
7
18
|
def test_each_event
|
8
19
|
skip
|
9
20
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HttpClientTest < Minitest::Test
|
4
|
+
let(:http) { Papertrail::HttpClient.new({}) }
|
5
|
+
describe 'http methods' do
|
6
|
+
def test_start_finish
|
7
|
+
assert_same http, http.start
|
8
|
+
assert_nil http.finish
|
9
|
+
|
10
|
+
block_args = nil
|
11
|
+
http.start {|*args| block_args = args}
|
12
|
+
assert_equal [http], block_args
|
13
|
+
|
14
|
+
assert_raises { http.finish }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_cli_version_present_in_http_methods
|
18
|
+
return if RUBY_VERSION < '2.0'
|
19
|
+
# if webmock.disable_net_connect intervenes with a stack trace,
|
20
|
+
# we know the http methods are not sending cli_version in params
|
21
|
+
stub_request(:get, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
|
22
|
+
http.get('some-path')
|
23
|
+
|
24
|
+
stub_request(:post, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
|
25
|
+
http.post('some-path', {})
|
26
|
+
|
27
|
+
|
28
|
+
stub_request(:put, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
|
29
|
+
http.put('some-path', {})
|
30
|
+
|
31
|
+
stub_request(:delete, "https://papertrailapp.com/api/v1/some-path?cli_version=#{Papertrail::VERSION}&").to_return(:status => 200, :body => '', :headers => {})
|
32
|
+
http.delete('some-path')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'build nested query' do
|
37
|
+
def test_value_accepts_hash
|
38
|
+
assert_equal(http.send(:build_nested_query, {}), "")
|
39
|
+
assert_equal(http.send(:build_nested_query, {:a => 1}), "a=1")
|
40
|
+
end
|
41
|
+
def test_value_accepts_array
|
42
|
+
assert_equal(http.send(:build_nested_query, []), "")
|
43
|
+
assert_equal(http.send(:build_nested_query, [1,2]), "%5B%5D=1&%5B%5D=2")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
gem "minitest"
|
1
2
|
require 'minitest/autorun'
|
2
3
|
require 'minitest/pride' # Color!
|
3
|
-
require 'mocha/
|
4
|
+
require 'mocha/minitest'
|
5
|
+
unless RUBY_VERSION < '1.9'
|
6
|
+
require 'webmock/minitest'
|
7
|
+
WebMock.disable_net_connect!
|
8
|
+
end
|
4
9
|
|
5
10
|
require 'pp'
|
6
11
|
|
@@ -8,4 +13,4 @@ class Minitest::Test
|
|
8
13
|
extend Minitest::Spec::DSL # Add let blocks
|
9
14
|
end
|
10
15
|
|
11
|
-
require './lib/papertrail'
|
16
|
+
require './lib/papertrail'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papertrail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Papertrail
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: addressable
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.4.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.4.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.24.6
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.24.6
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: guard
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,13 +178,14 @@ files:
|
|
150
178
|
- lib/papertrail/search_result.rb
|
151
179
|
- papertrail.gemspec
|
152
180
|
- test/connection_test.rb
|
181
|
+
- test/http_client_test.rb
|
153
182
|
- test/search_query_test.rb
|
154
183
|
- test/test_helper.rb
|
155
184
|
homepage: http://github.com/papertrail/papertrail-cli
|
156
185
|
licenses:
|
157
186
|
- MIT
|
158
187
|
metadata: {}
|
159
|
-
post_install_message:
|
188
|
+
post_install_message:
|
160
189
|
rdoc_options:
|
161
190
|
- "--charset=UTF-8"
|
162
191
|
require_paths:
|
@@ -172,9 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
201
|
- !ruby/object:Gem::Version
|
173
202
|
version: '0'
|
174
203
|
requirements: []
|
175
|
-
|
176
|
-
|
177
|
-
signing_key:
|
204
|
+
rubygems_version: 3.1.6
|
205
|
+
signing_key:
|
178
206
|
specification_version: 2
|
179
207
|
summary: Command-line client for Papertrail hosted log management service.
|
180
208
|
test_files:
|