log_analysis 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/log_analysis.rb +29 -0
- data/lib/log_analysis/model/record.rb +84 -0
- data/lib/log_analysis/model/session_identity.rb +8 -0
- data/lib/log_analysis/model/user_identity.rb +13 -0
- data/lib/log_analysis/preprocess.rb +75 -0
- data/lib/log_analysis/session_identification.rb +37 -0
- data/lib/log_analysis/user_identification.rb +15 -0
- data/lib/log_analysis/version.rb +3 -0
- data/log_analysis.gemspec +31 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7fb0868a486b07e30af1c5ce0d53a43bd92989c8c9aab417765363411f8de0b
|
4
|
+
data.tar.gz: 574d9810423c48fc9a51b5ee3b8fc574495578c9a4595582ff34f26b4ed4f9c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6185a37524183582de8a0fabebcb6d9ae32655f4c384c33621414877802d1efbab0bd26310e167428a1803bf81bc4cb7da573cae3047148c4d76a249b84d3708
|
7
|
+
data.tar.gz: 4cb647eaa11f23c0f853942acc2fe361d4ef5b2e27e4d7764228197e6e2174ecb9d599725a069e6bcbd69461b873046f98b3b649f71a3d7cd374f230d1a46f04
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at mictran205@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
log_analysis (0.1.0)
|
5
|
+
activesupport (~> 6.0.3.1)
|
6
|
+
useragent (~> 0.16.10)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.3.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
17
|
+
concurrent-ruby (1.1.6)
|
18
|
+
i18n (1.8.3)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
minitest (5.14.1)
|
21
|
+
rake (12.3.1)
|
22
|
+
thread_safe (0.3.6)
|
23
|
+
tzinfo (1.2.7)
|
24
|
+
thread_safe (~> 0.1)
|
25
|
+
useragent (0.16.10)
|
26
|
+
zeitwerk (2.3.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
log_analysis!
|
33
|
+
rake (~> 12.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Michael Tran
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# LogAnalysis
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/log_analysis`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'log_analysis'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install log_analysis
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/log_analysis. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/log_analysis/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the LogAnalysis project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/log_analysis/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "log_analysis"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/log_analysis.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'log_analysis/version'
|
2
|
+
require 'log_analysis/preprocess'
|
3
|
+
require 'log_analysis/user_identification'
|
4
|
+
require 'log_analysis/session_identification'
|
5
|
+
|
6
|
+
class LogAnalysis
|
7
|
+
class Error < StandardError; end
|
8
|
+
# Your code goes here...
|
9
|
+
|
10
|
+
attr_reader :path, :origin_logs
|
11
|
+
|
12
|
+
def initialize(path, type = nil)
|
13
|
+
@path = path
|
14
|
+
@type = type
|
15
|
+
@origin_logs = PreProcess.input(path, type)
|
16
|
+
end
|
17
|
+
|
18
|
+
def cleaned_data
|
19
|
+
PreProcess.data_cleaning(@origin_logs)
|
20
|
+
end
|
21
|
+
|
22
|
+
def identified_user
|
23
|
+
UserIdentification.execute(cleaned_data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def identified_session
|
27
|
+
SessionIdentification.execute(cleaned_data)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
require 'useragent'
|
3
|
+
require 'log_analysis/model/user_identity'
|
4
|
+
require 'active_support/core_ext/numeric/time'
|
5
|
+
|
6
|
+
class Record
|
7
|
+
attr_accessor :time,
|
8
|
+
:host,
|
9
|
+
:status,
|
10
|
+
:size,
|
11
|
+
:request_length,
|
12
|
+
:req,
|
13
|
+
:method,
|
14
|
+
:uri,
|
15
|
+
:referer,
|
16
|
+
:ua,
|
17
|
+
:reqtime,
|
18
|
+
:runtime,
|
19
|
+
:apptime,
|
20
|
+
:cache,
|
21
|
+
:vhost,
|
22
|
+
:user,
|
23
|
+
:forwardedfor,
|
24
|
+
:forwardedproto
|
25
|
+
|
26
|
+
attr_reader :params
|
27
|
+
|
28
|
+
DATA_TYPE = %w[.txt .json .js .css .jpg .jpeg .gif .woff2 .ico .png .bmp .mp3 .wav .avi .mpeg .vmw .mpg .map .pdf .doc .svg].freeze
|
29
|
+
REGEX_BOT = /facebookexternalhit|Mediapartners-Google|AWS|-|Crawler|spider|Detection/.freeze
|
30
|
+
|
31
|
+
def initialize(params)
|
32
|
+
@params = params
|
33
|
+
record_params.keys.each { |key| instance_variable_set("@#{key}", record_params[key]) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def status_200?
|
37
|
+
status == 200
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_get?
|
41
|
+
method == 'GET'
|
42
|
+
end
|
43
|
+
|
44
|
+
def uri_without_data
|
45
|
+
return false if uri.nil? || uri.end_with?(*DATA_TYPE)
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def robot?
|
51
|
+
ua.bot? || ua.to_s.match?(REGEX_BOT)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def record_params
|
57
|
+
{}.tap do |p|
|
58
|
+
p['time'] = Time.parse(@params['time'].split.first.sub(/:/, ' ')) || nil
|
59
|
+
p['host'] = IPAddr.new(@params['host'])
|
60
|
+
p['status'] = @params['status'].to_i || 0
|
61
|
+
p['size'] = @params['size'].to_i || 0
|
62
|
+
p['request_length'] = @params['request_length'].to_i || 0
|
63
|
+
p['req'] = validate_string(@params['req'])
|
64
|
+
p['method'] = validate_string(@params['method'])
|
65
|
+
p['uri'] = validate_string(@params['uri'])
|
66
|
+
p['referer'] = validate_string(@params['referer'])
|
67
|
+
p['ua'] = UserAgent.parse(@params['ua'])
|
68
|
+
p['reqtime'] = @params['reqtime'].to_f
|
69
|
+
p['runtime'] = @params['runtime'].to_f
|
70
|
+
p['apptime'] = @params['apptime'].to_f
|
71
|
+
p['cache'] = validate_string(@params['cache'])
|
72
|
+
p['vhost'] = validate_string(@params['vhost'])
|
73
|
+
p['user'] = UserIdentity.new(host: IPAddr.new(@params['host']), user_agent: UserAgent.parse(@params['ua']))
|
74
|
+
p['forwardedfor'] = validate_string(@params['forwardedfor'])
|
75
|
+
p['forwardedproto'] = validate_string(@params['forwardedproto'])
|
76
|
+
end
|
77
|
+
rescue IPAddr::InvalidAddressError => e
|
78
|
+
puts e
|
79
|
+
end
|
80
|
+
|
81
|
+
def validate_string(value)
|
82
|
+
value == '-' ? nil : value
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
require 'useragent'
|
3
|
+
|
4
|
+
class UserIdentity
|
5
|
+
attr_accessor :host, :user_agent
|
6
|
+
|
7
|
+
delegate :browser, :version, :os, :platform, :mobile?, :application, :localization, to: :user_agent
|
8
|
+
|
9
|
+
def initialize(params)
|
10
|
+
@host = params[:host]
|
11
|
+
@user_agent = params[:user_agent]
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'log_analysis/model/record'
|
2
|
+
require 'json'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
module PreProcess
|
6
|
+
class Error < StandardError; end
|
7
|
+
# Your code goes here...
|
8
|
+
|
9
|
+
REGEX_KEYS = /(time:| host:| status:| size:| request_length:| req:| method:| uri:| referer:| ua:| reqtime:| runtime:| apptime:| cache:| vhost:| server:| user:| forwardedfor:| forwardedproto:)/.freeze
|
10
|
+
REGEX_NGINX = /\A^(?<host>\S*) (?<identity>\S*) (?<user>\S*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?:\s+\S*)?)?" (?<code>\S*) (?<size>\S*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)"(?:\s+(?<http_x_forwarded_for>\S+))?)?$/.freeze
|
11
|
+
REGEX_APACHE = %r{(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (.{0})- \[([^\]]+?)\] "(GET|POST|PUT|DELETE) ([^\s]+?) (HTTP\/1\.1)" (\d+) (\d+) "-" "(.*)"}.freeze
|
12
|
+
|
13
|
+
CONVERT_RECORD = { 'nginx' => 'convert_nginx_logs', 'apache' => 'convert_apache_logs', 'default' => 'to_records' }.freeze
|
14
|
+
|
15
|
+
def self.input(file_path, type)
|
16
|
+
arr_logs = File.readlines(file_path).each_with_object([]) do |line, arr|
|
17
|
+
preprocess_log = type.nil? ? line.gsub(/[\t]/i, ' ').chomp! : line
|
18
|
+
arr.push(preprocess_log)
|
19
|
+
end
|
20
|
+
|
21
|
+
send(CONVERT_RECORD[type.nil? ? 'nginx' : type], arr_logs)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.data_cleaning(logs)
|
25
|
+
logs.select { |record| record.status_200? && record.method_get? && record.uri_without_data && !record.robot? }
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.to_records(logs)
|
29
|
+
logs.each_with_object([]).with_index do |(log, arrays), i|
|
30
|
+
next if log.nil?
|
31
|
+
|
32
|
+
o = log.split(REGEX_KEYS)
|
33
|
+
o = o.map(&:strip)
|
34
|
+
o.delete('')
|
35
|
+
|
36
|
+
log = o.each_slice(2).to_a.each_with_object({}) do |pair, log_obj|
|
37
|
+
log_obj.merge!(to_json(pair))
|
38
|
+
end
|
39
|
+
|
40
|
+
arrays << Record.new(log)
|
41
|
+
|
42
|
+
puts "#{i}/#{logs.size}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.convert_nginx_logs(logs)
|
47
|
+
logs.each_with_object([]).with_index do |(log, arrays), i|
|
48
|
+
next if log.nil?
|
49
|
+
|
50
|
+
o = log.split(REGEX_NGINX)
|
51
|
+
o.delete('')
|
52
|
+
|
53
|
+
obj = {}.tap do |p|
|
54
|
+
p['host'] = o[0]
|
55
|
+
p['user'] = o[2]
|
56
|
+
p['time'] = o[3]
|
57
|
+
p['method'] = o[4]
|
58
|
+
p['uri'] = o[5]
|
59
|
+
p['status'] = o[6]
|
60
|
+
p['size'] = o[7]
|
61
|
+
p['referer'] = o[8]
|
62
|
+
p['ua'] = o[9]
|
63
|
+
p['forwarded'] = o[10]
|
64
|
+
end
|
65
|
+
|
66
|
+
arrays << Record.new(obj)
|
67
|
+
|
68
|
+
puts "#{i}/#{logs.size}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.to_json(pair)
|
73
|
+
{ pair.first.delete(':') => pair.last }
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'active_support/core_ext/numeric/time'
|
2
|
+
require 'log_analysis/model/session_identity'
|
3
|
+
|
4
|
+
module SessionIdentification
|
5
|
+
MINUTE_THRESHOLD = 10
|
6
|
+
|
7
|
+
class Error < StandardError; end
|
8
|
+
# Your code goes here...
|
9
|
+
|
10
|
+
def self.execute(cleaned_data)
|
11
|
+
session_identity = []
|
12
|
+
cleaned_data.each do |record|
|
13
|
+
isession = session_identity.rindex { |s| s.user.host == record.user.host && s.user.user_agent == record.user.user_agent }
|
14
|
+
|
15
|
+
if isession.present? && validate_time_session(session_identity[isession].records.last.time, record.time)
|
16
|
+
session_identity[isession].records << record
|
17
|
+
else
|
18
|
+
session_identity << SessionIdentity.new(session_identity_params(record))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
session_identity.map { |i| i.records.map(&:uri) }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.session_identity_params(record)
|
28
|
+
{}.tap do |p|
|
29
|
+
p[:user] = record.user
|
30
|
+
p[:records] = [record]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.validate_time_session(last_session_record_time, time)
|
35
|
+
(time - last_session_record_time) / 60 < MINUTE_THRESHOLD
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
require 'log_analysis/model/user_identity'
|
3
|
+
|
4
|
+
module UserIdentification
|
5
|
+
class Error < StandardError; end
|
6
|
+
# Your code goes here...
|
7
|
+
|
8
|
+
def self.execute(cleaned_data)
|
9
|
+
data = cleaned_data.map { |record| [record.host, record.ua.to_s] }.uniq
|
10
|
+
data.each_with_object([]) do |record, arrs|
|
11
|
+
o = UserIdentity.new(host: record.first, user_agent: record.last)
|
12
|
+
arrs << o
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/log_analysis/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "log_analysis"
|
5
|
+
spec.version = LogAnalysis::VERSION
|
6
|
+
spec.authors = ["Michael Tran"]
|
7
|
+
spec.email = ["mictran205@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = 'Log Analysis for thesis Huflit'
|
10
|
+
spec.description = 'Preprocess step of web mining'
|
11
|
+
spec.homepage = 'https://github.com/michaelt0520/log_analysis_thesis'
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/michaelt0520/log_analysis_thesis"
|
19
|
+
|
20
|
+
spec.add_dependency "useragent", "~> 0.16.10"
|
21
|
+
spec.add_dependency "activesupport", "~> 6.0.3.1"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log_analysis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Tran
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: useragent
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.16.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.16.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.0.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.0.3.1
|
41
|
+
description: Preprocess step of web mining
|
42
|
+
email:
|
43
|
+
- mictran205@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".ruby-version"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/log_analysis.rb
|
59
|
+
- lib/log_analysis/model/record.rb
|
60
|
+
- lib/log_analysis/model/session_identity.rb
|
61
|
+
- lib/log_analysis/model/user_identity.rb
|
62
|
+
- lib/log_analysis/preprocess.rb
|
63
|
+
- lib/log_analysis/session_identification.rb
|
64
|
+
- lib/log_analysis/user_identification.rb
|
65
|
+
- lib/log_analysis/version.rb
|
66
|
+
- log_analysis.gemspec
|
67
|
+
homepage: https://github.com/michaelt0520/log_analysis_thesis
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata:
|
71
|
+
homepage_uri: https://github.com/michaelt0520/log_analysis_thesis
|
72
|
+
source_code_uri: https://github.com/michaelt0520/log_analysis_thesis
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.3.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.1.3
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Log Analysis for thesis Huflit
|
92
|
+
test_files: []
|