apache_log_report 0.9.2 → 0.9.7
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 +4 -4
- data/README.org +7 -0
- data/exe/apache_log_report +1 -2
- data/lib/apache_log_report.rb +46 -26
- data/lib/apache_log_report/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6585f8ec0330f9f396aff91cd5f45400e70afd77ab3aee3b780b940bf1fdfb2
|
4
|
+
data.tar.gz: 3c54f1128fb5a407ecd19e12252038ecdc4003fe0dc5ad309eb42e1d4a00126a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf3705b84a912e7a0d6b8b13a26ae12be6da8cba2effbfa136f899e78c9727295035348eaf2d689ff5772de4b03e26790dc8cb2e7b2c84b2043e2f05028c74f4
|
7
|
+
data.tar.gz: fc87021cff6a8a97666d42477dbbc5236199c9c76b25be31cdf0b378ccdb91e853cbfca2faf7cc2c381ff23e440cb434c48e343a714ae7ead965e93633d7f639
|
data/README.org
CHANGED
@@ -12,6 +12,13 @@
|
|
12
12
|
|
13
13
|
See the [[file:CHANGELOG.org][CHANGELOG]] file.
|
14
14
|
|
15
|
+
* Todo
|
16
|
+
|
17
|
+
** TODO Version information from command line and in reports
|
18
|
+
** TODO Refactor code from one giant class to more manageable chunkes
|
19
|
+
** TODO Move performance stats var to class (to isolate vars)
|
20
|
+
** TODO Check total number of days (which is not working, now)
|
21
|
+
|
15
22
|
* Compatibility
|
16
23
|
|
17
24
|
|
data/exe/apache_log_report
CHANGED
@@ -16,13 +16,12 @@ if @log_file and not File.exist? @log_file
|
|
16
16
|
end
|
17
17
|
|
18
18
|
#
|
19
|
-
# Parse Log
|
19
|
+
# Parse Log and Track Statistics
|
20
20
|
#
|
21
21
|
|
22
22
|
@started_at = Time.now
|
23
23
|
@db = ApacheLogReport.parse @log_file
|
24
24
|
ApacheLogReport.analyze_data @db, @options
|
25
|
-
|
26
25
|
@ended_at = Time.now
|
27
26
|
@duration = @ended_at - @started_at
|
28
27
|
|
data/lib/apache_log_report.rb
CHANGED
@@ -5,13 +5,14 @@ module ApacheLogReport
|
|
5
5
|
#
|
6
6
|
require 'optparse'
|
7
7
|
require 'optparse/date'
|
8
|
+
require 'apache_log_report/version'
|
8
9
|
|
9
10
|
def self.options_parse options
|
10
11
|
limit = 30
|
11
12
|
args = {}
|
12
13
|
|
13
14
|
opt_parser = OptionParser.new do |opts|
|
14
|
-
opts.banner = "Usage:
|
15
|
+
opts.banner = "Usage: apache_log_report [options] [logfile]"
|
15
16
|
|
16
17
|
opts.on("-lN", "--limit=N", Integer, "Number of entries to show (defaults to #{limit})") do |n|
|
17
18
|
args[:limit] = n
|
@@ -25,28 +26,42 @@ module ApacheLogReport
|
|
25
26
|
args[:to_date] = n
|
26
27
|
end
|
27
28
|
|
28
|
-
opts.on("-i", "--ignore-crawlers", "Ignore crawlers") do
|
29
|
+
opts.on("-i", "--ignore-crawlers", "Ignore crawlers") do
|
29
30
|
args[:ignore_crawlers] = true
|
30
31
|
end
|
31
32
|
|
32
|
-
opts.on("-p", "--ignore-selfpoll", "Ignore apaches self poll entries (from ::1)") do
|
33
|
+
opts.on("-p", "--ignore-selfpoll", "Ignore apaches self poll entries (from ::1)") do
|
33
34
|
args[:no_selfpoll] = true
|
34
35
|
end
|
35
36
|
|
36
|
-
opts.on("-c", "--only-crawlers", "Perform analysis on crawlers only") do
|
37
|
+
opts.on("-c", "--only-crawlers", "Perform analysis on crawlers only") do
|
37
38
|
args[:only_crawlers] = true
|
38
39
|
end
|
39
40
|
|
40
|
-
opts.on("-
|
41
|
+
opts.on("-uPREFIX", "--prefix=PREFIX", String, "Prefix to add to all plots (used to run multiple analyses in the same dir)") do |n|
|
41
42
|
args[:prefix] = n
|
42
43
|
end
|
43
44
|
|
44
|
-
opts.on("-
|
45
|
+
opts.on("-wSUFFIX", "--suffix=SUFFIX", String, "Suffix to add to all plots (used to run multiple analyses in the same dir)") do |n|
|
45
46
|
args[:suffix] = n
|
46
47
|
end
|
47
48
|
|
49
|
+
opts.on("-cWHAT", "--code-export=WHAT", String, "Control :export directive in code blocks (code, results, *both*, none)") do |n|
|
50
|
+
args[:code_export] = n
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on("-v", "--version", "Prints version information") do
|
54
|
+
puts "apache_log_report version #{ApacheLogReport::VERSION}"
|
55
|
+
puts "Copyright (C) 2020 Adolfo Villafiorita"
|
56
|
+
puts "Distributed under the terms of the MIT license"
|
57
|
+
puts ""
|
58
|
+
puts "Written by Adolfo Villafiorita"
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
|
48
62
|
opts.on("-h", "--help", "Prints this help") do
|
49
63
|
puts opts
|
64
|
+
puts "This is version #{ApacheLogReport::VERSION}"
|
50
65
|
exit
|
51
66
|
end
|
52
67
|
end
|
@@ -58,7 +73,8 @@ module ApacheLogReport
|
|
58
73
|
args[:no_selfpoll] ||= false
|
59
74
|
args[:only_crawlers] ||= false
|
60
75
|
args[:prefix] ||= ""
|
61
|
-
args[:
|
76
|
+
args[:suffix] ||= ""
|
77
|
+
args[:code_export] ||= "both"
|
62
78
|
|
63
79
|
return args
|
64
80
|
end
|
@@ -125,7 +141,7 @@ module ApacheLogReport
|
|
125
141
|
hash[:datetime].iso8601,
|
126
142
|
hash[:remote_host],
|
127
143
|
hash[:user],
|
128
|
-
hash[:remote_host] + hash[:user_agent],
|
144
|
+
hash[:datetime].iso8601 + " " + hash[:remote_host] + " " + hash[:user_agent],
|
129
145
|
hash[:request][:method],
|
130
146
|
hash[:request][:path],
|
131
147
|
(hash[:request][:path] ? File.extname(hash[:request][:path]) : ""),
|
@@ -188,8 +204,8 @@ module ApacheLogReport
|
|
188
204
|
@missed_resources = db.execute "SELECT path, count(path), count(distinct(unique_visitor)) from LogLine where status == '404' and #{@filter} group by path order by count(path) desc limit #{options[:limit]}"
|
189
205
|
|
190
206
|
@reasonable_requests_exts = [ ".html", ".css", ".js", ".jpg", ".svg", ".png", ".woff", ".xml", ".ttf", ".ico", ".pdf", ".htm", ".txt", ".org" ].map { |x|
|
191
|
-
"extension
|
192
|
-
}.join "
|
207
|
+
"extension != '#{x}'"
|
208
|
+
}.join " and "
|
193
209
|
|
194
210
|
@attacks = db.execute "SELECT path, count(path), count(distinct(unique_visitor)) from LogLine where status == '404' and #{@filter} and (#{@reasonable_requests_exts}) group by path order by count(path) desc limit #{options[:limit]}"
|
195
211
|
|
@@ -231,8 +247,9 @@ module ApacheLogReport
|
|
231
247
|
end
|
232
248
|
|
233
249
|
def self.emit options = {}, command, log_file, started_at, ended_at, duration
|
234
|
-
@
|
250
|
+
@prefix = options[:prefix]
|
235
251
|
@suffix = options[:suffix]
|
252
|
+
@export = options[:code_export]
|
236
253
|
|
237
254
|
<<EOS
|
238
255
|
#+TITLE: Apache Log Analysis: #{log_file}
|
@@ -253,7 +270,7 @@ module ApacheLogReport
|
|
253
270
|
|
254
271
|
#{ output_table "daily_distribution", ["Day", "Hits", "Visits", "Size"], @daily_distribution }
|
255
272
|
|
256
|
-
#+BEGIN_SRC gnuplot :var data = daily_distribution :results output :exports
|
273
|
+
#+BEGIN_SRC gnuplot :var data = daily_distribution :results output :exports #{@export} :file #{@prefix}daily#{@suffix}.svg
|
257
274
|
reset
|
258
275
|
set grid ytics linestyle 0
|
259
276
|
set grid xtics linestyle 0
|
@@ -267,7 +284,8 @@ set xtics rotate by 60 right
|
|
267
284
|
set title "Hits and Visitors"
|
268
285
|
set xlabel "Date"
|
269
286
|
set ylabel "Hits"
|
270
|
-
set
|
287
|
+
set y2label "Visits"
|
288
|
+
set y2tics
|
271
289
|
|
272
290
|
set style fill transparent solid 0.2 noborder
|
273
291
|
|
@@ -285,7 +303,7 @@ data using 1:($2+100):2 with labels notitle textcolor rgb "#0000AA" axes x1y2
|
|
285
303
|
#{ output_table "time_distribution", ["Hour", "Hits", "Visits", "Size"], @time_distribution }
|
286
304
|
|
287
305
|
|
288
|
-
#+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports
|
306
|
+
#+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports #{@export} :file #{@prefix}time#{@suffix}.svg
|
289
307
|
reset
|
290
308
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
291
309
|
|
@@ -293,7 +311,9 @@ set grid ytics linestyle 0
|
|
293
311
|
|
294
312
|
set title "Hits and Visitors"
|
295
313
|
set xlabel "Date"
|
296
|
-
set ylabel "Hits
|
314
|
+
set ylabel "Hits"
|
315
|
+
set y2label "Visitors"
|
316
|
+
set y2tics
|
297
317
|
|
298
318
|
set style fill solid 0.25
|
299
319
|
set boxwidth 0.6
|
@@ -307,7 +327,7 @@ data using ($0 - 0.2):($2 + 10):2 with labels title "" textcolor rgb("#0000AA"),
|
|
307
327
|
data using ($0 + 0.2):($3 + 10):3 with labels title "" textcolor rgb("#AA0000") axes x1y2
|
308
328
|
#+END_SRC
|
309
329
|
|
310
|
-
#+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports
|
330
|
+
#+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports #{@export} :file #{@prefix}time-traffic#{@suffix}.svg
|
311
331
|
reset
|
312
332
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
313
333
|
|
@@ -345,13 +365,13 @@ data using ($0):($2 + 10):2 with labels title "" textcolor rgb("#00AA00")
|
|
345
365
|
|
346
366
|
* Possible Attacks
|
347
367
|
|
348
|
-
#{ output_table "
|
368
|
+
#{ output_table "attacks", ["Path", "Hits", "Visitors"], @attacks }
|
349
369
|
|
350
370
|
* Statuses
|
351
371
|
|
352
372
|
#{ output_table "statuses", ["Status", "Count"], @statuses }
|
353
373
|
|
354
|
-
#+BEGIN_SRC gnuplot :var data = statuses :results output :exports
|
374
|
+
#+BEGIN_SRC gnuplot :var data = statuses :results output :exports #{@export} :file #{@prefix}statuses#{@suffix}.svg
|
355
375
|
reset
|
356
376
|
set grid ytics linestyle 0
|
357
377
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
@@ -367,7 +387,7 @@ data using ($0):($2+100):2 with labels textcolor rgb "#0000AA"
|
|
367
387
|
|
368
388
|
#{ output_table "daily_statuses", ["Status", "2xx", "3xx", "4xx"], @statuses_by_day }
|
369
389
|
|
370
|
-
#+BEGIN_SRC gnuplot :var data = daily_statuses :results output :exports
|
390
|
+
#+BEGIN_SRC gnuplot :var data = daily_statuses :results output :exports #{@export} :file #{@prefix}daily-statuses#{@suffix}.svg
|
371
391
|
reset
|
372
392
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
373
393
|
|
@@ -384,19 +404,19 @@ set boxwidth 0.6
|
|
384
404
|
set style data histograms
|
385
405
|
set style histogram clustered gap 1
|
386
406
|
|
387
|
-
plot data using 2:xtic(1) lc rgb "#
|
407
|
+
plot data using 2:xtic(1) lc rgb "#00AA00" title "2xx", \\
|
388
408
|
data using 3 lc rgb "#0000CC" title "3xx", \\
|
389
|
-
data using 4 lc rgb "#
|
390
|
-
data using ($0 - 1. / 4):($2 + 0.5):2 with labels title "" textcolor rgb("#
|
409
|
+
data using 4 lc rgb "#AA0000" title "4xx", \\
|
410
|
+
data using ($0 - 1. / 4):($2 + 0.5):2 with labels title "" textcolor rgb("#00AA00"), \\
|
391
411
|
data using ($0):($3 + 0.5):3 with labels title "" textcolor rgb("#0000CC"), \\
|
392
|
-
data using ($0 + 1. / 4):($4 + 0.5):4 with labels title "" textcolor rgb("#
|
412
|
+
data using ($0 + 1. / 4):($4 + 0.5):4 with labels title "" textcolor rgb("#AA0000")
|
393
413
|
#+END_SRC
|
394
414
|
|
395
415
|
* Browsers
|
396
416
|
|
397
417
|
#{ output_table "browsers", ["Browser", "Hits", "Visitors", "Size"], @browsers }
|
398
418
|
|
399
|
-
#+BEGIN_SRC gnuplot :var data = browsers :results output :exports
|
419
|
+
#+BEGIN_SRC gnuplot :var data = browsers :results output :exports #{@export} :file #{@prefix}browser#{@suffix}.svg
|
400
420
|
reset
|
401
421
|
set grid ytics linestyle 0
|
402
422
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
@@ -412,7 +432,7 @@ data using ($0):($2+100):2 with labels textcolor rgb "#0000AA"
|
|
412
432
|
|
413
433
|
#{ output_table "platforms", ["Platform", "Hits", "Visitors", "Size"], @platforms }
|
414
434
|
|
415
|
-
#+BEGIN_SRC gnuplot :var data = platforms :results output :exports
|
435
|
+
#+BEGIN_SRC gnuplot :var data = platforms :results output :exports #{@export} :file #{@prefix}platforms#{@suffix}.svg
|
416
436
|
reset
|
417
437
|
set grid ytics linestyle 0
|
418
438
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
@@ -433,7 +453,7 @@ data using ($0):($2+100):2 with labels textcolor rgb "#0000AA"
|
|
433
453
|
|
434
454
|
#{ output_table "referers", ["Referers", "Hits", "Visitors", "Size"], @referers }
|
435
455
|
|
436
|
-
#+BEGIN_SRC gnuplot :var data = referers :results output :exports
|
456
|
+
#+BEGIN_SRC gnuplot :var data = referers :results output :exports #{@export} :file #{@prefix}referers#{@suffix}.svg
|
437
457
|
reset
|
438
458
|
set terminal svg size 1200,800 fname 'Arial' fsize 10
|
439
459
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apache_log_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adolfo Villafiorita
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apache_log-parser
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.0.3
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Generate a request report in OrgMode format from an Apache log file.
|