papertrail-cli 0.8.2 → 0.8.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/Rakefile CHANGED
@@ -17,8 +17,7 @@ def module_name
17
17
  end
18
18
 
19
19
  def version
20
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
21
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
20
+ '0.8.3'
22
21
  end
23
22
 
24
23
  def date
@@ -41,49 +40,6 @@ def replace_header(head, header_name)
41
40
  head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
42
41
  end
43
42
 
44
- #############################################################################
45
- #
46
- # Standard tasks
47
- #
48
- #############################################################################
49
-
50
- task :default => :test
51
-
52
- require 'rake/testtask'
53
- Rake::TestTask.new(:test) do |test|
54
- test.libs << 'lib' << 'test'
55
- test.pattern = 'test/**/test_*.rb'
56
- test.verbose = true
57
- end
58
-
59
- desc "Generate RCov test coverage and open in your browser"
60
- task :coverage do
61
- require 'rcov'
62
- sh "rm -fr coverage"
63
- sh "rcov test/test_*.rb"
64
- sh "open coverage/index.html"
65
- end
66
-
67
- require 'rake/rdoctask'
68
- Rake::RDocTask.new do |rdoc|
69
- rdoc.rdoc_dir = 'rdoc'
70
- rdoc.title = "#{name} #{version}"
71
- rdoc.rdoc_files.include('README*')
72
- rdoc.rdoc_files.include('lib/**/*.rb')
73
- end
74
-
75
- desc "Open an irb session preloaded with this library"
76
- task :console do
77
- sh "irb -rubygems -r ./lib/#{name}.rb"
78
- end
79
-
80
- #############################################################################
81
- #
82
- # Custom tasks (add your own tasks here)
83
- #
84
- #############################################################################
85
-
86
-
87
43
 
88
44
  #############################################################################
89
45
  #
@@ -112,7 +68,7 @@ task :build => :gemspec do
112
68
  end
113
69
 
114
70
  desc "Generate #{gemspec_file}"
115
- task :gemspec => :validate do
71
+ task :gemspec do
116
72
  # read spec file and split out manifest section
117
73
  spec = File.read(gemspec_file)
118
74
  head, manifest, tail = spec.split(" # = MANIFEST =\n")
@@ -139,16 +95,3 @@ task :gemspec => :validate do
139
95
  File.open(gemspec_file, 'w') { |io| io.write(spec) }
140
96
  puts "Updated #{gemspec_file}"
141
97
  end
142
-
143
- desc "Validate #{gemspec_file}"
144
- task :validate do
145
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{module_name}"]
146
- unless libfiles.empty?
147
- puts "Directory `lib` should only contain a `#{name}.rb` file and `#{module_name}` dir."
148
- exit!
149
- end
150
- unless Dir['VERSION*'].empty?
151
- puts "A `VERSION` file at root level violates Gem best practices."
152
- exit!
153
- end
154
- end
@@ -13,67 +13,34 @@ 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-cli'
16
- s.version = '0.8.2'
17
- s.date = '2011-11-25'
16
+ s.version = '0.8.3'
17
+ s.date = '2012-02-11'
18
18
  s.rubyforge_project = 'papertrail-cli'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
21
21
  ## as you like.
22
- s.summary = "Command-line client for Papertrail hosted log management service."
23
- s.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)."
22
+ s.summary = "Placeholder gem to point to new papertrail gem"
23
+ s.description = "Placeholder gem to point to new papertrail gem."
24
24
 
25
25
  ## List the primary authors. If there are a bunch of authors, it's probably
26
26
  ## better to set the email to an email list or something. If you don't have
27
27
  ## a custom homepage, consider using your GitHub URL or the like.
28
28
  s.authors = ['Papertrail']
29
- s.email = 'troy@sevenscale.com'
30
- s.homepage = 'http://github.com/papertrail/papertrail-cli'
31
-
32
- ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
- ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
- s.require_paths = %w[lib]
35
-
36
- ## This sections is only necessary if you have C extensions.
37
- # s.require_paths << 'ext'
38
- # s.extensions = %w[ext/extconf.rb]
39
-
40
- ## If your gem includes any executables, list them here.
41
- s.executables = ["papertrail"]
42
- s.default_executable = 'papertrail'
43
-
44
- ## Specify any RDoc options here. You'll want to add your README and
45
- ## LICENSE files to the extra_rdoc_files list.
46
- s.rdoc_options = ["--charset=UTF-8"]
47
- # s.extra_rdoc_files = %w[README LICENSE]
48
- s.extra_rdoc_files = []
29
+ s.email = 'eric@sevenscale.com'
30
+ s.homepage = 'http://github.com/papertrail/papertrail-cli-gem'
49
31
 
