papertrail 0.9.9 → 0.9.10

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/README.md CHANGED
@@ -154,6 +154,25 @@ example, to search for `-whatever`, run:
154
154
 
155
155
  papertrail -- -whatever
156
156
 
157
+ ### Quoted phrases
158
+
159
+ Because the Unix shell parses and strips one set of quotes around a
160
+ phrase, to search for a phrase, wrap the string in both single-quotes
161
+ and double-quotes. For example:
162
+
163
+ papertrail -f '"Connection reset by peer"'
164
+
165
+ Use one set of double-quotes and one set of single-quotes. The order
166
+ does not matter as long as the pairs are consistent.
167
+
168
+ Note that many phrases are unique enough that searching for the
169
+ words yields the same results as searching for the quoted phrase. As a
170
+ result, quoting strings twice is often not actually necessary. For
171
+ example, these two searches are likely to yield the same log messages,
172
+ even though one is for 4 words (AND) while the other is for a phrase:
173
+
174
+ papertrail -f Connection reset by peer
175
+ papertrail -f '"Connection reset by peer"'
157
176
 
158
177
  ## Add/Remove Systems, Create Group, Join Group
159
178
 
data/Rakefile CHANGED
@@ -64,7 +64,7 @@ task :coverage do
64
64
  sh "open coverage/index.html"
65
65
  end
66
66
 
67
- require 'rake/rdoctask'
67
+ require 'rdoc/task'
68
68
  Rake::RDocTask.new do |rdoc|
69
69
  rdoc.rdoc_dir = 'rdoc'
70
70
  rdoc.title = "#{name} #{version}"
@@ -20,6 +20,7 @@ module Papertrail
20
20
  }
21
21
 
22
22
  @query_options = {}
23
+ @query = nil
23
24
  end
24
25
 
25
26
  def run
@@ -50,6 +51,9 @@ module Papertrail
50
51
  opts.on("-g", "--group GROUP", "Group to search") do |v|
51
52
  options[:group] = v
52
53
  end
54
+ opts.on("-S", "--search SEARCH", "Saved search to search") do |v|
55
+ options[:search] = v
56
+ end
53
57
  opts.on("-j", "--json", "Output raw json data") do |v|
54
58
  options[:json] = true
55
59
  end
@@ -67,6 +71,10 @@ module Papertrail
67
71
  configfile_options = load_configfile(options[:configfile])
68
72
  options.merge!(configfile_options)
69
73
  end
74
+
75
+ unless options[:token]
76
+ abort 'Authentication token not found. Set config file "token" attribute or PAPERTRAIL_API_TOKEN.'
77
+ end
70
78
 
71
79
  @connection = Papertrail::Connection.new(options)
72
80
 
@@ -84,8 +92,20 @@ module Papertrail
84
92
  end
85
93
  end
86
94
 
95
+ if options[:search]
96
+ search = connection.find_search(options[:search], query_options[:group_id])
97
+ unless search
98
+ abort "Search \"#{options[:search]}\" not found"
99
+ end
100
+
101
+ query_options[:group_id] ||= search['group_id']
102
+ @query = search['query']
103
+ end
104
+
105
+ @query ||= ARGV[0]
106
+
87
107
  if options[:follow]
88
- search_query = connection.query(ARGV[0], query_options)
108
+ search_query = connection.query(@query, query_options)
89
109
 
90
110
  loop do
91
111
  display_results(search_query.search)
@@ -95,7 +115,7 @@ module Papertrail
95
115
  query_time_range
96
116
  else
97
117
  set_min_max_time!(options, query_options)
98
- search_query = connection.query(ARGV[0], query_options)
118
+ search_query = connection.query(@query, query_options)
99
119
  display_results(search_query.search)
100
120
  end
101
121
  end
@@ -107,7 +127,7 @@ module Papertrail
107
127
  max_time = parse_time(options[:max_time])
108
128
  end
109
129
 
110
- search_results = connection.query(ARGV[0], query_options.merge(:min_time => min_time.to_i, :tail => false)).search
130
+ search_results = connection.query(@query, query_options.merge(:min_time => min_time.to_i, :tail => false)).search
111
131
 
112
132
  loop do
