jls-grok 0.1.2787 → 0.1.2821
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.
- data/ext/Makefile +2 -2
- data/ext/extconf.rb +2 -3
- data/ext/rgrok.h +3 -3
- data/ext/ruby_grok.c +11 -1
- data/ext/ruby_grokdiscover.c +54 -0
- data/lib/grok.rb +13 -0
- data/test/alltests.rb +2 -0
- data/test/patterns/day.rb +22 -0
- data/test/patterns/ip.rb +1 -2
- data/test/patterns/month.rb +3 -4
- data/test/patterns/number.rb +1 -2
- data/test/patterns/path.rb +3 -4
- data/test/patterns/uri.rb +6 -4
- data/test/speedtest.rb +24 -23
- metadata +4 -7
- data/ext/Grok.so +0 -0
- data/ext/mkmf.log +0 -54
- data/ext/ruby_grok.o +0 -0
- data/ext/ruby_grokmatch.o +0 -0
- data/test/GDB_COMMAND +0 -29
data/ext/Makefile
CHANGED
@@ -87,8 +87,8 @@ extout_prefix =
|
|
87
87
|
target_prefix =
|
88
88
|
LOCAL_LIBS =
|
89
89
|
LIBS = $(LIBRUBYARG_SHARED) -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc
|
90
|
-
SRCS = ruby_grok.c ruby_grokmatch.c
|
91
|
-
OBJS = ruby_grok.o ruby_grokmatch.o
|
90
|
+
SRCS = ruby_grok.c ruby_grokmatch.c ruby_grokdiscover.c
|
91
|
+
OBJS = ruby_grok.o ruby_grokmatch.o ruby_grokdiscover.o
|
92
92
|
TARGET = Grok
|
93
93
|
DLLIB = $(TARGET).so
|
94
94
|
EXTSTATIC =
|
data/ext/extconf.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "mkmf"
|
2
2
|
find_header("tcutil.h", "/usr/local/include")
|
3
3
|
find_header("pcre.h", "/usr/local/include")
|
4
|
-
find_header("grok.h", "
|
5
|
-
find_library("grok", "grok_init", "../")
|
6
|
-
|
4
|
+
find_header("grok.h", "/usr/local/include", "../../")
|
5
|
+
find_library("grok", "grok_init", "../", "/usr/local/lib")
|
7
6
|
create_makefile("Grok")
|
data/ext/rgrok.h
CHANGED
data/ext/ruby_grok.c
CHANGED
@@ -6,14 +6,16 @@
|
|
6
6
|
VALUE cGrok; /* Grok class object */
|
7
7
|
|
8
8
|
extern VALUE cGrokMatch;
|
9
|
+
extern VALUE cGrokDiscover;
|
9
10
|
extern void Init_GrokMatch();
|
11
|
+
extern void Init_GrokDiscover();
|
10
12
|
|
11
13
|
static VALUE rGrok_initialize(VALUE self) {
|
12
14
|
/* empty */
|
13
15
|
return Qnil;
|
14
16
|
}
|
15
17
|
|
16
|
-
|
18
|
+
void rGrok_free(void *p) {
|
17
19
|
grok_t *grok = (grok_t *)p;
|
18
20
|
|
19
21
|
/* we strdup our pattern from ruby and rb_str2cstr */
|
@@ -35,6 +37,13 @@ VALUE rGrok_new(VALUE klass) {
|
|
35
37
|
return rgrok;
|
36
38
|
}
|
37
39
|
|
40
|
+
VALUE rGrok_new_from_grok(grok_t *grok) {
|
41
|
+
VALUE rgrok;
|
42
|
+
rgrok = Data_Wrap_Struct(cGrok, 0, rGrok_free, grok);
|
43
|
+
rb_obj_call_init(rgrok, 0, 0);
|
44
|
+
return rgrok;
|
45
|
+
}
|
46
|
+
|
38
47
|
VALUE rGrok_compile(VALUE self, VALUE pattern) {
|
39
48
|
grok_t *grok;
|
40
49
|
char *c_pattern = NULL;
|
@@ -187,4 +196,5 @@ void Init_Grok() {
|
|
187
196
|
rb_define_method(cGrok, "patterns", rGrok_patterns, 0);
|
188
197
|
|
189
198
|
Init_GrokMatch();
|
199
|
+
Init_GrokDiscover();
|
190
200
|
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#include "rgrok.h"
|
2
|
+
#include <grok.h>
|
3
|
+
|
4
|
+
VALUE cGrokDiscover;
|
5
|
+
extern VALUE cGrok;
|
6
|
+
|
7
|
+
static void rGrokDiscover_free(void *p);
|
8
|
+
|
9
|
+
VALUE rGrokDiscover_new(VALUE klass, VALUE grok) {
|
10
|
+
VALUE rgd;
|
11
|
+
grok_discover_t *gdt = ALLOC(grok_discover_t); //grok_discover_new();
|
12
|
+
rgd = Data_Wrap_Struct(klass, 0, rGrokDiscover_free, gdt);
|
13
|
+
|
14
|
+
VALUE initargs[1] = { grok };
|
15
|
+
rb_obj_call_init(rgd, 1, initargs);
|
16
|
+
return (VALUE)rgd;
|
17
|
+
}
|
18
|
+
|
19
|
+
static void rGrokDiscover_free(void *p) {
|
20
|
+
grok_discover_t *gdt = p;
|
21
|
+
grok_discover_free(gdt);
|
22
|
+
}
|
23
|
+
|
24
|
+
VALUE rGrokDiscover_initialize(VALUE self, VALUE rb_grok) {
|
25
|
+
grok_discover_t *gdt;
|
26
|
+
grok_t *grok;
|
27
|
+
Data_Get_Struct(self, grok_discover_t, gdt);
|
28
|
+
Data_Get_Struct(rb_grok, grok_t, grok);
|
29
|
+
|
30
|
+
grok_discover_init(gdt, grok);
|
31
|
+
return Qnil;
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
VALUE rGrokDiscover_discover(VALUE self, VALUE input) {
|
36
|
+
char *cstr_discovery;
|
37
|
+
char *cstr_input;
|
38
|
+
long unused_input_len;
|
39
|
+
int discovery_len;
|
40
|
+
grok_discover_t *gdt;
|
41
|
+
grok_t *grok;
|
42
|
+
|
43
|
+
Data_Get_Struct(self, grok_discover_t, gdt);
|
44
|
+
cstr_input = rb_str2cstr(input, &unused_input_len);
|
45
|
+
grok_discover(gdt, cstr_input, &cstr_discovery, &discovery_len);
|
46
|
+
return rb_str_new(cstr_discovery, discovery_len);
|
47
|
+
}
|
48
|
+
|
49
|
+
void Init_GrokDiscover() {
|
50
|
+
cGrokDiscover = rb_define_class("GrokDiscover", rb_cObject);
|
51
|
+
rb_define_singleton_method(cGrokDiscover, "new", rGrokDiscover_new, 1);
|
52
|
+
rb_define_method(cGrokDiscover, "initialize", rGrokDiscover_initialize, 1);
|
53
|
+
rb_define_method(cGrokDiscover, "discover", rGrokDiscover_discover, 1);
|
54
|
+
}
|
data/lib/grok.rb
CHANGED
@@ -1 +1,14 @@
|
|
1
1
|
require "Grok"
|
2
|
+
|
3
|
+
# extend Grok to add simpler access to the discover feature.
|
4
|
+
class Grok
|
5
|
+
def discover(input)
|
6
|
+
init_discover if @discover == nil
|
7
|
+
|
8
|
+
return @discover.discover(input)
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_discover
|
12
|
+
@discover = GrokDiscover.new(self)
|
13
|
+
end
|
14
|
+
end
|
data/test/alltests.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'grok'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class DayPatternsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@grok = Grok.new
|
7
|
+
path = "#{File.dirname(__FILE__)}/../../../patterns/base"
|
8
|
+
@grok.add_patterns_from_file(path)
|
9
|
+
@grok.compile("%{DAY}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_days
|
13
|
+
days = %w{Mon Monday Tue Tuesday Wed Wednesday Thu Thursday Fri Friday
|
14
|
+
Sat Saturday Sun Sunday}
|
15
|
+
days.each do |day|
|
16
|
+
match = @grok.match(day)
|
17
|
+
assert_not_equal(false, day, "Expected #{day} to match.")
|
18
|
+
assert_equal(day, match.captures["DAY"][0])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/test/patterns/ip.rb
CHANGED
data/test/patterns/month.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'Grok'
|
1
|
+
require 'grok'
|
3
2
|
require 'test/unit'
|
4
3
|
|
5
4
|
class MonthPatternsTest < Test::Unit::TestCase
|
@@ -10,14 +9,14 @@ class MonthPatternsTest < Test::Unit::TestCase
|
|
10
9
|
@grok.compile("%{MONTH}")
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
12
|
+
def test_months
|
14
13
|
months = ["Jan", "January", "Feb", "February", "Mar", "March", "Apr",
|
15
14
|
"April", "May", "Jun", "June", "Jul", "July", "Aug", "August",
|
16
15
|
"Sep", "September", "Oct", "October", "Nov", "November", "Dec",
|
17
16
|
"December"]
|
18
17
|
months.each do |month|
|
19
18
|
match = @grok.match(month)
|
20
|
-
assert_not_equal(false, match)
|
19
|
+
assert_not_equal(false, match, "Expected #{month} to match")
|
21
20
|
assert_equal(month, match.captures["MONTH"][0])
|
22
21
|
end
|
23
22
|
end
|
data/test/patterns/number.rb
CHANGED
data/test/patterns/path.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'Grok'
|
1
|
+
require 'grok'
|
3
2
|
require 'test/unit'
|
4
3
|
|
5
4
|
class PathPatternsTest < Test::Unit::TestCase
|
@@ -21,11 +20,11 @@ class PathPatternsTest < Test::Unit::TestCase
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def test_windows_paths
|
24
|
-
paths = %w{C:\WINDOWS
|
23
|
+
paths = %w{C:\WINDOWS \\\\Foo\bar \\\\1.2.3.4\C$ \\\\some\path\here.exe}
|
25
24
|
paths << "C:\\Documents and Settings\\"
|
26
25
|
paths.each do |path|
|
27
26
|
match = @grok.match(path)
|
28
|
-
assert_not_equal(false, match)
|
27
|
+
assert_not_equal(false, match, "Expected #{path} to match, but it didn't.")
|
29
28
|
assert_equal(path, match.captures["PATH"][0])
|
30
29
|
end
|
31
30
|
end
|
data/test/patterns/uri.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'Grok'
|
1
|
+
require 'grok'
|
3
2
|
require 'test/unit'
|
4
3
|
|
5
4
|
class URIPatternsTest < Test::Unit::TestCase
|
@@ -31,12 +30,15 @@ class URIPatternsTest < Test::Unit::TestCase
|
|
31
30
|
"foo://user@somehost.com:12345/foo.bar/baz/fizz",
|
32
31
|
"foo://user@somehost.com:12345/foo.bar/baz/fizz?test",
|
33
32
|
"foo://user@somehost.com:12345/foo.bar/baz/fizz?test=1&sink&foo=4",
|
34
|
-
"http://www.google.com/search?hl=en&source=hp&q=hello+world+%5E%40%23%24&btnG=Google+Search"
|
33
|
+
"http://www.google.com/search?hl=en&source=hp&q=hello+world+%5E%40%23%24&btnG=Google+Search",
|
34
|
+
"http://www.freebsd.org/cgi/url.cgi?ports/sysutils/grok/pkg-descr",
|
35
|
+
"http://www.google.com/search?q=CAPTCHA+ssh&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official",
|
36
|
+
"svn+ssh://somehost:12345/testing",
|
35
37
|
]
|
36
38
|
|
37
39
|
urls.each do |url|
|
38
40
|
match = @grok.match(url)
|
39
|
-
assert_not_equal(false, match)
|
41
|
+
assert_not_equal(false, match, "Expected this to match: #{url}")
|
40
42
|
assert_equal(url, match.captures["URI"][0])
|
41
43
|
end
|
42
44
|
end
|
data/test/speedtest.rb
CHANGED
@@ -7,24 +7,24 @@ require 'pp'
|
|
7
7
|
|
8
8
|
#RubyProf.start
|
9
9
|
|
10
|
-
iterations =
|
10
|
+
iterations = 20000
|
11
11
|
pattern = "[A-z0-9_-]*\\[[0-9]+\\]"
|
12
12
|
|
13
13
|
grok = Grok.new
|
14
|
-
grok.
|
15
|
-
grok.compile("%{
|
14
|
+
grok.add_patterns_from_file("../../patterns/base")
|
15
|
+
grok.compile("%{COMBINEDAPACHELOG}")
|
16
16
|
|
17
|
-
rubyre = Regexp.new("(?<foo>#{pattern})")
|
17
|
+
#rubyre = Regexp.new("(?<foo>#{pattern})")
|
18
18
|
#rubyre = Regexp.new(pattern)
|
19
19
|
|
20
20
|
matches = { :grok => 0, :rubyre => 0 }
|
21
|
+
failures = { :grok => 0, :rubyre => 0 }
|
21
22
|
def time(iterations, &block)
|
22
23
|
start = Time.now
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
24
|
+
file = File.open("/b/logs/access")
|
25
|
+
data = (1 .. iterations).collect { file.readline() }
|
26
|
+
data.each do |line|
|
27
|
+
block.call(line)
|
28
28
|
end
|
29
29
|
return Time.now - start
|
30
30
|
end
|
@@ -34,23 +34,24 @@ groktime = time(iterations) do |line|
|
|
34
34
|
if m
|
35
35
|
matches[:grok] += 1
|
36
36
|
m.captures["FOO"]
|
37
|
+
else
|
38
|
+
puts line
|
39
|
+
failures[:grok] +=1
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
|
-
rubyretime = time(iterations) do |line|
|
41
|
-
m = rubyre.match(line)
|
42
|
-
if m
|
43
|
-
matches[:rubyre] += 1
|
44
|
-
m["foo"]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
puts "Grok: #{groktime}"
|
49
|
-
puts
|
50
|
-
puts
|
43
|
+
#rubyretime = time(iterations) do |line|
|
44
|
+
#m = rubyre.match(line)
|
45
|
+
#if m
|
46
|
+
#matches[:rubyre] += 1
|
47
|
+
#m["foo"]
|
48
|
+
#end
|
49
|
+
#end
|
50
|
+
|
51
|
+
puts "Grok: #{matches[:grok] / groktime}"
|
52
|
+
puts failures.inspect
|
53
|
+
#puts "rubyre: #{rubyretime}"
|
54
|
+
#puts matches.inspect
|
51
55
|
#result = RubyProf.stop
|
52
56
|
#printer = RubyProf::FlatPrinter.new(result)
|
53
57
|
#printer.print(STDOUT, 0)
|
54
|
-
|
55
|
-
|
56
|
-
pp matches
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jls-grok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2821
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,22 +25,19 @@ files:
|
|
25
25
|
- sample.rb
|
26
26
|
- INSTALL
|
27
27
|
- ext/ruby_grok.c
|
28
|
-
- ext/mkmf.log
|
29
28
|
- ext/Makefile
|
30
29
|
- ext/rgrok.h
|
31
30
|
- ext/ruby_grokmatch.c
|
32
31
|
- ext/ruby_grokmatch.h
|
33
32
|
- ext/extconf.rb
|
34
|
-
- ext/
|
35
|
-
- ext/Grok.so
|
36
|
-
- ext/ruby_grokmatch.o
|
37
|
-
- test/GDB_COMMAND
|
33
|
+
- ext/ruby_grokdiscover.c
|
38
34
|
- test/general/basic_test.rb
|
39
35
|
- test/general/captures_test.rb
|
40
36
|
- test/Makefile
|
41
37
|
- test/alltests.rb
|
42
38
|
- test/speedtest.rb
|
43
39
|
- test/patterns/quotedstring.rb
|
40
|
+
- test/patterns/day.rb
|
44
41
|
- test/patterns/number.rb
|
45
42
|
- test/patterns/ip.input
|
46
43
|
- test/patterns/ip.rb
|
data/ext/Grok.so
DELETED
Binary file
|
data/ext/mkmf.log
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
find_header: checking for tcutil.h in /usr/local/include... -------------------- yes
|
2
|
-
|
3
|
-
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -o conftest.i"
|
4
|
-
checked program was:
|
5
|
-
/* begin */
|
6
|
-
1: #include <tcutil.h>
|
7
|
-
/* end */
|
8
|
-
|
9
|
-
--------------------
|
10
|
-
|
11
|
-
find_header: checking for pcre.h in /usr/local/include... -------------------- yes
|
12
|
-
|
13
|
-
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -o conftest.i"
|
14
|
-
checked program was:
|
15
|
-
/* begin */
|
16
|
-
1: #include <pcre.h>
|
17
|
-
/* end */
|
18
|
-
|
19
|
-
--------------------
|
20
|
-
|
21
|
-
find_header: checking for grok.h in ../... -------------------- yes
|
22
|
-
|
23
|
-
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -o conftest.i"
|
24
|
-
checked program was:
|
25
|
-
/* begin */
|
26
|
-
1: #include <grok.h>
|
27
|
-
/* end */
|
28
|
-
|
29
|
-
--------------------
|
30
|
-
|
31
|
-
find_library: checking for grok_init() in -lgrok... -------------------- yes
|
32
|
-
|
33
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
34
|
-
conftest.c: In function 't':
|
35
|
-
conftest.c:3: error: 'grok_init' undeclared (first use in this function)
|
36
|
-
conftest.c:3: error: (Each undeclared identifier is reported only once
|
37
|
-
conftest.c:3: error: for each function it appears in.)
|
38
|
-
checked program was:
|
39
|
-
/* begin */
|
40
|
-
1: /*top*/
|
41
|
-
2: int main() { return 0; }
|
42
|
-
3: int t() { void ((*volatile p)()); p = (void ((*)()))grok_init; return 0; }
|
43
|
-
/* end */
|
44
|
-
|
45
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
46
|
-
checked program was:
|
47
|
-
/* begin */
|
48
|
-
1: /*top*/
|
49
|
-
2: int main() { return 0; }
|
50
|
-
3: int t() { grok_init(); return 0; }
|
51
|
-
/* end */
|
52
|
-
|
53
|
-
--------------------
|
54
|
-
|
data/ext/ruby_grok.o
DELETED
Binary file
|
data/ext/ruby_grokmatch.o
DELETED
Binary file
|
data/test/GDB_COMMAND
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
set confirm off
|
2
|
-
delete
|
3
|
-
|
4
|
-
break rGrokMatch_new_from_grok_match if strcmp(gm->subject, "40079") == 0
|
5
|
-
commands
|
6
|
-
printf "subject: %s\n", gm->subject
|
7
|
-
delete
|
8
|
-
break rGrokMatch_captures
|
9
|
-
cont
|
10
|
-
end
|
11
|
-
|
12
|
-
set confirm off
|
13
|
-
delete
|
14
|
-
break rGrokMatch_new_from_grok_match if strcmp(gm->subject, "-29086") == 0
|
15
|
-
commands
|
16
|
-
print *gm
|
17
|
-
delete
|
18
|
-
break rGrokMatch_captures
|
19
|
-
cont
|
20
|
-
end
|
21
|
-
|
22
|
-
run
|
23
|
-
|
24
|
-
next
|
25
|
-
print *gm
|
26
|
-
print *(gm->grok)
|
27
|
-
delete
|
28
|
-
cont
|
29
|
-
|