still buggy

This commit is contained in:
Denis Knauf 2010-03-29 11:50:59 +02:00
parent 313be57c1d
commit a5aaab685e
11 changed files with 160 additions and 132 deletions

View file

@ -11,8 +11,8 @@ begin
gem.homepage = "http://github.com/DenisKnauf/logan"
gem.authors = ["Denis Knauf"]
gem.files = %w[AUTHORS README.md VERSION lib/**/*.rb test/**/*.rb]
gem.require_paths = %w[lib]
gem.add_dependency 'sbdb'
gem.require_paths = %w[bin lib]
gem.add_dependency %w[robustserver sbdb]
end
Jeweler::GemcutterTasks.new
rescue LoadError

31
bin/conf.rb Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env ruby
require 'sbdb'
conf = {}
%w[etc sids].each {|key| conf[key.to_sym] = key }
conf[:sids] = File.basename( conf[:sids], ".cnf")+".cnf"
$stdout.puts ARGV.inspect
SBDB::Env.open( conf[:etc], SBDB::CREATE | SBDB::Env::INIT_TXN | Bdb::DB_INIT_MPOOL,
log_config: SBDB::Env::LOG_IN_MEMORY | SBDB::Env::LOG_AUTO_REMOVE) do |etc|
etc.recno( conf[:sids], ARGV[0], flags: SBDB::CREATE | SBDB::AUTO_COMMIT) do |db|
$stderr.puts db.inspect
if ARGV[2]
db[ ARGV[1].to_i] = ARGV[2].empty? ? nil : ARGV[2]
end
if ARGV[1]
$stdout.puts "#{ARGV[0].inspect} #{ARGV[1].to_i} #{db[ ARGV[1].to_i].inspect}"
else
db.each do |k, v|
begin
$stdout.puts "#{ARGV[0].inspect} #{k} #{v.inspect}"
rescue Bdb::DbError
next if 22 == $!.code
raise $!
end
end
end
end
end

View file

@ -1,34 +1,15 @@
#!/usr/bin/ruby
require 'sbdb'
require 'safebox'
require 'robustserver'
require 'logan'
require 'logan/inc'
class LogAn::Main < RobustServer
def initialize conf
super
@conf = conf
@logs = LogAn::Loglines.new 'logs'
Dir.mkdir 'etc' rescue Errno::EEXIST
@etc = SBDB::Env.new( 'etc',
log_config: SBDB::Env::LOG_IN_MEMORY | SBDB::Env::LOG_AUTO_REMOVE,
flags: SBDB::CREATE | SBDB::Env::INIT_TXN | Bdb::DB_INIT_MPOOL)
@serv = LogAn::Inc.new :sock => TCPServer.new( *@conf[:server])
@sigs[:INT] = @sigs[:TERM] = method(:shutdown)
opts = {}
opts[:server] = if ARGV[1]
ARGV
elsif ARGV[0]
['localhost', ARGV[1]]
else %w[localhost 1087]
end
opts[:server][1] = opts[:server][1].to_i
def at_exit
@logs and @logs.close
@etc and @etc.close
end
def shutdown s = nil
$stderr.puts [:signal, s, Signal[s]].inspect
@serv.close
exit 0
end
def run
@serv.run
end
end
LogAn::Inc::Main.main *opts

View file

@ -2,8 +2,9 @@
require 'logan/inc/server'
require 'logan/inc/fileparser'
require 'logan/inc/command'
require 'logan/inc/main'
module Logan
module LogAn
module Inc
end
end

View file

@ -1,5 +1,5 @@
module Logan
module LogAn
module Inc
class Command < ::Array
attr_reader :sid

View file

@ -1,5 +1,5 @@
module Logan
module LogAn
module Inc
module FileParser
module Base

View file