113
133
  search_results.events.each do |event|
@@ -133,7 +153,7 @@ module Papertrail
133
153
  end
134
154
 
135
155
  # Perform the next search
136
- search_results = connection.query(ARGV[0], query_options.merge(:min_id => search_results.max_id, :tail => false)).search
156
+ search_results = connection.query(@query, query_options.merge(:min_id => search_results.max_id, :tail => false)).search
137
157
  end
138
158
  end
139
159
 
@@ -154,7 +174,8 @@ module Papertrail
154
174
  <<-EOF
155
175
 
156
176
  Usage:
157
- papertrail [-f] [-s system] [-g group] [-d seconds] [-c papertrail.yml] [-j] [--min-time mintime] [--max-time maxtime] [query]
177
+ papertrail [-f] [-s system] [-g group] [-S search] [-d seconds] \
178
+ [-c papertrail.yml] [-j] [--min-time time] [--max-time time] [query]
158
179
 
159
180
  Examples:
160
181
  papertrail -f
@@ -62,6 +62,9 @@ module Papertrail
62
62
  puts "Error: #{e}"
63
63
  puts usage
64
64
  exit 1
65
+ rescue Net::HTTPServerException => e
66
+ output_http_error(e)
67
+ exit 1
65
68
  end
66
69
 
67
70
  def usage
@@ -103,6 +103,9 @@ module Papertrail
103
103
  rescue OptionParser::ParseError => e
104
104
  error(e, true)
105
105
  exit 1
106
+ rescue Net::HTTPServerException => e
107
+ output_http_error(e)
108
+ exit 1
106
109
  end
107
110
 
108
111
  def error(message, try_help = false)
@@ -1,11 +1,14 @@
1
1
  module Papertrail
2
2
  module CliHelpers
3
3
  def find_configfile
4
- if File.exists?(path = File.expand_path('.papertrail.yml'))
5
- return path
6
- end
7
- if File.exists?(path = File.expand_path('~/.papertrail.yml'))
8
- return path
4
+ begin
5
+ if File.exists?(path = File.expand_path('.papertrail.yml'))
6
+ return path
7
+ end
8
+ if File.exists?(path = File.expand_path('~/.papertrail.yml'))
9
+ return path
10
+ end
11
+ rescue ArgumentError => e
9
12
  end
10
13
  end
11
14
 
@@ -32,5 +35,12 @@ module Papertrail
32
35
  raise(ArgumentError, "Could not parse time string '#{tstring}'")
33
36
  end
34
37
 
38
+ def output_http_error(e)
39
+ if e.response && e.response.body
40
+ puts "Error: #{e.response.body}\n\n"
41
+ end
42
+
43
+ puts e
44
+ end
35
45
  end
36
46
  end
@@ -58,6 +58,9 @@ module Papertrail
58
58
  puts "Error: #{e}"
59
59
  puts usage
60
60
  exit 1
61
+ rescue Net::HTTPServerException => e
62
+ output_http_error(e)
63
+ exit 1
61
64
  end
62
65
 
63
66
  def usage
@@ -54,6 +54,9 @@ module Papertrail
54
54
  puts "Error: #{e}"
55
55
  puts usage
56
56
  exit 1
57
+ rescue Net::HTTPServerException => e
58
+ output_http_error(e)
59
+ exit 1
57
60
  end
58
61
 
59
62
  def usage
@@ -49,14 +49,45 @@ module Papertrail
49
49
  find_id_for_item(response.body, name)
50
50
  end
51
51
 
52
- def find_id_for_item(items, name_wanted)
52
+ def find_search(name, group_id = nil)
53
+ response = @connection.get('searches.json')
54
+
55
+ candidates = find_items_by_name(response.body, name)
56
+ return nil if candidates.empty?
57
+
58
+ candidates.each do |item|
59
+ if !group_id || group_id == item['group_id']
60
+ return item
61
+ end
62
+ end
63
+
64
+ return candidates.first
65
+ end
66
+
67
+ def find_items_by_name(items, name_wanted)
68
+ results = []
69
+
53
70
  items.each do |item|
54
- return item['id'] if item['name'] == name_wanted
71
+ results << item if item['name'] == name_wanted
55
72
  end
