rubiojr-apalo 0.0.102 → 0.0.104

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/Manifest.txt CHANGED
@@ -16,3 +16,4 @@ lib/apalo/core.rb
16
16
  lib/apalo/core/log_line.rb
17
17
  lib/apalo/core/log_parser.rb
18
18
  lib/apalo/core/log_string.rb
19
+ examples/simple.rb
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'apalo'
3
+
4
+ Apalo::logfile = '/data/logs/httpd/access_log'
5
+ Apalo.parser.each_line do |l|
6
+ puts l.ipaddr
7
+ puts l.user_agent
8
+ end
data/lib/apalo.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'time'
2
+ require 'zlib'
2
3
  require File.dirname(__FILE__) + '/apalo/core'
3
4
  require File.dirname(__FILE__) + '/apalo/cli'
4
5
 
5
6
  module Apalo
6
7
 
7
- VERSION = '0.0.102'
8
+ VERSION = '0.0.104'
8
9
 
9
10
  def self.logfile=(l)
10
11
  @logfile = l
@@ -15,7 +16,7 @@ module Apalo
15
16
  end
16
17
 
17
18
  def self.parser
18
- @parser ||= LogParser.new
19
+ @parser ||= Apalo::Core::LogParser.new
19
20
  end
20
21
 
21
22
  def self.parsing_errors
data/lib/apalo/cli.rb CHANGED
@@ -2,7 +2,7 @@ module Apalo
2
2
  module Cli
3
3
  def self.init(version)
4
4
  @cmd = CmdParse::CommandParser.new( true, true )
5
- @cmd.program_name = "knocked"
5
+ @cmd.program_name = "apalo"
6
6
  @cmd.program_version = version.split('.')
7
7
  @cmd.options = CmdParse::OptionParserWrapper.new do |opt|
8
8
  opt.separator "Global options:"
@@ -4,6 +4,10 @@ module Apalo
4
4
  attr_accessor :ipaddr, :ident, :userid, :time
5
5
  attr_accessor :request, :rcode, :rsize, :referer, :user_agent
6
6
  attr_accessor :vhost, :raw
7
+
8
+ def to_s
9
+ @raw
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -8,6 +8,7 @@ module Apalo
8
8
  @processed_lines = 0
9
9
  @filtered_lines = 0
10
10
  @errors = 0
11
+ @logline = LogLine.new
11
12
  if filter
12
13
  begin
13
14
  require 'oniguruma'
@@ -18,11 +19,7 @@ module Apalo
18
19
  @filter = /#{filter}/
19
20
  end
20
21
  end
21
- end
22
-
23
- def each_line
24
22
  @regex = nil
25
- @logline = LogLine.new
26
23
  r = [
27
24
  '(\d+\.\d+\.\d+\.\d+)', # ip
28
25
  '(.*?)', # foo
@@ -45,10 +42,19 @@ module Apalo
45
42
  "WARNING: oniguruma gem not installed. Log analysis will be much slower."
46
43
  @regex = /#{logr}/
47
44
  end
45
+ end
46
+
47
+ def each_line
48
48
  File.open(Apalo.logfile) do |f|
49
- f.each_line do |line|
49
+ if Apalo.logfile =~ /\.gz/
50
+ handle = Zlib::GzipReader.new(f)
51
+ else
52
+ handle = f
53
+ end
54
+ handle.each_line do |line|
50
55
  @processed_lines += 1
51
56
  if @regex.match(line)
57
+ @logline.raw = line
52
58
  @logline.ipaddr = $1
53
59
  @logline.ident = $2
54
60
  @logline.userid = $3
@@ -61,6 +67,8 @@ module Apalo
61
67
  @logline.vhost = $10
62
68
  @logline.raw = line
63
69
  yield @logline
70
+ else
71
+ Apalo.parsing_errors << line
64
72
  end
65
73
  end
66
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubiojr-apalo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.102
4
+ version: 0.0.104
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio RubioSergio Rubio
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-09 00:00:00 -08:00
12
+ date: 2008-12-26 00:00:00 -08:00
13
13
  default_executable: atk
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ files:
77
77
  - lib/apalo/core/log_line.rb
78
78
  - lib/apalo/core/log_parser.rb
79
79
  - lib/apalo/core/log_string.rb
80
+ - examples/simple.rb
80
81
  has_rdoc: true
81
82
  homepage: http://github.com/rubiojr/apalo
82
83
  post_install_message: