log_analysis 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0978f59fdbae30fc5a8b74b76bdfd31fcb4b8a38743ea1747cba684abe0388be'
4
- data.tar.gz: 5d815fc14ccfb65471a1d81fede9dee19b8eff435a172864b13b088512be0a64
3
+ metadata.gz: 3229e7a8ab9b83925c34270e0e4de8ccec44f62ca94d7c29d1cafe14c1d6adf9
4
+ data.tar.gz: 9a0c94678156f7dc429d972ecb8f038fe86cd720a7df76963a1ded5abdbd8bf6
5
5
  SHA512:
6
- metadata.gz: 314fb6fd1732a024e4a11ed3cfc446c52ce850bb7a256baf719d86f7fdbcc3c603e3935b4ab804cd2c73261f7e2ed559af215a9b64679d099e7f8234c1033f79
7
- data.tar.gz: ec43259ab41e91cb63c9697f26a668addd96129d1f8cd01e068ab38ea4ae16ea0e1ef48c2d14d69ebbc17b0511f9d61a1a051487aaeb7cfe39e18eac91a74345
6
+ metadata.gz: 69adb8ae6e8b12a239b4af81c3b5dd3e17bac46304811ebb3afaa78eba5dedd51120aaa5d371bd400e3237dc14d2c49c4a8b7297cffa06ca453e767be29f3da9
7
+ data.tar.gz: d0f4459fdfb8416b2c621f54929d397f02e41fdeebdae29d95d5933a4e1db6b28f44701467c7488bc52197c8e2d9cc9b9d7bcd36d2a065bf031669af39d3f1ac
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_analysis (0.1.1)
4
+ log_analysis (0.1.2)
5
5
  activesupport (~> 6.0.3.1)
6
6
  useragent (~> 0.16.10)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.0.3.1)
11
+ activesupport (6.0.3.2)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 0.7, < 2)
14
14
  minitest (~> 5.1)
@@ -17,13 +17,13 @@ GEM
17
17
  concurrent-ruby (1.1.6)
18
18
  i18n (1.8.3)
19
19
  concurrent-ruby (~> 1.0)
20
- minitest (5.14.1)
20
+ minitest (5.13.0)
21
21
  rake (12.3.1)
22
22
  thread_safe (0.3.6)
23
23
  tzinfo (1.2.7)
24
24
  thread_safe (~> 0.1)
25
25
  useragent (0.16.10)
26
- zeitwerk (2.3.0)
26
+ zeitwerk (2.3.1)
27
27
 
28
28
  PLATFORMS
29
29
  ruby
@@ -4,6 +4,7 @@ require 'log_analysis/user_identification'
4
4
  require 'log_analysis/session_identification'
5
5
  require 'log_analysis/transformation'
6
6
  require 'log_analysis/rule_generation'
7
+ require 'time'
7
8
 
8
9
  class LogAnalysis
9
10
  class Error < StandardError; end
@@ -15,7 +16,6 @@ class LogAnalysis
15
16
  @path = path
16
17
  @type = type
17
18
  @cleaned_data = PreProcess.input(path, type)
18
- system('mkdir', '-p', LogAnalysis::DATA_PATH)
19
19
  end
20
20
 
21
21
  def identified_user
@@ -30,7 +30,15 @@ class LogAnalysis
30
30
  Transformation.execute(identified_session)
31
31
  end
32
32
 
33
- def rule_generation
34
- RuleGeneration.execute(transformation)
33
+ def rule_generation(conf = 0.5, sup = 60)
34
+ result = RuleGeneration.execute(transformation, conf, sup)
35
+ move_data
36
+ result
37
+ end
38
+
39
+ def move_data
40
+ system('mv', "transform_data_#{Time.now.strftime('%Y%m%d')}.txt", '/home/app/data/waazabag/')
41
+ system('mv', "output_#{Time.now.strftime('%Y%m%d')}.txt", '/home/app/data/waazabag/')
42
+ system('mv', "map_uri_#{Time.now.strftime('%Y%m%d')}.txt", '/home/app/data/waazabag/')
35
43
  end
36
44
  end
@@ -17,9 +17,10 @@ module PreProcess
17
17
 
18
18
  File.readlines(file_path).each_with_object([]).with_index do |(line, arr), i|
19
19
  preprocessed_log = type.nil? ? line.gsub(/[\t]/i, ' ').chomp! : line
20
- record = Record.new(send(CONVERT_RECORD[type.nil? ? 'nginx' : type], preprocessed_log)) unless preprocessed_log.nil?
20
+ record_params = send(CONVERT_RECORD[type.nil? ? 'nginx' : type], preprocessed_log)
21
+ record = Record.new(record_params) if record_params && preprocessed_log
21
22
 
22
- arr.push(record) if record.status_200? && record.method_get? && record.uri_without_data && !record.robot?
23
+ arr.push(record) if record && record.status_200? && record.method_get? && record.uri_without_data && !record.robot?
23
24
 
