bind_log_analyzer 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/bind_log_analyzer +13 -5
- data/bind_log_analyzer.gemspec +1 -1
- data/doc/BindLogAnalyzer/Base.html +141 -63
- data/doc/BindLogAnalyzer/Connector.html +55 -161
- data/doc/BindLogAnalyzer/DatabaseConfsNotValid.html +1 -1
- data/doc/BindLogAnalyzer/LogUtils.html +242 -0
- data/doc/BindLogAnalyzer/WebServer.html +1 -1
- data/doc/BindLogAnalyzer.html +4 -4
- data/doc/Log.html +1 -1
- data/doc/_index.html +8 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +2 -2
- data/doc/top-level-namespace.html +1 -1
- data/lib/bind_log_analyzer/base.rb +34 -6
- data/lib/bind_log_analyzer/connector.rb +16 -27
- data/lib/bind_log_analyzer/log_utils.rb +28 -0
- data/lib/bind_log_analyzer/version.rb +1 -1
- metadata +19 -16
data/bin/bind_log_analyzer
CHANGED
@@ -16,11 +16,12 @@ require "optparse"
|
|
16
16
|
@db_port = nil
|
17
17
|
@db_username = nil
|
18
18
|
@db_password = nil
|
19
|
+
@check_uniq = false
|
19
20
|
|
20
21
|
optparse = OptionParser.new do |opts|
|
21
22
|
# Set a banner, displayed at the top
|
22
23
|
# of the help screen.
|
23
|
-
opts.banner = "Usage: ./#{File.basename(__FILE__)} (--file|-f FILENAME [--setup|-s] [--verbose|-v (1|2|3)] [--database|-d database_name] [--config|-c database_yaml_configurations] [--host|-H database_hostname] [--port|-p database_port] [--user|-u database_username] [--password|-p database_password] [-w|--webserver] | --help|-h)"
|
24
|
+
opts.banner = "Usage: ./#{File.basename(__FILE__)} (--file|-f FILENAME [--setup|-s] [--verbose|-v (1|2|3)] [--database|-d database_name] [--config|-c database_yaml_configurations] [--host|-H database_hostname] [--port|-p database_port] [--user|-u database_username] [--password|-p database_password] [-w|--webserver] [-u|--uniqueness] | --help|-h)"
|
24
25
|
|
25
26
|
# This displays the help screen
|
26
27
|
opts.on( '-h', '--help', 'Display this screen' ) do
|
@@ -28,14 +29,16 @@ optparse = OptionParser.new do |opts|
|
|
28
29
|
exit
|
29
30
|
end
|
30
31
|
|
31
|
-
opts.on( '-v', '--verbose LEVEL', "Enables verbose output. Use level 1 for
|
32
|
+
opts.on( '-v', '--verbose LEVEL', "Enables verbose output. Use level 1 for ERROR, 2 for WARN, 3 for INFO and 4 for DEBUG. If omitted will be user the FATAL level" ) do |opt|
|
32
33
|
case
|
33
34
|
when 1 === opt.to_i
|
34
35
|
@log_level = 1
|
35
36
|
when 2 === opt.to_i
|
36
37
|
@log_level = 2
|
37
|
-
when opt.to_i
|
38
|
+
when 3 === opt.to_i
|
38
39
|
@log_level = 3
|
40
|
+
when opt.to_i >= 4
|
41
|
+
@log_level = 4
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
@@ -79,6 +82,10 @@ optparse = OptionParser.new do |opts|
|
|
79
82
|
opts.on( '-p', '--password PASSWORD', 'The password of the user' ) do |opt|
|
80
83
|
@db_password = opt
|
81
84
|
end
|
85
|
+
|
86
|
+
opts.on( '-u', '--uniqueness', 'This param, used with -f|--file, checks if a record exists before creating it' ) do |opt|
|
87
|
+
@check_uniq = true
|
88
|
+
end
|
82
89
|
end
|
83
90
|
|
84
91
|
optparse.parse!
|
@@ -107,14 +114,15 @@ if @webserver
|
|
107
114
|
#**********************************#
|
108
115
|
EOF
|
109
116
|
@log_level = 1 if @log_level == 0
|
110
|
-
BindLogAnalyzer::
|
117
|
+
logger = BindLogAnalyzer::LogUtils.set_log_level(@log_level)
|
118
|
+
BindLogAnalyzer::Connector.establish_connection(@database_confs, logger)
|
111
119
|
if @webserver_port
|
112
120
|
BindLogAnalyzer::WebServer.run!({ port: @webserver_port.to_i})
|
113
121
|
else
|
114
122
|
BindLogAnalyzer::WebServer.run!
|
115
123
|
end
|
116
124
|
elsif @filename
|
117
|
-
base = BindLogAnalyzer::Base.new(@database_confs, @filename, @setup_database, @log_level)
|
125
|
+
base = BindLogAnalyzer::Base.new(@database_confs, @filename, @setup_database, @log_level, @check_uniq)
|
118
126
|
base.analyze
|
119
127
|
else
|
120
128
|
puts optparse.banner
|
data/bind_log_analyzer.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["tommaso.visconti@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/tommyblue/Bind-Log-Analyzer"
|
11
11
|
s.summary = %q{Log analysis and SQL storage for Bind DNS server}
|
12
|
-
s.description = %q{BindLogAnalyzer analyzes a Bind query log file and stores
|
12
|
+
s.description = %q{BindLogAnalyzer analyzes a Bind query log file and stores its data into a SQL database using ActiveRecord. It provides a fancy web interface to show some query stats and graphs.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "bind_log_analyzer"
|
15
15
|
|
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
|
86
86
|
<dt class="r2">Includes:</dt>
|
87
|
-
<dd class="r2"><span class='object_link'><a href="Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span></dd>
|
87
|
+
<dd class="r2"><span class='object_link'><a href="Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span>, <span class='object_link'><a href="LogUtils.html" title="BindLogAnalyzer::LogUtils (module)">LogUtils</a></span></dd>
|
88
88
|
|
89
89
|
|
90
90
|
|
@@ -179,7 +179,7 @@
|
|
179
179
|
<li class="public ">
|
180
180
|
<span class="summary_signature">
|
181
181
|
|
182
|
-
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Base) <strong>initialize</strong>(database_params = nil, logfile = nil, setup_database = false, log_level = 0) </a>
|
182
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Base) <strong>initialize</strong>(database_params = nil, logfile = nil, setup_database = false, log_level = 0, check_uniq = false) </a>
|
183
183
|
|
184
184
|
|
185
185
|
|
@@ -288,7 +288,8 @@ setup of the database.</p>
|
|
288
288
|
|
289
289
|
|
290
290
|
<span class="summary_desc"><div class='inline'>
|
291
|
-
<p>Stores the parsed log line into the database
|
291
|
+
<p>Stores the parsed log line into the database and increments @stored_queries
|
292
|
+
if successful.</p>
|
292
293
|
</div></span>
|
293
294
|
|
294
295
|
</li>
|
@@ -306,14 +307,24 @@ setup of the database.</p>
|
|
306
307
|
|
307
308
|
|
308
309
|
<h3 class="inherited">Methods included from <span class='object_link'><a href="Connector.html" title="BindLogAnalyzer::Connector (module)">Connector</a></span></h3>
|
309
|
-
<p class="inherited"><span class='object_link'><a href="Connector.html#connect-class_method" title="BindLogAnalyzer::Connector.connect (method)">connect</a></span>, <span class='object_link'><a href="Connector.html#connected%3F-instance_method" title="BindLogAnalyzer::Connector#connected? (method)">#connected?</a></span>, <span class='object_link'><a href="Connector.html#establish_connection-class_method" title="BindLogAnalyzer::Connector.establish_connection (method)">establish_connection</a></span>, <span class='object_link'><a href="Connector.html#load_environment-instance_method" title="BindLogAnalyzer::Connector#load_environment (method)">#load_environment</a></span>, <span class='object_link'><a href="Connector.html#migrate_tables-instance_method" title="BindLogAnalyzer::Connector#migrate_tables (method)">#migrate_tables</a></span>, <span class='object_link'><a href="Connector.html#
|
310
|
+
<p class="inherited"><span class='object_link'><a href="Connector.html#connect-class_method" title="BindLogAnalyzer::Connector.connect (method)">connect</a></span>, <span class='object_link'><a href="Connector.html#connected%3F-instance_method" title="BindLogAnalyzer::Connector#connected? (method)">#connected?</a></span>, <span class='object_link'><a href="Connector.html#establish_connection-class_method" title="BindLogAnalyzer::Connector.establish_connection (method)">establish_connection</a></span>, <span class='object_link'><a href="Connector.html#load_environment-instance_method" title="BindLogAnalyzer::Connector#load_environment (method)">#load_environment</a></span>, <span class='object_link'><a href="Connector.html#migrate_tables-instance_method" title="BindLogAnalyzer::Connector#migrate_tables (method)">#migrate_tables</a></span>, <span class='object_link'><a href="Connector.html#setup_db-instance_method" title="BindLogAnalyzer::Connector#setup_db (method)">#setup_db</a></span>, <span class='object_link'><a href="Connector.html#setup_db_confs-class_method" title="BindLogAnalyzer::Connector.setup_db_confs (method)">setup_db_confs</a></span></p>
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="LogUtils.html" title="BindLogAnalyzer::LogUtils (module)">LogUtils</a></span></h3>
|
320
|
+
<p class="inherited"><span class='object_link'><a href="LogUtils.html#set_log_level-class_method" title="BindLogAnalyzer::LogUtils.set_log_level (method)">set_log_level</a></span></p>
|
310
321
|
<div id="constructor_details" class="method_details_list">
|
311
322
|
<h2>Constructor Details</h2>
|
312
323
|
|
313
324
|
<div class="method_details first">
|
314
325
|
<p class="signature first" id="initialize-instance_method">
|
315
326
|
|
316
|
-
- (<tt><span class='object_link'><a href="" title="BindLogAnalyzer::Base (class)">Base</a></span></tt>) <strong>initialize</strong>(database_params = nil, logfile = nil, setup_database = false, log_level = 0)
|
327
|
+
- (<tt><span class='object_link'><a href="" title="BindLogAnalyzer::Base (class)">Base</a></span></tt>) <strong>initialize</strong>(database_params = nil, logfile = nil, setup_database = false, log_level = 0, check_uniq = false)
|
317
328
|
|
318
329
|
|
319
330
|
|
@@ -399,6 +410,24 @@ informations</p>
|
|
399
410
|
—
|
400
411
|
<div class='inline'>
|
401
412
|
<p>The level of the log requested by the user</p>
|
413
|
+
</div>
|
414
|
+
|
415
|
+
</li>
|
416
|
+
|
417
|
+
<li>
|
418
|
+
|
419
|
+
<span class='name'>check_uniq</span>
|
420
|
+
|
421
|
+
|
422
|
+
<span class='type'>(<tt>true</tt>, <tt>false</tt>)</span>
|
423
|
+
|
424
|
+
|
425
|
+
<em class="default">(defaults to: <tt>false</tt>)</em>
|
426
|
+
|
427
|
+
|
428
|
+
—
|
429
|
+
<div class='inline'>
|
430
|
+
<p>Checks if a record exists before creating it</p>
|
402
431
|
</div>
|
403
432
|
|
404
433
|
</li>
|
@@ -412,19 +441,27 @@ informations</p>
|
|
412
441
|
<pre class="lines">
|
413
442
|
|
414
443
|
|
415
|
-
19
|
416
|
-
20
|
417
|
-
21
|
418
444
|
22
|
419
|
-
23
|
445
|
+
23
|
446
|
+
24
|
447
|
+
25
|
448
|
+
26
|
449
|
+
27
|
450
|
+
28
|
451
|
+
29
|
452
|
+
30</pre>
|
420
453
|
</td>
|
421
454
|
<td>
|
422
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
455
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 22</span>
|
423
456
|
|
424
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_database_params'>database_params</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_logfile'>logfile</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_setup_database'>setup_database</span> <span class='op'>=</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_log_level'>log_level</span> <span class='op'>=</span> <span class='int'>0</span><span class='rparen'>)</span>
|
457
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_database_params'>database_params</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_logfile'>logfile</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_setup_database'>setup_database</span> <span class='op'>=</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_log_level'>log_level</span> <span class='op'>=</span> <span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_check_uniq'>check_uniq</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
|
425
458
|
<span class='ivar'>@stored_queries</span> <span class='op'>=</span> <span class='int'>0</span>
|
459
|
+
<span class='ivar'>@check_uniq</span> <span class='op'>=</span> <span class='id identifier rubyid_check_uniq'>check_uniq</span>
|
460
|
+
|
461
|
+
<span class='ivar'>@log</span> <span class='op'>=</span> <span class='const'>BindLogAnalyzer</span><span class='op'>::</span><span class='const'>LogUtils</span><span class='period'>.</span><span class='id identifier rubyid_set_log_level'>set_log_level</span><span class='lparen'>(</span><span class='id identifier rubyid_log_level'>log_level</span><span class='rparen'>)</span>
|
462
|
+
|
426
463
|
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_logfile'>logfile</span> <span class='op'>=</span> <span class='id identifier rubyid_logfile'>logfile</span> <span class='kw'>if</span> <span class='id identifier rubyid_logfile'>logfile</span>
|
427
|
-
<span class='id identifier rubyid_setup_db'>setup_db</span><span class='lparen'>(</span><span class='id identifier rubyid_database_params'>database_params</span><span class='comma'>,</span> <span class='id identifier rubyid_setup_database'>setup_database</span><span class='
|
464
|
+
<span class='id identifier rubyid_setup_db'>setup_db</span><span class='lparen'>(</span><span class='id identifier rubyid_database_params'>database_params</span><span class='comma'>,</span> <span class='id identifier rubyid_setup_database'>setup_database</span><span class='rparen'>)</span>
|
428
465
|
<span class='kw'>end</span></pre>
|
429
466
|
</td>
|
430
467
|
</tr>
|
@@ -481,12 +518,12 @@ informations</p>
|
|
481
518
|
<pre class="lines">
|
482
519
|
|
483
520
|
|
484
|
-
|
485
|
-
|
486
|
-
|
521
|
+
14
|
522
|
+
15
|
523
|
+
16</pre>
|
487
524
|
</td>
|
488
525
|
<td>
|
489
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
526
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 14</span>
|
490
527
|
|
491
528
|
<span class='kw'>def</span> <span class='id identifier rubyid_log_filename'>log_filename</span>
|
492
529
|
<span class='ivar'>@log_filename</span>
|
@@ -546,31 +583,35 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
546
583
|
<pre class="lines">
|
547
584
|
|
548
585
|
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
586
|
+
98
|
587
|
+
99
|
588
|
+
100
|
589
|
+
101
|
590
|
+
102
|
591
|
+
103
|
592
|
+
104
|
593
|
+
105
|
594
|
+
106
|
595
|
+
107
|
596
|
+
108
|
597
|
+
109
|
598
|
+
110
|
599
|
+
111
|
600
|
+
112
|
601
|
+
113</pre>
|
563
602
|
</td>
|
564
603
|
<td>
|
565
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
604
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 98</span>
|
566
605
|
|
567
606
|
<span class='kw'>def</span> <span class='id identifier rubyid_analyze'>analyze</span>
|
568
607
|
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='ivar'>@log_filename</span>
|
569
608
|
|
570
609
|
<span class='id identifier rubyid_lines'>lines</span> <span class='op'>=</span> <span class='int'>0</span>
|
571
610
|
<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='ivar'>@log_filename</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_line'>line</span><span class='op'>|</span>
|
611
|
+
<span class='ivar'>@log</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Got line: \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_line'>line</span><span class='rbrace'>}</span><span class='tstring_content'>\"</span><span class='tstring_end'>"</span></span>
|
572
612
|
<span class='id identifier rubyid_query'>query</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse_line'>parse_line</span><span class='lparen'>(</span><span class='id identifier rubyid_line'>line</span><span class='rparen'>)</span>
|
573
613
|
<span class='kw'>if</span> <span class='id identifier rubyid_query'>query</span>
|
614
|
+
<span class='ivar'>@log</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Storing line: \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_query'>query</span><span class='rbrace'>}</span><span class='tstring_content'>\"</span><span class='tstring_end'>"</span></span>
|
574
615
|
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_store_query'>store_query</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
|
575
616
|
<span class='id identifier rubyid_lines'>lines</span> <span class='op'>+=</span> <span class='int'>1</span>
|
576
617
|
<span class='kw'>end</span>
|
@@ -625,12 +666,12 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
625
666
|
<pre class="lines">
|
626
667
|
|
627
668
|
|
628
|
-
|
629
|
-
|
630
|
-
|
669
|
+
44
|
670
|
+
45
|
671
|
+
46</pre>
|
631
672
|
</td>
|
632
673
|
<td>
|
633
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
674
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 44</span>
|
634
675
|
|
635
676
|
<span class='kw'>def</span> <span class='id identifier rubyid_logfile'>logfile</span>
|
636
677
|
<span class='ivar'>@log_filename</span>
|
@@ -684,15 +725,23 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
684
725
|
<pre class="lines">
|
685
726
|
|
686
727
|
|
687
|
-
|
688
|
-
|
689
|
-
|
728
|
+
34
|
729
|
+
35
|
730
|
+
36
|
731
|
+
37
|
732
|
+
38
|
733
|
+
39
|
734
|
+
40</pre>
|
690
735
|
</td>
|
691
736
|
<td>
|
692
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
737
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 34</span>
|
693
738
|
|
694
739
|
<span class='kw'>def</span> <span class='id identifier rubyid_logfile='>logfile=</span><span class='lparen'>(</span><span class='id identifier rubyid_logfile'>logfile</span><span class='rparen'>)</span>
|
695
|
-
<span class='
|
740
|
+
<span class='kw'>if</span> <span class='const'>FileTest</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_logfile'>logfile</span><span class='rparen'>)</span>
|
741
|
+
<span class='ivar'>@log_filename</span> <span class='op'>=</span> <span class='id identifier rubyid_logfile'>logfile</span>
|
742
|
+
<span class='kw'>else</span>
|
743
|
+
<span class='ivar'>@log</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>The provided log file doesn't exist</span><span class='tstring_end'>"</span></span>
|
744
|
+
<span class='kw'>end</span>
|
696
745
|
<span class='kw'>end</span></pre>
|
697
746
|
</td>
|
698
747
|
</tr>
|
@@ -761,17 +810,6 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
761
810
|
<pre class="lines">
|
762
811
|
|
763
812
|
|
764
|
-
40
|
765
|
-
41
|
766
|
-
42
|
767
|
-
43
|
768
|
-
44
|
769
|
-
45
|
770
|
-
46
|
771
|
-
47
|
772
|
-
48
|
773
|
-
49
|
774
|
-
50
|
775
813
|
51
|
776
814
|
52
|
777
815
|
53
|
@@ -781,10 +819,22 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
781
819
|
57
|
782
820
|
58
|
783
821
|
59
|
784
|
-
60
|
822
|
+
60
|
823
|
+
61
|
824
|
+
62
|
825
|
+
63
|
826
|
+
64
|
827
|
+
65
|
828
|
+
66
|
829
|
+
67
|
830
|
+
68
|
831
|
+
69
|
832
|
+
70
|
833
|
+
71
|
834
|
+
72</pre>
|
785
835
|
</td>
|
786
836
|
<td>
|
787
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
837
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 51</span>
|
788
838
|
|
789
839
|
<span class='kw'>def</span> <span class='id identifier rubyid_parse_line'>parse_line</span><span class='lparen'>(</span><span class='id identifier rubyid_line'>line</span><span class='rparen'>)</span>
|
790
840
|
<span class='id identifier rubyid_query'>query</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
@@ -804,6 +854,7 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
804
854
|
|
805
855
|
<span class='id identifier rubyid_query'>query</span>
|
806
856
|
<span class='kw'>else</span>
|
857
|
+
<span class='ivar'>@log</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Can't parse the line: \"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_line'>line</span><span class='rbrace'>}</span><span class='tstring_content'>\"</span><span class='tstring_end'>"</span></span>
|
807
858
|
<span class='kw'>false</span>
|
808
859
|
<span class='kw'>end</span>
|
809
860
|
<span class='kw'>end</span></pre>
|
@@ -822,8 +873,9 @@ and passes wvery line to #parse_line and #store_query</p>
|
|
822
873
|
</p><div class="docstring">
|
823
874
|
<div class="discussion">
|
824
875
|
|
825
|
-
<p>Stores the parsed log line into the database
|
826
|
-
successful
|
876
|
+
<p>Stores the parsed log line into the database and increments @stored_queries
|
877
|
+
if successful. It checks the uniqueness of a record if the @check_uniq
|
878
|
+
flag is set</p>
|
827
879
|
|
828
880
|
|
829
881
|
</div>
|
@@ -857,17 +909,43 @@ successful</p>
|
|
857
909
|
<pre class="lines">
|
858
910
|
|
859
911
|
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
912
|
+
77
|
913
|
+
78
|
914
|
+
79
|
915
|
+
80
|
916
|
+
81
|
917
|
+
82
|
918
|
+
83
|
919
|
+
84
|
920
|
+
85
|
921
|
+
86
|
922
|
+
87
|
923
|
+
88
|
924
|
+
89
|
925
|
+
90
|
926
|
+
91
|
927
|
+
92
|
928
|
+
93</pre>
|
864
929
|
</td>
|
865
930
|
<td>
|
866
|
-
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line
|
931
|
+
<pre class="code"><span class="info file"># File 'lib/bind_log_analyzer/base.rb', line 77</span>
|
867
932
|
|
868
933
|
<span class='kw'>def</span> <span class='id identifier rubyid_store_query'>store_query</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
|
869
|
-
<span class='
|
870
|
-
|
934
|
+
<span class='kw'>if</span> <span class='ivar'>@check_uniq</span>
|
935
|
+
<span class='kw'>unless</span> <span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
|
936
|
+
<span class='id identifier rubyid_log'>log</span> <span class='op'>=</span> <span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:date</span> <span class='op'>=></span> <span class='id identifier rubyid_query'>query</span><span class='lbracket'>[</span><span class='symbol'>:date</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
937
|
+
<span class='ivar'>@stored_queries</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='kw'>if</span> <span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span>
|
938
|
+
<span class='kw'>else</span>
|
939
|
+
<span class='ivar'>@log</span><span class='period'>.</span><span class='id identifier rubyid_warn'>warn</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Skipping duplicate entry: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_query'>query</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
940
|
+
<span class='kw'>end</span>
|
941
|
+
<span class='kw'>else</span>
|
942
|
+
<span class='id identifier rubyid_log'>log</span> <span class='op'>=</span> <span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
|
943
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span>
|
944
|
+
<span class='ivar'>@stored_queries</span> <span class='op'>+=</span> <span class='int'>1</span>
|
945
|
+
<span class='kw'>else</span>
|
946
|
+
<span class='ivar'>@log</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Error saving the log </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_query'>query</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
947
|
+
<span class='kw'>end</span>
|
948
|
+
<span class='kw'>end</span>
|
871
949
|
<span class='kw'>end</span></pre>
|
872
950
|
</td>
|
873
951
|
</tr>
|
@@ -879,7 +957,7 @@ successful</p>
|
|
879
957
|
</div>
|
880
958
|
|
881
959
|
<div id="footer">
|
882
|
-
Generated on
|
960
|
+
Generated on Tue Apr 10 16:12:42 2012 by
|
883
961
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
884
962
|
0.7.5 (ruby-1.9.3).
|
885
963
|
</div>
|