apache_log-parser 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/apache_log-parser.gemspec +23 -0
- data/lib/apache_log/parser.rb +18 -0
- data/lib/apache_log/parser/combined.rb +53 -0
- data/lib/apache_log/parser/common.rb +47 -0
- data/lib/apache_log/parser/format.rb +32 -0
- data/lib/apache_log/parser/version.rb +5 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 909728a9cf9d9f8fe6f3a5dc600da0f69a964759
|
4
|
+
data.tar.gz: 16d92e4ce7963c67a22cd92ead416d59e65ff3b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 947dfe5dd1af740c8ed4ab20aeaca12ce547e4084bca890280a8ad90a209613761d25263fc13bd96648d371ef2743495c72a5b6f882cc5b184a529d0a76538de
|
7
|
+
data.tar.gz: 78cf579ef4fd553a0d6a6d6252af4c1511df5acd9871cda9f281c833445717a66f41e4a90765788a7741d918b9437ed5de70279a07bb5e3e727574e9b3ec6fec
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
bin/
|
24
|
+
apache_log-parser-*
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yuichi Takada
|
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,40 @@
|
|
1
|
+
# ApacheLog::Parser
|
2
|
+
|
3
|
+
Gem to parse popular format apache log files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'apache_log-parser'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install apache_log-parser
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'apache_log/parser'
|
23
|
+
|
24
|
+
parser = ApacheLog::Parser.getParser(format)
|
25
|
+
entity = []
|
26
|
+
|
27
|
+
File.foreach(logfile) do |line|
|
28
|
+
entity << parser.parse(line.chomp)
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
The format parameter must be 'common' or 'combined'.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/takady/apache_log-parser/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'apache_log/parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "apache_log-parser"
|
8
|
+
spec.version = ApacheLog::Parser::VERSION
|
9
|
+
spec.authors = ["Yuichi Takada"]
|
10
|
+
spec.email = ["takadyy@gmail.com"]
|
11
|
+
spec.summary = "Gem to parse popular format apache log files."
|
12
|
+
spec.description = "You can parse common or combined format log."
|
13
|
+
spec.homepage = "https://github.com/takady/apache_log-parser"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "apache_log/parser/version"
|
2
|
+
require "apache_log/parser/common"
|
3
|
+
require "apache_log/parser/combined"
|
4
|
+
|
5
|
+
module ApacheLog
|
6
|
+
module Parser
|
7
|
+
def self.getParser(format)
|
8
|
+
case format
|
9
|
+
when 'common'
|
10
|
+
ApacheLog::Parser::Common
|
11
|
+
when 'combined'
|
12
|
+
ApacheLog::Parser::Combined
|
13
|
+
else
|
14
|
+
raise "format error\n no such format: <#{format}> \n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "apache_log/parser/format"
|
2
|
+
|
3
|
+
module ApacheLog
|
4
|
+
module Parser
|
5
|
+
class Combined < Format
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(line)
|
10
|
+
match = log_pattern.match(line)
|
11
|
+
raise "parse error\n at line: <#{line}> \n" if match.nil?
|
12
|
+
|
13
|
+
columns = match.to_a.values_at(1..9)
|
14
|
+
{
|
15
|
+
remote_host: columns[0],
|
16
|
+
identity_check: columns[1],
|
17
|
+
user: columns[2],
|
18
|
+
datetime: to_datetime(columns[3]),
|
19
|
+
request: parse_request(columns[4]),
|
20
|
+
status: columns[5],
|
21
|
+
size: columns[6],
|
22
|
+
referer: columns[7],
|
23
|
+
user_agent: columns[8],
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.log_pattern
|
28
|
+
/^
|
29
|
+
(\S+) # remote_host
|
30
|
+
\s+
|
31
|
+
(\S+) # identity_check
|
32
|
+
\s+
|
33
|
+
(\S+) # user
|
34
|
+
\s+
|
35
|
+
\[ (\d{2}\/.*?\d{4}:\d{2}:\d{2}:\d{2}\s.*?) \] # date
|
36
|
+
\s+
|
37
|
+
" (.*?\s.*?\s.*?) " # request
|
38
|
+
\s+
|
39
|
+
(\S+) # status
|
40
|
+
\s+
|
41
|
+
(\S+) # size
|
42
|
+
\s+
|
43
|
+
" (.*?) " # referer
|
44
|
+
\s+
|
45
|
+
" (.*?) " # user_agent
|
46
|
+
$/x
|
47
|
+
end
|
48
|
+
|
49
|
+
private_class_method :log_pattern
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "apache_log/parser/format"
|
2
|
+
|
3
|
+
module ApacheLog
|
4
|
+
module Parser
|
5
|
+
class Common < Format
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(line)
|
10
|
+
match = log_pattern.match(line)
|
11
|
+
raise "parse error\n at line: <#{line}> \n" if match.nil?
|
12
|
+
|
13
|
+
columns = match.to_a.values_at(1..7)
|
14
|
+
{
|
15
|
+
remote_host: columns[0],
|
16
|
+
identity_check: columns[1],
|
17
|
+
user: columns[2],
|
18
|
+
datetime: to_datetime(columns[3]),
|
19
|
+
request: parse_request(columns[4]),
|
20
|
+
status: columns[5],
|
21
|
+
size: columns[6],
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.log_pattern
|
26
|
+
/^
|
27
|
+
(\S+) # remote_host
|
28
|
+
\s+
|
29
|
+
(\S+) # identity_check
|
30
|
+
\s+
|
31
|
+
(\S+) # user
|
32
|
+
\s+
|
33
|
+
\[ (\d{2}\/.*?\d{4}:\d{2}:\d{2}:\d{2}\s.*?) \] # date
|
34
|
+
\s+
|
35
|
+
" (.*?\s.*?\s.*?) " # request
|
36
|
+
\s+
|
37
|
+
(\S+) # status
|
38
|
+
\s+
|
39
|
+
(\S+) # size
|
40
|
+
$/x
|
41
|
+
end
|
42
|
+
|
43
|
+
private_class_method :log_pattern
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module ApacheLog
|
4
|
+
module Parser
|
5
|
+
class Format
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(line)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.log_pattern
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.to_datetime(str)
|
16
|
+
DateTime.strptime( str, '%d/%b/%Y:%T %z')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse_request(str)
|
20
|
+
method, path, protocol = str.split
|
21
|
+
{
|
22
|
+
method: method,
|
23
|
+
path: path,
|
24
|
+
protocol: protocol,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private_class_method :to_datetime, :parse_request
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apache_log-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuichi Takada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-14 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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
|
+
description: You can parse common or combined format log.
|
42
|
+
email:
|
43
|
+
- takadyy@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- apache_log-parser.gemspec
|
54
|
+
- lib/apache_log/parser.rb
|
55
|
+
- lib/apache_log/parser/combined.rb
|
56
|
+
- lib/apache_log/parser/common.rb
|
57
|
+
- lib/apache_log/parser/format.rb
|
58
|
+
- lib/apache_log/parser/version.rb
|
59
|
+
homepage: https://github.com/takady/apache_log-parser
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Gem to parse popular format apache log files.
|
83
|
+
test_files: []
|