24
25
  puts arr.size
25
26
  end
@@ -35,6 +36,8 @@ module PreProcess
35
36
 
36
37
  def self.convert_nginx_logs(log)
37
38
  o = log.split(REGEX_NGINX)
39
+
40
+ return false if o.size <= 1
38
41
  o.delete('')
39
42
 
40
43
  {}.tap do |p|
@@ -2,18 +2,18 @@ require 'time'
2
2
  require 'log_analysis/version'
3
3
 
4
4
  module RuleGeneration
5
- JAR_FILE_PATH = File.expand_path('spmf.jar')
6
- TRANSFORM_DATA_PATH = File.expand_path("#{LogAnalysis::DATA_PATH}transform_data_#{Time.now.strftime('%Y%m%d')}.txt")
7
- RULE_FILE_PATH = File.expand_path("#{LogAnalysis::DATA_PATH}output_#{Time.now.strftime('%Y%m%d')}.txt")
8
- MAP_URI_FILE_PATH = File.expand_path("#{LogAnalysis::DATA_PATH}map_uri_#{Time.now.strftime('%Y%m%d')}.txt")
5
+ JAR_FILE_PATH = File.join(File.dirname(__FILE__), './files/spmf.jar')
6
+ TRANSFORM_DATA_PATH = "transform_data_#{Time.now.strftime('%Y%m%d')}.txt".freeze
7
+ RULE_FILE_PATH = "output_#{Time.now.strftime('%Y%m%d')}.txt".freeze
8
+ MAP_URI_FILE_PATH = "map_uri_#{Time.now.strftime('%Y%m%d')}.txt".freeze
9
9
 
10
10
  class Error < StandardError; end
11
11
  # Your code goes here...
12
12
 
13
- def self.execute(transform_data)
13
+ def self.execute(transform_data, min_conf, min_sup)
14
14
  File.open(TRANSFORM_DATA_PATH, 'w+') { |f| transform_data.keys.each { |e| f.puts(transform_data[e].map { |i| i.is_a?(Array) ? i.join(' ') : i }.join(' -1 ').concat(' -1 -2')) } }
15
- system("java -jar #{JAR_FILE_PATH} run SPADE #{TRANSFORM_DATA_PATH} #{RULE_FILE_PATH} 65%")
16
- result = rule_gen(get_seq(File.read(RULE_FILE_PATH)), 0.5)
15
+ system("java -jar #{JAR_FILE_PATH} run SPADE #{TRANSFORM_DATA_PATH} #{RULE_FILE_PATH} #{min_sup}%")
16
+ result = rule_gen(get_seq(File.read(RULE_FILE_PATH)), min_conf)
17
17
  map_uri = File.read(MAP_URI_FILE_PATH).split(' ')
18
18
 
19
19
  result.map do |rule|
@@ -3,7 +3,7 @@ require 'log_analysis/model/user_identity'
3
3
  require 'log_analysis/version'
4
4
 
5
5
  module Transformation
6
- MAP_URI_FILE_PATH = File.expand_path("#{LogAnalysis::DATA_PATH}map_uri_#{Time.now.strftime('%Y%m%d')}.txt")
6
+ MAP_URI_FILE_PATH = "map_uri_#{Time.now.strftime('%Y%m%d')}.txt".freeze
7
7
 
8
8
  class Error < StandardError; end
9
9
  # Your code goes here...
@@ -1,4 +1,4 @@
1
1
  class LogAnalysis
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  DATA_PATH = '~/data/waazabag/'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Tran
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-12 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: useragent
@@ -57,6 +57,7 @@ files:
57
57
  - bin/console
58
58
  - bin/setup
59
59
  - lib/log_analysis.rb
60
+ - lib/log_analysis/files/spmf.jar
60
61
  - lib/log_analysis/model/record.rb
61
62
  - lib/log_analysis/model/session_identity.rb
62
63
  - lib/log_analysis/model/user_identity.rb
@@ -67,14 +68,13 @@ files:
67
68
  - lib/log_analysis/user_identification.rb
68
69
  - lib/log_analysis/version.rb
69
70
  - log_analysis.gemspec
70
- - spmf.jar
71
71
  homepage: https://github.com/michaelt0520/log_analysis_thesis
72
72
  licenses:
73
73
  - MIT
74
74
  metadata:
75
75
  homepage_uri: https://github.com/michaelt0520/log_analysis_thesis
76
76
  source_code_uri: https://github.com/michaelt0520/log_analysis_thesis
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options: []
79
79
  require_paths:
80
80
  - lib
@@ -89,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.1.3
93
- signing_key:
92
+ rubygems_version: 3.1.2
93
+ signing_key:
94
94
  specification_version: 4
95
95
  summary: Log Analysis for thesis Huflit
96
96
  test_files: []