logripper 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/bin/logripper +6 -0
- data/lib/logripper.rb +6 -0
- data/lib/logripper/cli.rb +15 -0
- data/lib/logripper/exporter.rb +20 -0
- data/lib/logripper/parser.rb +40 -0
- data/lib/logripper/version.rb +3 -0
- data/logripper.gemspec +26 -0
- data/spec/logripper/exporter_spec.rb +21 -0
- data/spec/logripper/parser_spec.rb +40 -0
- data/spec/spec_helper.rb +17 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be22539ac70f578d1aeea65034a55eccef921202
|
4
|
+
data.tar.gz: 2bce1cf701cb9a30f38abce16f6bbce9c851be21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d33e7358eb569f66a6843fc51cdace37c68a35cbe2a273430babb951575ac3c5c3f2f725e2c3ba00965faed6a30d8d469fd0c1d179f4ed1db1cf1647f75defbc
|
7
|
+
data.tar.gz: c5287fa82bb0cf08ac0a0701be22d618f68834c16018f3fa9e996d42c9decf5d3359f1cf8a2e590410a2efa0329f1b1d8bd21a0d7c2fa343fcb13927d1806cce
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ben Cates
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Logripper
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'logripper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install logripper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/logripper
ADDED
data/lib/logripper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'logripper'
|
3
|
+
|
4
|
+
module Logripper
|
5
|
+
class CLI < Thor
|
6
|
+
package_name 'logripper'
|
7
|
+
|
8
|
+
desc "extract URL LOG", "extracts all lines matching URL from LOG"
|
9
|
+
def extract(url, log)
|
10
|
+
log_file = File.open(log, 'r')
|
11
|
+
parsed_log = Parser.new(log_file).find(url)
|
12
|
+
puts Exporter.new(parsed_log).to_csv
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Logripper
|
4
|
+
class Exporter
|
5
|
+
attr_reader :parsed_log
|
6
|
+
|
7
|
+
def initialize(parsed_log)
|
8
|
+
@parsed_log = parsed_log
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_csv
|
12
|
+
CSV.generate do |csv|
|
13
|
+
csv << parsed_log.first.keys
|
14
|
+
parsed_log.each do |log_entry|
|
15
|
+
csv << log_entry.values
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Logripper
|
2
|
+
class Parser
|
3
|
+
attr_reader :log_file
|
4
|
+
|
5
|
+
def initialize(log_file)
|
6
|
+
@log_file = log_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(url)
|
10
|
+
parsed_lines.find_all do |line|
|
11
|
+
line[:url] == url
|
12
|
+
end.force
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
COMMON_LOG_FORMAT_REGEX = %r{\A
|
18
|
+
(?<ip_address>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})
|
19
|
+
\s-\s-\s
|
20
|
+
\[(?<timestamp>\d{2}/\w{3}/\d{4}:\d{2}:\d{2}:\d{2}\s[+-]\d{4})\]\s
|
21
|
+
"(?<method>[A-Z]+)\s(?<url>.+)\sHTTP/1\.[01]"\s
|
22
|
+
(?<status>\d{3})\s
|
23
|
+
(?<bytes_sent>\d+)\s
|
24
|
+
(["](?<refferer>(\-)|(.+))["])\s
|
25
|
+
(["](?<useragent>.+)["])
|
26
|
+
\Z}x
|
27
|
+
|
28
|
+
def parsed_lines
|
29
|
+
log_file.each_line.lazy.map do |line|
|
30
|
+
parsed_line = COMMON_LOG_FORMAT_REGEX.match(line) or next
|
31
|
+
{
|
32
|
+
timestamp: DateTime.strptime(parsed_line[:timestamp], '%d/%b/%Y:%H:%M:%S %z'),
|
33
|
+
method: parsed_line[:method],
|
34
|
+
url: parsed_line[:url],
|
35
|
+
status: parsed_line[:status].to_i
|
36
|
+
}
|
37
|
+
end.reject(&:nil?)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/logripper.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logripper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "logripper"
|
8
|
+
spec.version = Logripper::VERSION
|
9
|
+
spec.authors = ["Ben Cates"]
|
10
|
+
spec.email = ["ben@ideum.com"]
|
11
|
+
spec.description = %q{Tool for parsing metrics from logs}
|
12
|
+
spec.summary = %q{Tool for parsing metrics from logs}
|
13
|
+
spec.homepage = "https://github.com/ideum/logripper"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
|
25
|
+
spec.add_dependency "thor", "~> 0.18.1"
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'logripper/exporter'
|
3
|
+
|
4
|
+
describe Logripper::Exporter do
|
5
|
+
let(:parsed_log) {
|
6
|
+
[
|
7
|
+
{timestamp: DateTime.new(2013, 1, 1, 0, 0, 0), method: 'GET', url: '/test/1', status: 200},
|
8
|
+
{timestamp: DateTime.new(2013, 1, 1, 0, 5, 0), method: 'GET', url: '/test/2', status: 200},
|
9
|
+
]
|
10
|
+
}
|
11
|
+
|
12
|
+
subject(:exporter) { Logripper::Exporter.new(parsed_log) }
|
13
|
+
|
14
|
+
it "should export a CSV" do
|
15
|
+
exporter.to_csv.should == <<-CSV
|
16
|
+
timestamp,method,url,status
|
17
|
+
2013-01-01T00:00:00+00:00,GET,/test/1,200
|
18
|
+
2013-01-01T00:05:00+00:00,GET,/test/2,200
|
19
|
+
CSV
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'logripper/parser'
|
3
|
+
|
4
|
+
describe Logripper::Parser do
|
5
|
+
let(:log_pseudofile) { StringIO.new(<<-LOG_SNIPPET, 'r') }
|
6
|
+
64.49.91.30 - - [19/Dec/2013:17:12:02 +0000] "GET /alive.txt HTTP/1.1" 200 6 "-" "-"
|
7
|
+
173.163.247.62 - - [19/Dec/2013:17:12:06 +0000] "GET /alive.txt HTTP/1.1" 200 6 "-" "-"
|
8
|
+
54.247.188.179 - - [19/Dec/2013:17:12:22 +0000] "HEAD / HTTP/1.0" 200 0 "-" "NewRelicPinger/1.0 (370512)"
|
9
|
+
LOG_SNIPPET
|
10
|
+
|
11
|
+
let(:malformed_log_pseudofile) { StringIO.new(<<-LOG_SNIPPET, 'r') }
|
12
|
+
64.49.91.30 - - [19/Dec/2013:17:12:02 +0000] "GET /alive.txt HTTP/1.1" 200 6 "-" "-"
|
13
|
+
This is an intentionally malformed row
|
14
|
+
LOG_SNIPPET
|
15
|
+
|
16
|
+
subject(:parser) { Logripper::Parser.new(log_pseudofile) }
|
17
|
+
|
18
|
+
describe '#find' do
|
19
|
+
subject(:results) { parser.find('/alive.txt') }
|
20
|
+
|
21
|
+
it "filters by URL" do
|
22
|
+
results.length.should == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it "handles malformed lines" do
|
26
|
+
expect {
|
27
|
+
Logripper::Parser.new(malformed_log_pseudofile).find('/alive.txt')
|
28
|
+
}.to_not raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'returned info' do
|
32
|
+
subject { results.first }
|
33
|
+
|
34
|
+
its([:timestamp]) { should == DateTime.new(2013, 12, 19, 17, 12, 02) }
|
35
|
+
its([:method]) { should == 'GET' }
|
36
|
+
its([:url]) { should == '/alive.txt' }
|
37
|
+
its([:status]) { should == 200 }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logripper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Cates
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.18.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.18.1
|
69
|
+
description: Tool for parsing metrics from logs
|
70
|
+
email:
|
71
|
+
- ben@ideum.com
|
72
|
+
executables:
|
73
|
+
- logripper
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/logripper
|
84
|
+
- lib/logripper.rb
|
85
|
+
- lib/logripper/cli.rb
|
86
|
+
- lib/logripper/exporter.rb
|
87
|
+
- lib/logripper/parser.rb
|
88
|
+
- lib/logripper/version.rb
|
89
|
+
- logripper.gemspec
|
90
|
+
- spec/logripper/exporter_spec.rb
|
91
|
+
- spec/logripper/parser_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/ideum/logripper
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.0.3
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Tool for parsing metrics from logs
|
117
|
+
test_files:
|
118
|
+
- spec/logripper/exporter_spec.rb
|
119
|
+
- spec/logripper/parser_spec.rb
|
120
|
+
- spec/spec_helper.rb
|