50
32
  ## List your runtime dependencies here. Runtime dependencies are those
51
33
  ## that are needed for an end user to actually USE your code.
52
- s.add_dependency('yajl-ruby')
53
- s.add_dependency('faraday', [ '~> 0.6' ])
54
- s.add_dependency('faraday-stack', [ '~> 0.1' ])
55
-
56
- ## List your development dependencies here. Development dependencies are
57
- ## those that are only needed during development
58
- # s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
34
+ s.add_dependency('papertrail', [ '~> 0.8' ])
59
35
 
60
36
  ## Leave this section as-is. It will be automatically generated from the
61
37
  ## contents of your Git repository via the gemspec task. DO NOT REMOVE
62
38
  ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
63
39
  # = MANIFEST =
64
40
  s.files = %w[
65
- Gemfile
66
- README.md
67
41
  Rakefile
68
- bin/papertrail
69
- examples/papertrail.yml.example
70
- lib/papertrail-cli.rb
71
- lib/papertrail/search_client.rb
72
42
  papertrail-cli.gemspec
73
43
  ]
74
44
  # = MANIFEST =
75
45
 
76
- ## Test files will be grabbed from the file list. Make sure the path glob
77
- ## matches what you actually use.
78
- s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
79
46
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 2
9
- version: 0.8.2
8
+ - 3
9
+ version: 0.8.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Papertrail
@@ -14,71 +14,40 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-11-25 00:00:00 -08:00
18
- default_executable: papertrail
17
+ date: 2012-02-11 00:00:00 -08:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: yajl-ruby
21
+ name: papertrail
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :runtime
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: faraday
34
- prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
24
  requirements:
37
25
  - - ~>
38
26
  - !ruby/object:Gem::Version
39
27
  segments:
40
28
  - 0
41
- - 6
42
- version: "0.6"
29
+ - 8
30
+ version: "0.8"
43
31
  type: :runtime
44
- version_requirements: *id002
45
- - !ruby/object:Gem::Dependency
46
- name: faraday-stack
47
- prerelease: false
48
- requirement: &id003 !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ~>
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- - 1
55
- version: "0.1"
56
- type: :runtime
57
- version_requirements: *id003
58
- 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).
59
- email: troy@sevenscale.com
60
- executables:
61
- - papertrail
32
+ version_requirements: *id001
33
+ description: Placeholder gem to point to new papertrail gem.
34
+ email: eric@sevenscale.com
35
+ executables: []
36
+
62
37
  extensions: []
63
38
 
64
39
  extra_rdoc_files: []
65
40
 
66
41
  files:
67
- - Gemfile
68
- - README.md
69
42
  - Rakefile
70
- - bin/papertrail
71
- - examples/papertrail.yml.example
72
- - lib/papertrail-cli.rb
73
- - lib/papertrail/search_client.rb
74
43
  - papertrail-cli.gemspec
75
44
  has_rdoc: true
76
- homepage: http://github.com/papertrail/papertrail-cli
45
+ homepage: http://github.com/papertrail/papertrail-cli-gem
77
46
  licenses: []
78
47
 
79
48
  post_install_message:
80
- rdoc_options:
81
- - --charset=UTF-8
49
+ rdoc_options: []
50
+
82
51
  require_paths:
83
52
  - lib
84
53
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -101,6 +70,6 @@ rubyforge_project: papertrail-cli
101
70
  rubygems_version: 1.3.6
102
71
  signing_key:
103
72
  specification_version: 2
104
- summary: Command-line client for Papertrail hosted log management service.
73
+ summary: Placeholder gem to point to new papertrail gem
105
74
  test_files: []