56
73
 
57
74
  items.each do |item|
58
- return item['id'] if item['name'] =~ /#{Regexp.escape(name_wanted)}/i
75
+ results << item if item['name'] =~ /#{Regexp.escape(name_wanted)}/i
76
+ end
77
+
78
+ results
79
+ end
80
+
81
+ def find_item_by_name(items, name_wanted)
82
+ find_items_by_name(items, name_wanted).first
83
+ end
84
+
85
+ def find_id_for_item(items, name_wanted)
86
+ item = find_item_by_name(items, name_wanted)
87
+ if item
88
+ return item['id']
59
89
  end
90
+
60
91
  return nil
61
92
  end
62
93
 
@@ -5,7 +5,7 @@ require 'papertrail/okjson'
5
5
 
6
6
  module Papertrail
7
7
 
8
- # Used because Net::HTTPOK in Ruby 1.8 hasn't method body=
8
+ # Used because Net::HTTPOK in Ruby 1.8 has no body= method
9
9
  class HttpResponse < SimpleDelegator
10
10
 
11
11
  def initialize(response)
@@ -13,7 +13,11 @@ module Papertrail
13
13
  end
14
14
 
15
15
  def body
16
- @body ||= Papertrail::OkJson.decode(__getobj__.body.dup.force_encoding('UTF-8'))
16
+ if __getobj__.body.respond_to?(:force_encoding)
17
+ @body ||= Papertrail::OkJson.decode(__getobj__.body.dup.force_encoding('UTF-8'))
18
+ else
19
+ @body ||= Papertrail::OkJson.decode(__getobj__.body.dup)
20
+ end
17
21
  end
18
22
 
19
23
  end
data/lib/papertrail.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Papertrail
2
- VERSION = "0.9.9"
2
+ VERSION = "0.9.10"
3
3
  end
4
4
 
5
5
  require 'papertrail/connection'
data/papertrail.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'papertrail'
16
- s.version = '0.9.9'
17
- s.date = '2014-04-02'
16
+ s.version = '0.9.10'
17
+ s.date = '2014-06-05'
18
18
  s.rubyforge_project = 'papertrail'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -1,49 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: papertrail
3
- version: !ruby/object:Gem::Version
4
- hash: 41
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.10
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 9
10
- version: 0.9.9
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Papertrail
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2014-04-02 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2014-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chronic
16
+ requirement: !ruby/object:Gem::Requirement
22
17
  none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- prerelease: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :runtime
32
- requirement: *id001
33
- name: chronic
34
- description: Command-line client for Papertrail hosted log management service. Tails and searches app server logs and system syslog. Supports Boolean search and works with grep and pipe output (Unix).
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Command-line client for Papertrail hosted log management service. Tails
31
+ and searches app server logs and system syslog. Supports Boolean search and works
32
+ with grep and pipe output (Unix).
35
33
  email: troy@sevenscale.com
36
- executables:
34
+ executables:
37
35
  - papertrail
38
36
  - papertrail-add-system
39
37
  - papertrail-remove-system
40
38
  - papertrail-add-group
41
39
  - papertrail-join-group
42
40
  extensions: []
43
-
44
41
  extra_rdoc_files: []
45
-
46
- files:
42
+ files:
47
43
  - Gemfile
48
44
  - LICENSE
49
45
  - README.md
@@ -70,36 +66,28 @@ files:
70
66
  - papertrail.gemspec
71
67
  homepage: http://github.com/papertrail/papertrail-cli
72
68
  licenses: []
73
-
74
69
  post_install_message:
75
- rdoc_options:
70
+ rdoc_options:
76
71
  - --charset=UTF-8
77
- require_paths:
72
+ require_paths:
78
73
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
80
75
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
81
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
95
- - 0
96
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
97
86
  requirements: []
98
-
99
87
  rubyforge_project: papertrail
100
- rubygems_version: 1.8.25
88
+ rubygems_version: 1.8.29
101
89
  signing_key:
102
90
  specification_version: 2
103
91
  summary: Command-line client for Papertrail hosted log management service.
104
92
  test_files: []
105
-
93
+ has_rdoc: