clarity 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +37 -0
- data/PostInstall.txt +8 -0
- data/README.rdoc +56 -0
- data/Rakefile +27 -0
- data/bin/clarity +10 -0
- data/config/config.yml.sample +7 -0
- data/lib/clarity.rb +20 -0
- data/lib/clarity/cli.rb +80 -0
- data/lib/clarity/commands/command_builder.rb +56 -0
- data/lib/clarity/commands/tail_command_builder.rb +27 -0
- data/lib/clarity/parsers/hostname_parser.rb +43 -0
- data/lib/clarity/parsers/shop_parser.rb +48 -0
- data/lib/clarity/parsers/time_parser.rb +93 -0
- data/lib/clarity/renderers/log_renderer.rb +47 -0
- data/lib/clarity/server.rb +143 -0
- data/lib/clarity/server/basic_auth.rb +24 -0
- data/lib/clarity/server/chunk_http.rb +57 -0
- data/lib/clarity/server/mime_types.rb +23 -0
- data/public/images/spinner_big.gif +0 -0
- data/public/javascripts/app.js +154 -0
- data/public/stylesheets/app.css +54 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/commands/command_builder_test.rb +100 -0
- data/test/commands/tail_command_builder_test.rb +43 -0
- data/test/files/logfile.log +17 -0
- data/test/parsers/hostname_parser_test.rb +40 -0
- data/test/parsers/shop_parser_test.rb +54 -0
- data/test/parsers/time_parser_test.rb +84 -0
- data/test/test_helper.rb +3 -0
- data/test/test_string_scanner.rb +17 -0
- data/views/_header.html.erb +5 -0
- data/views/_toolbar.html.erb +89 -0
- data/views/error.html.erb +11 -0
- data/views/index.html.erb +9 -0
- metadata +134 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
/* ----------------------------------------------------------------------------
|
2
|
+
* Log Search Server CSS
|
3
|
+
* by John Tajima
|
4
|
+
* ----------------------------------------------------------------------------
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* 960 reset */
|
8
|
+
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outline:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
|
9
|
+
/* 960 text */
|
10
|
+
body{font:13px/1.5 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif}a:focus{outline:1px dotted invert}hr{border:0 #ccc solid;border-top-width:1px;clear:both;height:0}h1{font-size:25px}h2{font-size:23px}h3{font-size:21px}h4{font-size:19px}h5{font-size:17px}h6{font-size:15px}ol{list-style:decimal}ul{list-style:disc}li{margin-left:30px}p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset{margin-bottom:20px}
|
11
|
+
|
12
|
+
/*
|
13
|
+
* Toolbar Styling
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
#toolbar { color: #333; font-size: 12px; min-width: 980px; height: 130px;
|
19
|
+
padding: 0 10px; background: #f0f0f0; border-bottom: 2px solid #000;
|
20
|
+
position:fixed; top: 0; margin: 0 -10px; width: 100%;
|
21
|
+
font-family: 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif;
|
22
|
+
}
|
23
|
+
#toolbar a { color: blue; background: none; }
|
24
|
+
#toolbar a:hover { background: none; }
|
25
|
+
|
26
|
+
#toolbar #header { height: 20px; padding: 3px 5px; margin: 0 -10px 10px; overflow:hidden; background: #333; border-bottom: 2px solid #222; color: #eee; }
|
27
|
+
#toolbar #header h1 { font-size: 16px; line-height: 20px; }
|
28
|
+
#toolbar #header a { text-decoration: none; color: #eee; }
|
29
|
+
#toolbar #header a:hover { text-decoration: none; color: #fff;}
|
30
|
+
#toolbar .small { font-size: 11px; color: #333; font-weight: bold;}
|
31
|
+
#toolbar input.time { width: 20px;}
|
32
|
+
|
33
|
+
table.actions { width: auto; border-collapse: collapse; }
|
34
|
+
table.actions th { font-size: 11px; color: #333; text-align: left; min-width: 100px; padding: 0 5px; }
|
35
|
+
table.actions td { padding: 2px 5px; text-align: left; vertical-align: middle;}
|
36
|
+
table.actions span.note { font-weight: normal; color: #999; }
|
37
|
+
table.actions span.and { font-size: 11px; color: red; font-weight: bold; }
|
38
|
+
table.actions span.label { font-weight: bold; cursor:pointer;}
|
39
|
+
table.actions input[type=text] { width: 200px; padding: 2px; border: 1px solid #aaa;}
|
40
|
+
|
41
|
+
|
42
|
+
div#option-ctrl { position: fixed; z-index: 100; bottom: 0; right: 0; min-width: 60px; min-height: 20px; height: 20px; padding: 5px; border: 1px solid #ddd; background: #f0f0f0; font-size: 11px; color: #000;
|
43
|
+
font-family: 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif; }
|
44
|
+
div#option-ctrl ul { list-style:none; margin: 0; padding: 0;}
|
45
|
+
div#option-ctrl ul li { list-style:none; margin: 0 5px 0 0; float:left; }
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
/* output */
|
50
|
+
body { margin: 10px; padding-top: 130px; font-family: 'Monaco', 'Deja Vu Sans Mono', 'Inconsolata' ,'Consolas',monospace; background:#111 none repeat scroll 0 0; color:#fff; font-size:10px;}
|
51
|
+
a { color: #0f0; }
|
52
|
+
a:hover { background-color: #03c; color: white; text-decoration: none; }
|
53
|
+
|
54
|
+
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/clarity.rb'}"
|
9
|
+
puts "Loading clarity gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../../lib/commands/command_builder.rb"
|
3
|
+
|
4
|
+
class CommandBuilderTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@params = {
|
8
|
+
"file" => "testfile.log",
|
9
|
+
"tool" => "grep",
|
10
|
+
"term1" => "foo",
|
11
|
+
"term2" => nil,
|
12
|
+
"term3" => nil
|
13
|
+
}
|
14
|
+
@command = CommandBuilder.new(@params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_new_builder
|
18
|
+
assert @command.is_a?(CommandBuilder)
|
19
|
+
assert_equal "testfile.log", @command.filename
|
20
|
+
assert_equal 1, @command.terms.size
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_raises_error_if_no_file
|
24
|
+
assert_raises CommandBuilder::InvalidParameterError do
|
25
|
+
command = CommandBuilder.new(@params.merge("file" => nil))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_exec_functions_for_log
|
30
|
+
command = CommandBuilder.new(@params)
|
31
|
+
assert_equal 1, command.exec_functions.size
|
32
|
+
assert_match /^grep/, command.exec_functions.first
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_exec_functions_with_multiple_terms_for_log
|
36
|
+
command = CommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
|
37
|
+
assert_equal 3, command.exec_functions.size
|
38
|
+
assert_match /^grep/, command.exec_functions[0]
|
39
|
+
assert_match /^grep/, command.exec_functions[1]
|
40
|
+
assert_match /^grep/, command.exec_functions[2]
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_exec_function_with_no_terms_for_log
|
44
|
+
command = CommandBuilder.new(@params.merge("term1" => nil))
|
45
|
+
assert_equal 1, command.exec_functions.size
|
46
|
+
assert_match /^cat/, command.exec_functions[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_exec_funcations_for_gzip
|
50
|
+
command = CommandBuilder.new(@params.merge("file" => "testfile.gz"))
|
51
|
+
assert_equal 1, command.exec_functions.size
|
52
|
+
assert_match /^zgrep/, command.exec_functions.first
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_exec_functions_with_multiple_terms_for_gzip
|
56
|
+
command = CommandBuilder.new(@params.merge("file" => "testfile.gz", "term2" => "bar", "term3" => "baz"))
|
57
|
+
assert_equal 3, command.exec_functions.size
|
58
|
+
assert_match /^zgrep/, command.exec_functions[0]
|
59
|
+
assert_match /^grep/, command.exec_functions[1]
|
60
|
+
assert_match /^grep/, command.exec_functions[2]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_exec_function_with_no_terms_for_gzip
|
64
|
+
command = CommandBuilder.new(@params.merge("file" => "testfile.gz", "term1" => nil))
|
65
|
+
assert_equal 1, command.exec_functions.size
|
66
|
+
assert_match "gzcat", command.exec_functions[0]
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_command_for_log
|
70
|
+
command = CommandBuilder.new(@params)
|
71
|
+
assert_equal "sh -c 'grep -e foo testfile.log'", command.command
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_command_with_no_terms_for_log
|
75
|
+
command = CommandBuilder.new(@params.merge("term1" => nil))
|
76
|
+
assert_equal "sh -c 'cat testfile.log'", command.command
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_command_with_multiple_terms_for_log
|
80
|
+
command = CommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
|
81
|
+
assert_equal "sh -c 'grep -e foo testfile.log | grep -e bar | grep -e baz'", command.command
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_command_for_gzip
|
85
|
+
command = CommandBuilder.new(@params.merge("file" => "testfile.gz"))
|
86
|
+
assert_equal "sh -c 'zgrep -e foo testfile.gz'", command.command
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_command_with_no_terms_for_gzip
|
90
|
+
command = CommandBuilder.new(@params.merge("file" => "testfile.gz","term1" => nil))
|
91
|
+
assert_equal "sh -c 'gzcat testfile.gz'", command.command
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_command_with_multiple_terms_for_gzip
|
95
|
+
command = CommandBuilder.new(@params.merge("file" => "testfile.gz","term2" => "bar", "term3" => "baz"))
|
96
|
+
assert_equal "sh -c 'zgrep -e foo testfile.gz | grep -e bar | grep -e baz'", command.command
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../../lib/commands/tail_command_builder.rb"
|
3
|
+
|
4
|
+
class TailCommandBuilderTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@params = {
|
8
|
+
"file" => "testfile.log",
|
9
|
+
"tool" => "tail",
|
10
|
+
"term1" => "foo",
|
11
|
+
"term2" => nil,
|
12
|
+
"term3" => nil
|
13
|
+
}
|
14
|
+
@command = TailCommandBuilder.new(@params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_new_builder
|
18
|
+
assert @command.is_a?(TailCommandBuilder)
|
19
|
+
assert_equal "testfile.log", @command.filename
|
20
|
+
assert_equal 1, @command.terms.size
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_raises_error_if_invalid_file
|
24
|
+
assert_raises CommandBuilder::InvalidParameterError do
|
25
|
+
command = TailCommandBuilder.new(@params.merge("file" => "testfile.gz"))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_command_for_log
|
30
|
+
command = TailCommandBuilder.new(@params)
|
31
|
+
assert_equal "sh -c 'tail -n 250 -f testfile.log | grep -e foo'", command.command
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_command_with_no_terms_for_log
|
35
|
+
command = TailCommandBuilder.new(@params.merge("term1" => nil))
|
36
|
+
assert_equal "sh -c 'tail -n 250 -f testfile.log'", command.command
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_command_with_multiple_terms_for_log
|
40
|
+
command = TailCommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
|
41
|
+
assert_equal "sh -c 'tail -n 250 -f testfile.log | grep -e foo | grep -e bar | grep -e baz'", command.command
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Jul 7 20:12:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Processing Admin::ProductsController#index (for 67.70.29.242 at 2009-07-07 20:12:11) [GET]
|
2
|
+
Jul 7 20:12:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Parameters: {"action"=>"index", "controller"=>"admin/products"}
|
3
|
+
Jul 7 20:12:12 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Shop Load (44.5ms) SELECT shops.* FROM shops JOIN domains ON domains.host = 'jessetesting.staging.shopify.com' AND domains.shop_id = shops.id LIMIT 1
|
4
|
+
Jul 7 20:12:12 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Subscription Columns (1.4ms) SHOW FIELDS FROM `subscriptions`
|
5
|
+
Jul 7 20:12:12 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Subscription Load (11.3ms) SELECT * FROM `subscriptions` WHERE (`subscriptions`.`id` = 500852)
|
6
|
+
Jul 7 20:12:13 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Redirected to http://jessetesting.staging.shopify.com/admin/auth/login
|
7
|
+
Jul 7 20:12:13 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Filter chain halted as [:ensure_proper_user] rendered_or_redirected.
|
8
|
+
Jul 7 20:12:13 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Completed in 118ms (DB: 57) | 302 Found [http://jessetesting.staging.shopify.com/admin/products]
|
9
|
+
Jul 7 20:20:00 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Processing Admin::AuthController#login (for 67.70.29.242 at 2009-07-07 20:12:11) [GET]
|
10
|
+
Jul 7 20:20:00 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Parameters: {"action"=>"login", "controller"=>"admin/auth"}
|
11
|
+
Jul 7 20:30:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Shop Load (0.2ms) SELECT shops.* FROM shops JOIN domains ON domains.host = 'jessetesting.staging.shopify.com' AND domains.shop_id = shops.id LIMIT 1
|
12
|
+
Jul 7 20:40:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Rendering template within layouts/admin/auth
|
13
|
+
Jul 7 20:50:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Rendering admin/auth/login
|
14
|
+
Jul 7 21:00:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Completed in 17ms (View: 10, DB: 0) | 200 OK [http://jessetesting.staging.shopify.com/admin/auth/login]
|
15
|
+
Jul 7 22:12:11 10.1.1.1 rails.shopify[27975]: [john.staging.shopify.com] Processing Admin::ProductsController#index (for 67.70.29.242 at 2009-07-07 20:12:11) [GET]
|
16
|
+
Jul 7 22:12:11 192.168.5.1 rails.shopify[27975]: [john.staging.shopify.com] Processing Admin::ProductsController#index (for 67.70.29.242 at 2009-07-07 20:12:11) [GET]
|
17
|
+
Jul 7 22:12:11 192.168.5.1 rails.shopify[27975]: [john.staging.shopify.com] Processing Admin::ProductsController#index (for 67.70.29.242 at 2009-07-07 20:12:11) [GET]
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../../lib/parsers/hostname_parser.rb"
|
3
|
+
|
4
|
+
class HostnameParserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@params = { "sh" => "12", "sm" => "00", "ss" => "10", "eh" => "12", "em" => "00", "es" => "59" }
|
8
|
+
@lines = %|Jul 24 14:58:21 app3 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
9
|
+
Jul 24 12:00:21 192.168.5.1 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
10
|
+
Jul 24 12:00:31 192.168.5.1 rails.shopify[9855]: [test.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
11
|
+
Jul 24 12:00:41 192.168.5.1 rails.shopify[9855]: [test2.myshopify.com] Processing some other line of text
|
12
|
+
|.split("\n")
|
13
|
+
@parser = HostnameParser.new(nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_parse_strips_out_ip_and_appname
|
18
|
+
line = @lines[1][16..-1] # strip out first 16 lines
|
19
|
+
out = @parser.parse(line)
|
20
|
+
|
21
|
+
assert out.has_key?(:line)
|
22
|
+
assert_equal "[wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]", out[:line]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse_strips_out_host_and_appname
|
26
|
+
line = @lines.first[16..-1] # strip out first 16 lines
|
27
|
+
out = @parser.parse(line)
|
28
|
+
|
29
|
+
assert out.has_key?(:line)
|
30
|
+
assert_equal "[wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]", out[:line]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_parse_returns_line_if_no_match
|
34
|
+
line = "in@valid rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]"
|
35
|
+
out = @parser.parse(line)
|
36
|
+
assert out.has_key?(:line)
|
37
|
+
assert_equal line, out[:line]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../../lib/parsers/shop_parser.rb"
|
3
|
+
|
4
|
+
class ShopParserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@parser = ShopParser.new(nil)
|
8
|
+
@lines = %|[wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
9
|
+
[wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
10
|
+
[test.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
11
|
+
[my-shop.myshopify.com] Processing some other line of text
|
12
|
+
Jul 7 20:12:11 staging rails.shopify[27975]: [jessetesting.staging.shopify.com] Processing Admin::ProductsController#index (for 67.70.29.242 at 2009-07-07 20:12:11) [GET]
|
13
|
+
|.split("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_parse_shop_name
|
17
|
+
line = @lines.first
|
18
|
+
out = @parser.parse(line)
|
19
|
+
|
20
|
+
assert out.has_key?(:shop)
|
21
|
+
assert out.has_key?(:line)
|
22
|
+
assert_equal "wadedemt.myshopify.com", out[:shop]
|
23
|
+
assert_equal "Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]", out[:line]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_parse_shop_name_with_extra_space
|
27
|
+
line = @lines[1]
|
28
|
+
out = @parser.parse(line)
|
29
|
+
|
30
|
+
assert out.has_key?(:shop)
|
31
|
+
assert out.has_key?(:line)
|
32
|
+
assert_equal "wadedemt.myshopify.com", out[:shop]
|
33
|
+
assert_equal "Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]", out[:line]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_parse_shop_name_with_dashes
|
37
|
+
line = @lines[3]
|
38
|
+
out = @parser.parse(line)
|
39
|
+
|
40
|
+
assert out.has_key?(:shop)
|
41
|
+
assert out.has_key?(:line)
|
42
|
+
assert_equal "my-shop.myshopify.com", out[:shop]
|
43
|
+
assert_equal "Processing some other line of text", out[:line]
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_parse_with_no_shop_returns_line
|
47
|
+
line = @lines[4]
|
48
|
+
out = @parser.parse(line)
|
49
|
+
assert !out.has_key?(:shop)
|
50
|
+
assert_equal line, out[:line]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require File.dirname(__FILE__) + "/../../lib/parsers/time_parser.rb"
|
3
|
+
|
4
|
+
class TimeParserTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@params = { "sh" => "12", "sm" => "00", "ss" => "10", "eh" => "12", "em" => "00", "es" => "59" }
|
8
|
+
@lines = %|Jul 24 14:58:21 app3 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
9
|
+
Jul 24 12:00:21 192.168.5.1 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
10
|
+
Jul 24 12:00:31 192.168.5.1 rails.shopify[9855]: [test.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]
|
11
|
+
Jul 24 12:00:41 192.168.5.1 rails.shopify[9855]: [test2.myshopify.com] Processing some other line of text
|
12
|
+
|.split("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_parse_timestamp
|
16
|
+
@parser = TimeParser.new(nil, {})
|
17
|
+
line = @lines.first
|
18
|
+
elements = @parser.parse(line)
|
19
|
+
|
20
|
+
assert elements.has_key?(:timestamp)
|
21
|
+
assert_equal "Jul 24 14:58:21", elements[:timestamp]
|
22
|
+
assert_equal "app3 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET]", elements[:line]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse_with_start_time_and_early_timestamp
|
26
|
+
@parser = TimeParser.new(nil, {"sh" => "15", "sm" => "00", "ss" => "10"})
|
27
|
+
line = @lines.first
|
28
|
+
elements = @parser.parse(line)
|
29
|
+
|
30
|
+
# does not match - reject line all together
|
31
|
+
assert elements.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_parse_with_start_time_and_later_timestamp
|
35
|
+
@parser = TimeParser.new(nil, {"sh" => "12", "sm" => "00", "ss" => "10"})
|
36
|
+
line = @lines[1]
|
37
|
+
elements = @parser.parse(line)
|
38
|
+
|
39
|
+
assert elements.has_key?(:timestamp)
|
40
|
+
assert elements.has_key?(:line)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_parse_with_end_time_and_early_timestamp
|
44
|
+
@parser = TimeParser.new(nil, {"eh" => "12", "em" => "00", "es" => "00"})
|
45
|
+
line = @lines.first
|
46
|
+
elements = @parser.parse(line)
|
47
|
+
|
48
|
+
assert elements.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_parse_with_end_time_and_later_timestamp
|
52
|
+
@parser = TimeParser.new(nil, {"eh" => "13", "em" => "00", "es" => "00"})
|
53
|
+
line = @lines[1]
|
54
|
+
elements = @parser.parse(line)
|
55
|
+
|
56
|
+
assert elements.has_key?(:timestamp)
|
57
|
+
assert elements.has_key?(:line)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_parse_with_entry_between_start_and_end
|
61
|
+
@parser = TimeParser.new(nil, {"sh" => "14", "sm" => "00", "ss" => "00", "eh" => "15", "em" => "00", "es" => "00"})
|
62
|
+
line = @lines.first
|
63
|
+
elements = @parser.parse(line)
|
64
|
+
|
65
|
+
assert elements.has_key?(:timestamp)
|
66
|
+
assert elements.has_key?(:line)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_parse_with_entry_outside_start_and_end
|
70
|
+
@parser = TimeParser.new(nil, {"sh" => "14", "sm" => "00", "ss" => "00", "eh" => "15", "em" => "00", "es" => "00"})
|
71
|
+
line = @lines[1]
|
72
|
+
elements = @parser.parse(line)
|
73
|
+
|
74
|
+
assert elements.empty?
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_parse_returns_entry_if_doesnt_match_parser
|
78
|
+
line = "July 24, 1999 12:00:21 192.168.5.1 rails.shopify[9855]: [wadedemt.myshopify.com] Processing ShopController#products (for 192.168.1.230 at 2009-07-24 14:58:21) [GET] "
|
79
|
+
@parser = TimeParser.new(nil)
|
80
|
+
elements = @parser.parse(line)
|
81
|
+
assert_equal line, elements[:line]
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
data/test/test_helper.rb
ADDED