106
75
 
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'rake', '0.8.7'
4
-
5
- gemspec
data/README.md DELETED
@@ -1,131 +0,0 @@
1
- # papertrail Command-line tail & search client for Papertrail log management service
2
-
3
- Small standalone [binary] to retrieve, search, and tail recent app
4
- server log and system syslog messages from [Papertrail].
5
-
6
- Supports optional Boolean search queries and polling for new events
7
- (like "tail -f"). Example:
8
-
9
- papertrail -f "(www OR db) (nginx OR pgsql) -accepted"
10
-
11
- Output is line-buffered so it can be fed into a pipe, like for grep.
12
- See below for colorization setup.
13
-
14
- The [SearchClient] class can be used by other apps to perform one-off
15
- API searches or follow (tail) events matching a given query. Interface
16
- may change.
17
-
18
-
19
- ## Quick Start
20
-
21
- $ [sudo] gem install papertrail-cli
22
- $ echo "token: 123456789012345678901234567890ab" > ~/.papertrail.yml
23
- $ papertrail
24
-
25
- Retrieve token from Papertrail [User Profile].
26
-
27
-
28
- ## Installation
29
-
30
- Install the gem (details on [RubyGems]), which includes a binary called
31
- "papertrail":
32
-
33
- $ [sudo] gem install papertrail-cli
34
-
35
-
36
- ## Configuration
37
-
38
- Create ~/.papertrail.yml containing your API token, or specify the
39
- path to that file with -c. Example (from
40
- examples/papertrail.yml.example):
41
-
42
- token: 123456789012345678901234567890ab
43
-
44
- Retrieve token from Papertrail [User Profile]. For compatibility with
45
- older config files, `username` and `password` keys are also supported.
46
-
47
- You may want to alias "trail" to "papertrail", like:
48
-
49
- echo "alias trail=papertrail" >> ~/.bashrc
50
-
51
-
52
- ## Usage & Examples
53
-
54
- $ papertrail -h
55
- papertrail - command-line tail and search for Papertrail log management service
56
- -h, --help Show usage
57
- -f, --follow Continue running and print new events (off)
58
- -d, --delay SECONDS Delay between refresh (3)
59
- -c, --configfile PATH Path to config (~/.papertrail.yml)
60
-
61
- Usage: papertrail [-f] [-d seconds] [-c /path/to/papertrail.yml] [query]
62
-
63
- Examples:
64
- papertrail -f
65
- papertrail something
66
- papertrail 1.2.3 Failure
67
- papertrail -f "(www OR db) (nginx OR pgsql) -accepted"
68
- papertrail -f -d 10 "ns1 OR 'connection refused'"
69
-
70
- More: http://papertrailapp.com/
71
-
72
-
73
- ## Colors
74
-
75
- Pipe through [colortail] or [MultiTail]. We recommend colortail:
76
-
77
- $ sudo gem install colortail
78
-
79
- Save [colortailrc] as `~/.colortailrc` and edit it to enable:
80
-
81
- $ papertrail -f -d 5 | colortail -g papertrail
82
-
83
- ### Shorthand
84
-
85
- If you're using bash, create a function that accepts arguments, then
86
- invoke `pt` with optional search operators:
87
-
88
- $ function pt() { papertrail -f -d 5 $_ | colortail -g papertrail }
89
- $ pt 1.2.3 Failure
90
-
91
- Add the function line to your `~/.bashrc`.
92
-
93
- ### Advanced
94
-
95
- For complete control, pipe through anything capable of inserting ANSI
96
- control characters. Here's an example that colorizes 3 fields separately
97
- - the first 15 characters for the date, a word for the hostname, and a
98
- word for the program name:
99
-
100
- $ papertrail | perl -pe 's/^(.{15})(.)([\S]+)(.)([\S]+)/\e[1;31;43m\1\e[0m\2\e[1;31;43m\3\e[0m\4\e[1;31;43m\5\e[0m/g'
101
-
102
- the "1;31;43" are bold (1), foreground red (31), background yellow (43),
103
- and can be any ANSI [escape characters].
104
-
105
-
106
- ## Contribute
107
-
108
- Bug report:
109
-
110
- 1. See whether the issue has already been reported:
111
- http://github.com/papertrail/papertrail-cli/issues/
112
- 2. If you don't find one, create an issue with a repro case.
113
-
114
- Enhancement or fix:
115
-
116
- 1. Fork the project:
117
- http://github.com/papertrail/papertrail-cli
118
- 2. Make your changes with tests.
119
- 3. Commit the changes without changing the Rakefile or other files unrelated
120
- to your enhancement.
121
- 4. Send a pull request.
122
-
123
- [binary]: https://github.com/papertrail/papertrail-cli/blob/master/bin/papertrail
124
- [Papertrail]: http://papertrailapp.com/
125
- [SearchClient]: https://github.com/papertrail/papertrail-cli/blob/master/lib/papertrail/search_client.rb
126
- [User Profile]: https://papertrailapp.com/user/edit
127
- [RubyGems]: https://rubygems.org/gems/papertrail-cli
128
- [colortail]: http://rubydoc.info/gems/colortail
129
- [colortailrc]: https://github.com/papertrail/papertrail-cli/wiki/colortailrc
130
- [MultiTail]: http://www.vanheusden.com/multitail/index.html
131
- [escape characters]: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'yaml'
5
-
6
- require 'papertrail-cli'
7
-
8
- class PapertrailSearch
9
- def run
10
- options = {
11
- :configfile => File.expand_path('~/.papertrail.yml'),
12
- :delay => 10,
13
- :follow => false
14
- }
15
-
16
- OptionParser.new do |opts|
17
- opts.banner = "papertrail - command-line tail and search for Papertrail log management service"
18
-
19
- opts.on("-h", "--help", "Show usage") do |v|
20
- puts opts
21
- exit
22
- end
23
- opts.on("-f", "--follow", "Continue running and print new events (off)") do |v|
24
- options[:follow] = true
25
- end
26
- opts.on("-d", "--delay SECONDS", "Delay between refresh (3)") do |v|
27
- options[:delay] = v.to_i
28
- end
29
- opts.on("-c", "--configfile PATH", "Path to config (~/.papertrail.yml)") do |v|
30
- options[:configfile] = File.expand_path(v)
31
- end
32
-
33
- opts.separator usage
34
- end.parse!
35
-
36
- credentials = open(options[:configfile]) do |f|
37
- YAML.load(f)
38
- end
39
-
40
- if credentials['token']
41
- client = Papertrail::SearchClient.new(:token => credentials['token'])
42
- else
43
- client = Papertrail::SearchClient.new(:username => credentials['username'], :password => credentials['password'])
44
- end
45
-
46
- search_and_print(client)
47
-
48
- if options[:follow]
49
- loop do
50
- sleep options[:delay]
51
- search_and_print(client)
52
- end
53
- end
54
- end
55
-
56
- def search_and_print(client)
57
- events = client.search(ARGV[0])
58
- return unless events
59
-
60
- Papertrail::SearchClient.format_events(events) do |e|
61
- puts e
62
- $stdout.flush
63
- end
64
- end
65
-
66
- def usage
67
- <<EOF
68
-
69
- Usage: papertrail [-f] [-d seconds] [-c /path/to/papertrail.yml] [query]
70
-
71
- Examples:
72
- papertrail -f
73
- papertrail something
74
- papertrail 1.2.3 Failure
75
- papertrail -f "(www OR db) (nginx OR pgsql) -accepted"
76
- papertrail -f -d 10 "ns1 OR 'connection refused'"
77
-
78
- More: https://papertrailapp.com/
79
-
80
- EOF
81
- end
82
- end
83
-
84
- begin
85
- PapertrailSearch.new.run
86
- rescue Interrupt
87
- exit(0)
88
- end
@@ -1 +0,0 @@
1
- token: 123456789012345678901234567890ab
@@ -1,5 +0,0 @@
1
- module PapertrailCli
2
- VERSION = "0.8.2"
3
- end
4
-
5
- require 'papertrail/search_client'
@@ -1,60 +0,0 @@
1
- require 'faraday'
2
- require 'time'
3
- require 'openssl'
4
- require 'faraday_stack'
5
-
6
- module Papertrail
7
- class SearchClient
8
- def initialize(options)
9
- ssl_options = { :verify => OpenSSL::SSL::VERIFY_PEER }
10
-
11
- # Make Ubuntu OpenSSL work
12
- #
13
- # From: https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/396818
14
- # "[OpenSSL] does not presume to select a set of CAs by default."
15
- if File.file?('/etc/ssl/certs/ca-certificates.crt')
16
- ssl_options[:ca_file] = '/etc/ssl/certs/ca-certificates.crt'
17
- end
18
-
19
- @conn = Faraday::Connection.new(:url => 'https://papertrailapp.com', :ssl => ssl_options) do |builder|
20
- builder.adapter Faraday.default_adapter
21
- builder.use FaradayStack::ResponseJSON
22
- end.tap do |conn|
23
- if options[:username] && options[:password]
24
- conn.basic_auth(options[:username], options[:password])
25
- else
26
- conn.headers['X-Papertrail-Token'] = options[:token]
27
- end
28
- end
29
-
30
- @max_id_seen = {}
31
- end
32
-
33
- # search for all events or a specific query, defaulting to all events since
34
- # last result set (call with since=0 for all).
35
- def search(q = nil, since = nil)
36
- response = @conn.get('/api/v1/events/search.json') do |r|
37
- r.params = params_for_query(q, since)
38
- end
39
-
40
- if response.body
41
- @max_id_seen[q] = response.body['max_id']
42
- response.body['events']
43
- end
44
- end
45
-
46
- def params_for_query(q = nil, since = nil)
47
- params = {}
48
- params[:q] = q if q
49
- params[:min_id] = @max_id_seen[q] if @max_id_seen[q]
50
- params[:min_id] = since if since
51
- params
52
- end
53
-
54
- def self.format_events(events, &block)
55
- events.each do |event|
56
- yield "#{Time.parse(event['received_at']).strftime('%b %e %X')} #{event['hostname']} #{event['program']} #{event['message']}"
57
- end
58
- end
59
- end
60
- end