@ -2,13 +2,16 @@
require 'sbdb'
require 'safebox'
require 'robustserver'
require 'logan/inc'
require 'logan/loglines'
module LogAn::Inc
class Main < RobustServer
# Open Config.
def config env, db, type = nil
$stderr.puts "Open Database "sids.cnf" #{db.inspect} (#{type.inspect})"
type ||= 1+4
ret = env[ 'inc.cnf', db, SBDB::RDONLY]
ret = env[ 'sids.cnf', db, SBDB::RDONLY]
ret = AutoValueConvertHash.new ret if type&4 > 0
ret = Cache.new ret, type&3 if type&3 > 0
ret
@ -27,7 +30,7 @@ module LogAn::Inc
super
@conf = {}
# Copy config - changes possible
conf.each &@conf.method(:[]=)
conf.each {|key, val| @conf[key]= val }
# Default directories
%w[logs etc].each {|key| @conf[key.to_sym] = key }
# Open Loglines-databases

View file

@ -1,9 +1,12 @@
require 'select'
module Logan
module LogAn
module Inc
class Select <::Select
end
end
class LogAn::Inc::Select <::Select
attr_reader :entries
def initialize *p
super *p
@ -49,7 +52,7 @@ module Logan
end
end
class Socket <::Select::Socket
class LogAn::Inc::Socket <::Select::Socket
def event_read sock = @sock, event = :read
begin
@linebuf += sock.readpartial( @bufsize)
@ -72,7 +75,7 @@ module Logan
end
end
class Server < ::Select::Server
class LogAn::Inc::Server < ::Select::Server
attr_reader :config
def init opts
@ -84,7 +87,7 @@ module Logan
{ :clientclass => LogAn::Inc::Server::Socket, :config => @config }
end
class Socket < LogAn::Inc::Server::Socket
class Socket < LogAn::Inc::Socket
attr_reader :config
def init opts
@ -94,13 +97,8 @@ module Logan
def event_cmd cmd
sid, line = cmd.unpack 'Na*'
begin
@config[ :fileparser][sid].event_line line, self
rescue Didi::Config::NoSIDFound, Didi::Config::SIDLoadingError
$stderr.puts( {:sid => sid, :exception => $!, :backtrace => $!.backtrace}.inspect)
end
end
end
fileparser = @config[:fileparser][sid]
fileparser.event_line line, self if fileparser
end
end
end

View file

@ -29,7 +29,7 @@ module LogAn
@rdb = @env[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | SBDB::AUTO_COMMIT]
@queue = @env[ "newids.queue", :type => SBDB::Queue, :flags => SBDB::CREATE | SBDB::AUTO_COMMIT, :re_len => 16]
@dbs = {}
self.hash = lambda {|k|
self.hash_func = lambda {|k|
[k.timestamp.to_i/60/60].pack 'N' # Hour-based rotation
}
end

View file

@ -1,3 +1,3 @@
require 'logan'
Logan.add CStruct.new( :line)
LogAn.add CStruct.new( :line)

View file

@ -9,22 +9,33 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Denis Knauf"]
s.date = %q{2010-02-24}
s.date = %q{2010-03-29}
s.description = %q{}
s.email = %q{Denis.Knauf@gmail.com}
s.executables = ["box3.rb", "box.rb", "box2.rb", "loganinc"]
s.extra_rdoc_files = [
"LICENSE"
"LICENSE",
"README.md"
]
s.files = [
"AUTHORS",
"README.md",
"VERSION",
"lib/cstruct.rb",
"lib/logan.rb",
"lib/logan/cache.rb",
"lib/logan/inc.rb",
"lib/logan/inc/command.rb",
"lib/logan/inc/fileparser.rb",
"lib/logan/inc/main.rb",
"lib/logan/inc/server.rb",
"lib/logan/loglines.rb",
"lib/logan/types/syslog.rb"
]
s.homepage = %q{http://github.com/DenisKnauf/logan}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.require_paths = ["bin", "lib"]
s.rubygems_version = %q{1.3.6}
s.summary = %q{Logdata analysing database}
if s.respond_to? :specification_version then
@ -32,9 +43,12 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<["robustserver", "sbdb"]>, [">= 0"])
else
s.add_dependency(%q<["robustserver", "sbdb"]>, [">= 0"])
end
else
s.add_dependency(%q<["robustserver", "sbdb"]>, [">= 0"])
end
end