apache_log_report 1.0.0 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ <%
2
+ def slugify string
3
+ string.downcase.gsub(/ +/, '-')
4
+ end
5
+ %>
6
+
7
+ <table id="<%= slugify(title || "") %>" class="table <%= slugify(title || "") %>">
8
+ <thead>
9
+ <tr>
10
+ <% header.each do |heading| %>
11
+ <th class="<%= slugify(heading) %>"><%= heading %></th>
12
+ <% end %>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% rows.each do |row| %>
17
+ <tr>
18
+ <% row.each_with_index do |cell, i| %>
19
+ <td class="<%= slugify (header[i] || "") %>"><%= cell %></td>
20
+ <% end %>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+
@@ -0,0 +1,221 @@
1
+ <html>
2
+ <head>
3
+ <title>Apache Log Analysis: <%= data[:log_file] || "stdin" %></title>
4
+ <meta name="author" content="apache_log_report">
5
+
6
+ <link rel="stylesheet" href="alr-styles.css"></style>
7
+
8
+ <link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre.min.css">
9
+ <link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-exp.min.css">
10
+ <link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-icons.min.css">
11
+ </head>
12
+
13
+ <body>
14
+ <section class="container">
15
+ <h1>Apache Log Analysis: <%= data[:log_file] || "stdin" %></h1>
16
+
17
+ <div class="columns">
18
+ <article class="col-6 column">
19
+ <h2>Summary</h2>
20
+
21
+ <table class="table summary">
22
+ <tr>
23
+ <th class="hits">Hits</th>
24
+ <td class="hits"><%= data[:total_hits][0][0] %></td>
25
+ </tr>
26
+ <tr>
27
+ <th class="unique-visitors">Unique Visitors</th>
28
+ <td class="unique-visitors"><%= data[:total_unique_visitors][0][0] %></td>
29
+ </tr>
30
+ <tr>
31
+ <th class="tx">Tx</th>
32
+ <td class="tx"><%= data[:total_size][0][0] %></td>
33
+ </tr>
34
+ <tr>
35
+ <th class="period">Period</th>
36
+ <td class="period">
37
+ <%= data[:first_day][0][0] %>
38
+ --
39
+ <%= data[:last_day][0][0] %>
40
+ </td>
41
+ </tr>
42
+ <tr>
43
+ <th class="days">Days </th>
44
+ <td class="days"><%= data[:total_days] %></td>
45
+ </tr>
46
+ </table>
47
+ </article>
48
+ <article class="column col-6">
49
+ <h3> Log Structure</h3>
50
+
51
+ <table class="table log-structure">
52
+ <tbody>
53
+ <tr>
54
+ <th>Input file</th>
55
+ <td><b><%= (data[:log_file] || "stdin") %></b></td>
56
+ </tr>
57
+ <tr>
58
+ <th>Log size</th>
59
+ <td><%= data[:log_size][0][0] %></td>
60
+ </tr>
61
+ <tr>
62
+ <th>Self poll entries</th>
63
+ <td><%= data[:selfpolls_size][0][0] %></td>
64
+ </tr>
65
+ <tr>
66
+ <th>Crawlers</th>
67
+ <td><%= data[:crawlers_size][0][0] %></td>
68
+ </tr>
69
+ <tr>
70
+ <th>Entries considered</th>
71
+ <td><%= data[:total_hits][0][0] %></td>
72
+ </tr>
73
+ </tbody>
74
+ </table>
75
+ </article>
76
+ </div>
77
+
78
+ <% @reports = [
79
+ { title: "Daily Distribution", header: ["Day", "Hits", "Visits", "Size"], rows: data[:daily_distribution] },
80
+ { title: "Time Distribution", header: ["Hour", "Hits", "Visits", "Size"], rows: data[:time_distribution] },
81
+ { title: "Most Requested Pages", header: ["Path", "Hits", "Visits", "Size"], rows: data[:most_requested_pages] },
82
+ { title: "Most Requested Resources", header: ["Path", "Hits", "Visits", "Size"], rows: data[:most_requested_resources] },
83
+ { title: "404 on HTML Files", header: ["Path", "Hits", "Visitors"], rows: data[:missed_pages] },
84
+ { title: "404 on other Resources", header: ["Path", "Hits", "Visitors"], rows: data[:missed_resources] },
85
+ { title: "Attacks", header: ["Path", "Hits", "Visitors"], rows: data[:attacks] },
86
+ { },
87
+ { title: "Statuses", header: ["Status", "Count"], rows: data[:statuses] },
88
+ { title: "Daily Statuses", header: ["Status", "2xx", "3xx", "4xx"], rows: data[:statuses_by_day] },
89
+ { title: "Browsers", header: ["Browser", "Hits", "Visitors", "Size"], rows: data[:browsers] },
90
+ { title: "Platforms", header: ["Platform", "Hits", "Visitors", "Size"], rows: data[:platforms] },
91
+ { title: "Referers", header: ["Referers", "Hits", "Visitors", "Size"], rows: data[:referers], col: "col-12" },
92
+ { title: "IPs", header: ["IPs", "Hits", "Visitors", "Size"], rows: data[:ips] },
93
+ { },
94
+ ]
95
+ %>
96
+ <div class="columns">
97
+ <% @reports.each do |report| %>
98
+ <div class="column <%= report[:col] || "col-6" %>">
99
+ <article>
100
+ <% if report[:title] != nil %>
101
+ <h2><%= report[:title] %></h2>
102
+ <%= render "output_table", report %>
103
+ <% end %>
104
+ </article>
105
+ </div>
106
+ <% end %>
107
+ </div>
108
+
109
+ <article>
110
+ <h2>Streaks</h2>
111
+
112
+ <table class="table streaks">
113
+ <thead>
114
+ <tr>
115
+ <th>IP</th>
116
+ <th>Day and URL</th>
117
+ </tr>
118
+ </thead>
119
+ <tbody>
120
+ <% data[:streaks].group_by(&:first).each do |ip, date_urls| %>
121
+ <tr>
122
+ <td class="ip"><%= ip %></td>
123
+ <td class="streaks">
124
+ <% date_urls.group_by(&:first).each do |date, urls| %>
125
+ <% urls.each do |url| %>
126
+ <b><%= url[1] %>:</b> <%= url[2] %> <br />
127
+ <% end %>
128
+ <% end %>
129
+ </td>
130
+ </tr>
131
+ <% end %>
132
+ </tbody>
133
+ </table>
134
+ </article>
135
+
136
+ <div class="columns">
137
+ <div class="column col-6">
138
+ <article>
139
+ <h2>Command Invocation</h2>
140
+
141
+ <table class="table command-invocation">
142
+ <tbody>
143
+ <tr>
144
+ <th>CLI Command</th>
145
+ <td><pre><%= data[:command] %></pre></td>
146
+ </tr>
147
+ <tr>
148
+ <th>Input file</th>
149
+ <td><code><%= (data[:log_file] || "stdin") %></code></td>
150
+ </tr>
151
+ <tr>
152
+ <th>Ignore crawlers</th>
153
+ <td><code><%= options[:ignore_crawlers] %></code></td></tr>
154
+ <tr>
155
+ <th>Only crawlers</th>
156
+ <td><code><%= options[:only_crawlers] %></code></td>
157
+ </tr>
158
+ <tr>
159
+ <th>No selfpoll</th>
160
+ <td><code><%= options[:no_selfpoll] %></code></td>
161
+ </tr>
162
+ <tr>
163
+ <th>Filter by date</th>
164
+ <td>
165
+ <code><%= (options[:from_date] != nil or options[:to_date] != nil) %></code>
166
+ </td>
167
+ </tr>
168
+ <tr>
169
+ <th>Prefix</th>
170
+ <td><code><%= @prefix %></code></td>
171
+ </tr>
172
+ <tr>
173
+ <th>Suffix</th>
174
+ <td><code><%= @suffix %></code></td>
175
+ </tr>
176
+ </tbody>
177
+ </table>
178
+ </article>
179
+ </div>
180
+
181
+ <div class="column col-6">
182
+ <article>
183
+ <h2> Performance</h2>
184
+
185
+ <table class="table performance">
186
+ <tbody>
187
+ <tr>
188
+ <th>Analysis started at</th>
189
+ <td><%= data[:started_at].to_s %></td>
190
+ </tr>
191
+ <tr>
192
+ <th>Analysis ended at</th>
193
+ <td><%= data[:ended_at].to_s %></td>
194
+ </tr>
195
+ <tr>
196
+ <th>Duration (sec)</th>
197
+ <td><%= "%.1f" % data[:duration] %></td>
198
+ </tr>
199
+ <tr>
200
+ <th>Duration (min)</th>
201
+ <td><%= "%d" % (data[:duration] / 60 ) %></td>
202
+ </tr>
203
+ <tr>
204
+ <th>Log size</th>
205
+ <td><%= data[:log_size][0][0] %></td>
206
+ </tr>
207
+ <tr>
208
+ <th>Lines/sec</th>
209
+ <td><%= "%.2f" % (data[:log_size][0][0] / data[:duration]) %></td></tr>
210
+ </tbody>
211
+ </table>
212
+ </article>
213
+ </div>
214
+ </div>
215
+ </section>
216
+ </body>
217
+ </html>
218
+
219
+
220
+
221
+
@@ -0,0 +1,262 @@
1
+ #+TITLE: Apache Log Analysis: <%= data[:log_file] %>
2
+ #+DATE: <<%= Date.today %>>
3
+ #+STARTUP: showall
4
+ #+OPTIONS: ^:{}
5
+ #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="ala-style.css" />
6
+ #+OPTIONS: html-style:nil
7
+
8
+ * Summary
9
+
10
+ | Hits | <%= "%10d" % data[:total_hits][0][0] %> |
11
+ | Unique Visitors | <%= "%10d" % data[:total_unique_visitors][0][0] %> |
12
+ | Tx | <%= "%10s" % data[:total_size][0][0] %> |
13
+ | Days | <%= "%10d" % data[:total_days][0][0] %> |
14
+
15
+ * Daily Distribution
16
+
17
+ <%= self.output_table "daily_distribution", ["Day", "Hits", "Visits", "Size"], data[:daily_distribution] %>
18
+
19
+ #+BEGIN_SRC gnuplot :var data = daily_distribution :results output :exports <%= @export %> :file <%= @prefix %>daily<%= @suffix %>.svg
20
+ reset
21
+ set grid ytics linestyle 0
22
+ set grid xtics linestyle 0
23
+ set terminal svg size 1200,800 fname 'Arial'
24
+
25
+ set xdata time
26
+ set timefmt "%Y-%m-%d"
27
+ set format x "%a, %b %d"
28
+ set xtics rotate by 60 right
29
+
30
+ set title "Hits and Visitors"
31
+ set xlabel "Date"
32
+ set ylabel "Hits"
33
+ set y2label "Visits"
34
+ set y2tics
35
+
36
+ set style fill transparent solid 0.2 noborder
37
+
38
+ plot data using 1:2 with linespoints lw 3 lc rgb "#0000AA" pointtype 5 title "Hits" axes x1y2, \\
39
+ data using 1:2 with filledcurves below x1 linecolor rgb "#0000AA" notitle axes x1y2, \\
40
+ data using 1:3 with linespoints lw 3 lc rgb "#AA0000" pointtype 7 title "Visitors", \\
41
+ data using 1:3 with filledcurves below x1 notitle linecolor rgb "#AA0000", \\
42
+ data using 1:($3+0.1*$3):3 with labels notitle textcolor rgb "#AA0000", \\
43
+ data using 1:($2+0.1*$2):2 with labels notitle textcolor rgb "#0000AA" axes x1y2
44
+ #+END_SRC
45
+
46
+
47
+ * Time Distribution
48
+
49
+ <%= self.output_table "time_distribution", ["Hour", "Hits", "Visits", "Size"], data[:time_distribution] %>
50
+
51
+
52
+ #+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports <%= @export %> :file <%= @prefix %>time<%= @suffix %>.svg
53
+ reset
54
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
55
+
56
+ set grid ytics linestyle 0
57
+
58
+ set title "Hits and Visitors"
59
+ set xlabel "Date"
60
+ set ylabel "Hits"
61
+ set y2label "Visitors"
62
+ set y2tics
63
+
64
+ set style fill solid 0.25
65
+ set boxwidth 0.6
66
+
67
+ set style data histograms
68
+ set style histogram clustered gap 1
69
+
70
+ plot data using 2:xtic(1) lc rgb "#0000AA" title "Hits", \\
71
+ data using 3 lc rgb "#AA0000" title "Visitors" axes x1y2, \\
72
+ data using ($0 - 0.2):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#0000AA"), \\
73
+ data using ($0 + 0.2):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#AA0000") axes x1y2
74
+ #+END_SRC
75
+
76
+ #+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports <%= @export %> :file <%= @prefix %>time-traffic<%= @suffix %>.svg
77
+ reset
78
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
79
+
80
+ set grid ytics linestyle 0
81
+
82
+ set title "Traffic"
83
+ set xlabel "Date"
84
+ set ylabel "Traffic"
85
+
86
+ set style fill solid 0.50
87
+ set boxwidth 0.6
88
+
89
+ set style data histograms
90
+ set style histogram clustered gap 1
91
+
92
+ plot data using 2:xtic(1) lc rgb "#00AA00" title "Traffic", \\
93
+ data using ($0):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#00AA00")
94
+ #+END_SRC
95
+
96
+ * Most Requested Pages
97
+
98
+ <%= self.output_table "most_requested_pages", ["Path", "Hits", "Visits", "Size"], data[:most_requested_pages] %>
99
+
100
+ * Most Requested URIs
101
+
102
+ <%= self.output_table "most_requested_resources", ["Path", "Hits", "Visits", "Size"], data[:most_requested_resources] %>
103
+
104
+ * 404s on HTML files
105
+
106
+ <%= self.output_table "pages_404", ["Path", "Hits", "Visitors"], data[:missed_pages] %>
107
+
108
+ * 404s on other resources
109
+
110
+ <%= self.output_table "resources_404", ["Path", "Hits", "Visitors"], data[:missed_resources] %>
111
+
112
+ * Possible Attacks
113
+
114
+ <%= self.output_table "attacks", ["Path", "Hits", "Visitors"], data[:attacks] %>
115
+
116
+ * Statuses
117
+
118
+ <%= self.output_table "statuses", ["Status", "Count"], data[:statuses] %>
119
+
120
+ #+BEGIN_SRC gnuplot :var data = statuses :results output :exports <%= @export %> :file <%= @prefix %>statuses<%= @suffix %>.svg
121
+ reset
122
+ set grid ytics linestyle 0
123
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
124
+
125
+ set style fill solid 0.25
126
+ set boxwidth 0.6
127
+
128
+ plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
129
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
130
+ #+END_SRC
131
+
132
+ * Daily Statuses
133
+
134
+ <%= self.output_table "daily_statuses", ["Status", "2xx", "3xx", "4xx"], data[:statuses_by_day] %>
135
+
136
+ #+BEGIN_SRC gnuplot :var data = daily_statuses :results output :exports <%= @export %> :file <%= @prefix %>daily-statuses<%= @suffix %>.svg
137
+ reset
138
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
139
+
140
+ set grid ytics linestyle 0
141
+
142
+ set title "Daily Statuses"
143
+ set xlabel "Date"
144
+ set ylabel "Number of Hits"
145
+ set xtics rotate by 60 right
146
+
147
+ set style fill solid 0.25
148
+ set boxwidth 0.6
149
+
150
+ set style data histograms
151
+ set style histogram clustered gap 1
152
+
153
+ plot data using 2:xtic(1) lc rgb "#00AA00" title "2xx", \\
154
+ data using 3 lc rgb "#0000CC" title "3xx", \\
155
+ data using 4 lc rgb "#AA0000" title "4xx", \\
156
+ data using ($0 - 1. / 4):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#00AA00"), \\
157
+ data using ($0):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#0000CC"), \\
158
+ data using ($0 + 1. / 4):($4 + 0.1*$4):4 with labels title "" textcolor rgb("#AA0000")
159
+ #+END_SRC
160
+
161
+ * Browsers
162
+
163
+ <%= self.output_table "browsers", ["Browser", "Hits", "Visitors", "Size"], data[:browsers] %>
164
+
165
+ #+BEGIN_SRC gnuplot :var data = browsers :results output :exports <%= @export %> :file <%= @prefix %>browser<%= @suffix %>.svg
166
+ reset
167
+ set grid ytics linestyle 0
168
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
169
+
170
+ set style fill solid 0.25
171
+ set boxwidth 0.6
172
+
173
+ plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
174
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
175
+ #+END_SRC
176
+
177
+ * Platforms
178
+
179
+ <%= self.output_table "platforms", ["Platform", "Hits", "Visitors", "Size"], data[:platforms] %>
180
+
181
+ #+BEGIN_SRC gnuplot :var data = platforms :results output :exports <%= @export %> :file <%= @prefix %>platforms<%= @suffix %>.svg
182
+ reset
183
+ set grid ytics linestyle 0
184
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
185
+
186
+ set style fill solid 0.25
187
+ set boxwidth 0.6
188
+
189
+ plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
190
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
191
+ #+END_SRC
192
+
193
+ * IPs
194
+
195
+ <%= self.output_table "ips", ["IPs", "Hits", "Visitors", "Size"], data[:ips] %>
196
+
197
+
198
+ * Referers
199
+
200
+ <%= self.output_table "referers", ["Referers", "Hits", "Visitors", "Size"], data[:referers] %>
201
+
202
+ #+BEGIN_SRC gnuplot :var data = referers :results output :exports <%= @export %> :file <%= @prefix %>referers<%= @suffix %>.svg
203
+ reset
204
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
205
+
206
+ set grid ytics linestyle 0
207
+ set grid xtics linestyle 0
208
+
209
+ set title "Referers"
210
+ set xlabel "Date"
211
+ set xtics rotate by 60 right
212
+ set ylabel "Hits and Visits"
213
+
214
+ set style fill solid 0.45
215
+ set boxwidth 0.7
216
+
217
+ set style data histograms
218
+ set style histogram clustered gap 1
219
+
220
+ plot data using 2:xtic(1) lc rgb "#AA00AA" title "Hits", \\
221
+ data using 3 lc rgb "#0AAAA0" title "Visits", \\
222
+ data using ($0 - 1. / 3):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#AA00AA"), \\
223
+ data using ($0 + 1. / 3):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#0AAAA0")
224
+ #+END_SRC
225
+
226
+ * Command Invocation and Performance
227
+
228
+ ** Command Invocation
229
+
230
+ #+BEGIN_EXAMPLE shell
231
+ <%= data[:command] %>
232
+ #+END_EXAMPLE
233
+
234
+ | Input file | <%= "%-50s" % (data[:log_file] || "stdin") %> |
235
+ | Ignore crawlers | <%= "%-50s" % options[:ignore_crawlers] %> |
236
+ | Only crawlers | <%= "%-50s" % options[:only_crawlers] %> |
237
+ | No selfpoll | <%= "%-50s" % options[:no_selfpoll] %> |
238
+ | Filter by date | <%= "%-50s" % (options[:from_date] != nil or options[:to_date] != nil) %> |
239
+ | Prefix | <%= "%-50s" % @prefix %> |
240
+ | Suffix | <%= "%-50s" % @suffix %> |
241
+
242
+ ** Log Structure
243
+
244
+ | Log size | <%= "%10d" % data[:log_size][0][0] %> |
245
+ | Self poll entries | <%= "%10d" % data[:selfpolls_size][0][0] %> |
246
+ | Crawlers | <%= "%10d" % data[:crawlers_size][0][0] %> |
247
+ | Entries considered | <%= "%10d" % data[:total_hits][0][0] %> |
248
+
249
+ ** Performance
250
+
251
+ | Analysis started at | <%= data[:started_at].to_s %> |
252
+ | Analysis ended at | <%= data[:ended_at].to_s %> |
253
+ | Duration (sec) | <%= "%5.3d" % data[:duration] %> |
254
+ | Duration (min) | <%= "%5.3d" % (data[:duration] / 60 ) %> |
255
+ | Log size | <%= "%9d" % data[:log_size][0][0] %> |
256
+ | Lines/sec | <%= "%6.2f" % (data[:log_size][0][0] / data[:duration]) %> |
257
+
258
+ * Local Variables :noexport:
259
+ # Local Variables:
260
+ # org-confirm-babel-evaluate: nil
261
+ # org-display-inline-images: t
262
+ # end:
@@ -1,3 +1,3 @@
1
1
  module ApacheLogReport
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.3"
3
3
  end