still buggy
This commit is contained in:
parent
313be57c1d
commit
a5aaab685e
4
Rakefile
4
Rakefile
|
@ -11,8 +11,8 @@ begin
|
||||||
gem.homepage = "http://github.com/DenisKnauf/logan"
|
gem.homepage = "http://github.com/DenisKnauf/logan"
|
||||||
gem.authors = ["Denis Knauf"]
|
gem.authors = ["Denis Knauf"]
|
||||||
gem.files = %w[AUTHORS README.md VERSION lib/**/*.rb test/**/*.rb]
|
gem.files = %w[AUTHORS README.md VERSION lib/**/*.rb test/**/*.rb]
|
||||||
gem.require_paths = %w[lib]
|
gem.require_paths = %w[bin lib]
|
||||||
gem.add_dependency 'sbdb'
|
gem.add_dependency %w[robustserver sbdb]
|
||||||
end
|
end
|
||||||
Jeweler::GemcutterTasks.new
|
Jeweler::GemcutterTasks.new
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
31
bin/conf.rb
Executable file
31
bin/conf.rb
Executable 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
|
39
bin/loganinc
39
bin/loganinc
|
@ -1,34 +1,15 @@
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
|
|
||||||
require 'sbdb'
|
require 'logan'
|
||||||
require 'safebox'
|
require 'logan/inc'
|
||||||
require 'robustserver'
|
|
||||||
|
|
||||||
class LogAn::Main < RobustServer
|
opts = {}
|
||||||
def initialize conf
|
opts[:server] = if ARGV[1]
|
||||||
super
|
ARGV
|
||||||
@conf = conf
|
elsif ARGV[0]
|
||||||
@logs = LogAn::Loglines.new 'logs'
|
['localhost', ARGV[1]]
|
||||||
Dir.mkdir 'etc' rescue Errno::EEXIST
|
else %w[localhost 1087]
|
||||||
@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)
|
|
||||||
end
|
end
|
||||||
|
opts[:server][1] = opts[:server][1].to_i
|
||||||
|
|
||||||
def at_exit
|
LogAn::Inc::Main.main *opts
|
||||||
@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
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
require 'logan/inc/server'
|
require 'logan/inc/server'
|
||||||
require 'logan/inc/fileparser'
|
require 'logan/inc/fileparser'
|
||||||
require 'logan/inc/command'
|
require 'logan/inc/command'
|
||||||
|
require 'logan/inc/main'
|
||||||
|
|
||||||
module Logan
|
module LogAn
|
||||||
module Inc
|
module Inc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
module Logan
|
module LogAn
|
||||||
module Inc
|
module Inc
|
||||||
class Command < ::Array
|
class Command < ::Array
|
||||||
attr_reader :sid
|
attr_reader :sid
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
module Logan
|
module LogAn
|
||||||
module Inc
|
module Inc
|
||||||
module FileParser
|
module FileParser
|
||||||
module Base
|
module Base
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
require 'sbdb'
|
require 'sbdb'
|
||||||
require 'safebox'
|
require 'safebox'
|
||||||
require 'robustserver'
|
require 'robustserver'
|
||||||
|
require 'logan/inc'
|
||||||
|
require 'logan/loglines'
|
||||||
|
|
||||||
module LogAn::Inc
|
module LogAn::Inc
|
||||||
class Main < RobustServer
|
class Main < RobustServer
|
||||||
# Open Config.
|
# Open Config.
|
||||||
def config env, db, type = nil
|
def config env, db, type = nil
|
||||||
|
$stderr.puts "Open Database "sids.cnf" #{db.inspect} (#{type.inspect})"
|
||||||
type ||= 1+4
|
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 = AutoValueConvertHash.new ret if type&4 > 0
|
||||||
ret = Cache.new ret, type&3 if type&3 > 0
|
ret = Cache.new ret, type&3 if type&3 > 0
|
||||||
ret
|
ret
|
||||||
|
@ -27,7 +30,7 @@ module LogAn::Inc
|
||||||
super
|
super
|
||||||
@conf = {}
|
@conf = {}
|
||||||
# Copy config - changes possible
|
# Copy config - changes possible
|
||||||
conf.each &@conf.method(:[]=)
|
conf.each {|key, val| @conf[key]= val }
|
||||||
# Default directories
|
# Default directories
|
||||||
%w[logs etc].each {|key| @conf[key.to_sym] = key }
|
%w[logs etc].each {|key| @conf[key.to_sym] = key }
|
||||||
# Open Loglines-databases
|
# Open Loglines-databases
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
|
|
||||||
require 'select'
|
require 'select'
|
||||||
|
|
||||||
module Logan
|
module LogAn
|
||||||
module Inc
|
module Inc
|
||||||
class Select <::Select
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class LogAn::Inc::Select <::Select
|
||||||
attr_reader :entries
|
attr_reader :entries
|
||||||
def initialize *p
|
def initialize *p
|
||||||
super *p
|
super *p
|
||||||
|
@ -47,9 +50,9 @@ module Logan
|
||||||
@entries << a
|
@entries << a
|
||||||
@entries.sort!
|
@entries.sort!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Socket <::Select::Socket
|
class LogAn::Inc::Socket <::Select::Socket
|
||||||
def event_read sock = @sock, event = :read
|
def event_read sock = @sock, event = :read
|
||||||
begin
|
begin
|
||||||
@linebuf += sock.readpartial( @bufsize)
|
@linebuf += sock.readpartial( @bufsize)
|
||||||
|
@ -70,9 +73,9 @@ module Logan
|
||||||
event_cmd @linebuf.remove( l)
|
event_cmd @linebuf.remove( l)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Server < ::Select::Server
|
class LogAn::Inc::Server < ::Select::Server
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
|
|
||||||
def init opts
|
def init opts
|
||||||
|
@ -84,7 +87,7 @@ module Logan
|
||||||
{ :clientclass => LogAn::Inc::Server::Socket, :config => @config }
|
{ :clientclass => LogAn::Inc::Server::Socket, :config => @config }
|
||||||
end
|
end
|
||||||
|
|
||||||
class Socket < LogAn::Inc::Server::Socket
|
class Socket < LogAn::Inc::Socket
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
|
|
||||||
def init opts
|
def init opts
|
||||||
|
@ -94,13 +97,8 @@ module Logan
|
||||||
|
|
||||||
def event_cmd cmd
|
def event_cmd cmd
|
||||||
sid, line = cmd.unpack 'Na*'
|
sid, line = cmd.unpack 'Na*'
|
||||||
begin
|
fileparser = @config[:fileparser][sid]
|
||||||
@config[ :fileparser][sid].event_line line, self
|
fileparser.event_line line, self if fileparser
|
||||||
rescue Didi::Config::NoSIDFound, Didi::Config::SIDLoadingError
|
|
||||||
$stderr.puts( {:sid => sid, :exception => $!, :backtrace => $!.backtrace}.inspect)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@ module LogAn
|
||||||
@rdb = @env[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | SBDB::AUTO_COMMIT]
|
@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]
|
@queue = @env[ "newids.queue", :type => SBDB::Queue, :flags => SBDB::CREATE | SBDB::AUTO_COMMIT, :re_len => 16]
|
||||||
@dbs = {}
|
@dbs = {}
|
||||||
self.hash = lambda {|k|
|
self.hash_func = lambda {|k|
|
||||||
[k.timestamp.to_i/60/60].pack 'N' # Hour-based rotation
|
[k.timestamp.to_i/60/60].pack 'N' # Hour-based rotation
|
||||||
}
|
}
|
||||||
end
|
end
|
|
@ -1,3 +1,3 @@
|
||||||
require 'logan'
|
require 'logan'
|
||||||
|
|
||||||
Logan.add CStruct.new( :line)
|
LogAn.add CStruct.new( :line)
|
||||||
|
|
|
@ -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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Denis Knauf"]
|
s.authors = ["Denis Knauf"]
|
||||||
s.date = %q{2010-02-24}
|
s.date = %q{2010-03-29}
|
||||||
s.description = %q{}
|
s.description = %q{}
|
||||||
s.email = %q{Denis.Knauf@gmail.com}
|
s.email = %q{Denis.Knauf@gmail.com}
|
||||||
|
s.executables = ["box3.rb", "box.rb", "box2.rb", "loganinc"]
|
||||||
s.extra_rdoc_files = [
|
s.extra_rdoc_files = [
|
||||||
"LICENSE"
|
"LICENSE",
|
||||||
|
"README.md"
|
||||||
]
|
]
|
||||||
s.files = [
|
s.files = [
|
||||||
|
"AUTHORS",
|
||||||
|
"README.md",
|
||||||
"VERSION",
|
"VERSION",
|
||||||
"lib/cstruct.rb",
|
"lib/cstruct.rb",
|
||||||
"lib/logan.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"
|
"lib/logan/types/syslog.rb"
|
||||||
]
|
]
|
||||||
s.homepage = %q{http://github.com/DenisKnauf/logan}
|
s.homepage = %q{http://github.com/DenisKnauf/logan}
|
||||||
s.rdoc_options = ["--charset=UTF-8"]
|
s.rdoc_options = ["--charset=UTF-8"]
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["bin", "lib"]
|
||||||
s.rubygems_version = %q{1.3.5}
|
s.rubygems_version = %q{1.3.6}
|
||||||
s.summary = %q{Logdata analysing database}
|
s.summary = %q{Logdata analysing database}
|
||||||
|
|
||||||
if s.respond_to? :specification_version then
|
if s.respond_to? :specification_version then
|
||||||
|
@ -32,9 +43,12 @@ Gem::Specification.new do |s|
|
||||||
s.specification_version = 3
|
s.specification_version = 3
|
||||||
|
|
||||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||||
|
s.add_runtime_dependency(%q<["robustserver", "sbdb"]>, [">= 0"])
|
||||||
else
|
else
|
||||||
|
s.add_dependency(%q<["robustserver", "sbdb"]>, [">= 0"])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
s.add_dependency(%q<["robustserver", "sbdb"]>, [">= 0"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue