scribeit 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/Manifest +11 -0
- data/README.md +3 -0
- data/Rakefile +15 -0
- data/bin/scribeit +55 -0
- data/lib/scribeit.rb +88 -0
- data/lib/scribeit/log.rb +19 -0
- data/lib/scribeit/source.rb +37 -0
- data/scribeit.gemspec +40 -0
- metadata +108 -0
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
scribeit (0.0.3)
|
5
|
+
eventmachine
|
6
|
+
eventmachine-tail
|
7
|
+
scribe (> 0.2.2)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
eventmachine (0.12.10)
|
13
|
+
eventmachine-tail (0.6.1)
|
14
|
+
eventmachine
|
15
|
+
rake (0.8.7)
|
16
|
+
scribe (0.2.4)
|
17
|
+
rake
|
18
|
+
thrift_client (~> 0.6)
|
19
|
+
thrift (0.5.0)
|
20
|
+
thrift_client (0.6.0)
|
21
|
+
thrift (~> 0.5.0)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
scribeit!
|
data/Manifest
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new("scribeit") do |p|
|
6
|
+
p.author = "Thom May"
|
7
|
+
p.email = "thom@may.lt"
|
8
|
+
p.url = "https://github.com/thommay/scribeit"
|
9
|
+
p.summary = "A configurable scribe client"
|
10
|
+
p.runtime_dependencies = ['scribe >0.2.2', "eventmachine", "eventmachine-tail"]
|
11
|
+
p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
data/bin/scribeit
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.dirname($0) + '/../lib'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'eventmachine'
|
7
|
+
require 'yaml'
|
8
|
+
require 'optparse'
|
9
|
+
require 'scribe'
|
10
|
+
require 'scribeit'
|
11
|
+
|
12
|
+
conf = '/etc/scribeit.conf'
|
13
|
+
|
14
|
+
opts = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: #{$0} [options]"
|
16
|
+
|
17
|
+
opts.on("-f CONFIGFILE", "--config CONFIGFILE", "Load scribeit's config from the specified file") do |arg|
|
18
|
+
conf = arg
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.parse!
|
23
|
+
if conf == '' or conf.nil?
|
24
|
+
raise "No config file given"
|
25
|
+
end
|
26
|
+
|
27
|
+
if !File.exist? conf
|
28
|
+
$stderr.puts "Config file #{conf} does not exist!"
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
config = YAML::load_file(conf)
|
34
|
+
if config["dirs"]
|
35
|
+
config["dirs"].each do |dir|
|
36
|
+
Dir.glob("#{dir}/*.yml") do |fn|
|
37
|
+
config.merge!(YAML::load_file(fn)) do |k,r1,r2|
|
38
|
+
r1.merge(r2) do |k,r1,r2|
|
39
|
+
if r1.respond_to? "merge"
|
40
|
+
r1.merge r2
|
41
|
+
else
|
42
|
+
r1 + r2 if r1.is_a? Array
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue => e
|
50
|
+
$stderr.puts "Loading config file #{conf} failed: #{e}"
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
|
54
|
+
scr = ScribeIt.new(config)
|
55
|
+
scr.run
|
data/lib/scribeit.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'eventmachine-tail'
|
3
|
+
require 'scribe'
|
4
|
+
require 'scribeit/source'
|
5
|
+
require 'scribeit/log'
|
6
|
+
|
7
|
+
class ScribeIt
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
attr_reader :sources
|
11
|
+
|
12
|
+
def initialize(config)
|
13
|
+
@config = config
|
14
|
+
@sources = []
|
15
|
+
@scribe = Scribe.new
|
16
|
+
@logger = ScribeIt::Log.new STDERR
|
17
|
+
end
|
18
|
+
|
19
|
+
def register
|
20
|
+
if !@config.has_key? "sources"
|
21
|
+
raise "Config error - no sources defined"
|
22
|
+
end
|
23
|
+
|
24
|
+
sources = @config["sources"]
|
25
|
+
sources.each do |source|
|
26
|
+
puts source.inspect
|
27
|
+
if source.is_a? Array or source.is_a? Hash
|
28
|
+
cat, files = source
|
29
|
+
else
|
30
|
+
raise "Config error - no category for file: #{files.inspect}"
|
31
|
+
end
|
32
|
+
|
33
|
+
files = [files] if !files.is_a? Array
|
34
|
+
|
35
|
+
files.each do |f|
|
36
|
+
@logger.debug("Adding new source #{f} to category #{cat}")
|
37
|
+
s = ScribeIt::Source.new(f, cat) { |event| fire(event) }
|
38
|
+
s.register
|
39
|
+
@sources << s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
register_signal_handler
|
44
|
+
end
|
45
|
+
|
46
|
+
def run(&block)
|
47
|
+
EventMachine.epoll
|
48
|
+
EventMachine.run do
|
49
|
+
self.register
|
50
|
+
yield if block_given?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop
|
55
|
+
EventMachine.stop_event_loop
|
56
|
+
end
|
57
|
+
|
58
|
+
def register_signal_handler
|
59
|
+
@signals = EventMachine::Channel.new
|
60
|
+
|
61
|
+
Signal.trap("INT") do
|
62
|
+
@signals.push(:INT)
|
63
|
+
end
|
64
|
+
|
65
|
+
Signal.trap("USR1") do
|
66
|
+
@signals.push(:USR1)
|
67
|
+
end
|
68
|
+
|
69
|
+
@signals.subscribe do |msg|
|
70
|
+
case msg
|
71
|
+
when :USR1
|
72
|
+
#eventually, we want to reload our config.
|
73
|
+
# for now, we'll just show what we're looking at.
|
74
|
+
puts @sources
|
75
|
+
when :INT
|
76
|
+
EventMachine.stop_event_loop
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
|
83
|
+
def fire(event)
|
84
|
+
@logger.debug("Firing a new event at scribe for #{event.inspect}")
|
85
|
+
@scribe.log(event[:event], event[:category])
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/lib/scribeit/log.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class ScribeIt
|
2
|
+
class Source
|
3
|
+
def initialize(file, category, &block)
|
4
|
+
@logger = ScribeIt::Log.new STDERR
|
5
|
+
@file = file
|
6
|
+
@callback = block
|
7
|
+
@category = category
|
8
|
+
end
|
9
|
+
|
10
|
+
def register
|
11
|
+
@logger.info "Registering #{@file}"
|
12
|
+
EventMachine::FileGlobWatchTail.new(@file, Reader, interval=60, exclude=[], receiver=self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def receive(filetail, event)
|
16
|
+
@logger.debug "File #{@file} got event: #{event.inspect}"
|
17
|
+
e = {:event => event, :category => @category}
|
18
|
+
@callback.call e
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
class Reader < EventMachine::FileTail
|
23
|
+
def initialize(path, receiver)
|
24
|
+
super path
|
25
|
+
@receiver = receiver
|
26
|
+
@buffer = BufferedTokenizer.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def receive_data(data)
|
30
|
+
@buffer.extract(data).each do |line|
|
31
|
+
@receiver.receive(self, line)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/scribeit.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{scribeit}
|
5
|
+
s.version = "0.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Thom May"]
|
9
|
+
s.date = %q{2011-05-09}
|
10
|
+
s.default_executable = %q{scribeit}
|
11
|
+
s.description = %q{A configurable scribe client}
|
12
|
+
s.email = %q{thom@may.lt}
|
13
|
+
s.executables = ["scribeit"]
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "README.md", "bin/scribeit", "lib/scribeit.rb", "lib/scribeit/log.rb", "lib/scribeit/source.rb"]
|
15
|
+
s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "README.md", "Rakefile", "bin/scribeit", "lib/scribeit.rb", "lib/scribeit/log.rb", "lib/scribeit/source.rb", "scribeit.gemspec", "Manifest"]
|
16
|
+
s.homepage = %q{https://github.com/thommay/scribeit}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Scribeit", "--main", "README.md"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{scribeit}
|
20
|
+
s.rubygems_version = %q{1.6.0}
|
21
|
+
s.summary = %q{A configurable scribe client}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<scribe>, ["> 0.2.2"])
|
28
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
29
|
+
s.add_runtime_dependency(%q<eventmachine-tail>, [">= 0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<scribe>, ["> 0.2.2"])
|
32
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
33
|
+
s.add_dependency(%q<eventmachine-tail>, [">= 0"])
|
34
|
+
end
|
35
|
+
else
|
36
|
+
s.add_dependency(%q<scribe>, ["> 0.2.2"])
|
37
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
38
|
+
s.add_dependency(%q<eventmachine-tail>, [">= 0"])
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scribeit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thom May
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-09 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: scribe
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.2.2
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: eventmachine-tail
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: A configurable scribe client
|
50
|
+
email: thom@may.lt
|
51
|
+
executables:
|
52
|
+
- scribeit
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- CHANGELOG
|
57
|
+
- README.md
|
58
|
+
- bin/scribeit
|
59
|
+
- lib/scribeit.rb
|
60
|
+
- lib/scribeit/log.rb
|
61
|
+
- lib/scribeit/source.rb
|
62
|
+
files:
|
63
|
+
- CHANGELOG
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/scribeit
|
69
|
+
- lib/scribeit.rb
|
70
|
+
- lib/scribeit/log.rb
|
71
|
+
- lib/scribeit/source.rb
|
72
|
+
- scribeit.gemspec
|
73
|
+
- Manifest
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: https://github.com/thommay/scribeit
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --line-numbers
|
81
|
+
- --inline-source
|
82
|
+
- --title
|
83
|
+
- Scribeit
|
84
|
+
- --main
|
85
|
+
- README.md
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "1.2"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project: scribeit
|
103
|
+
rubygems_version: 1.6.0
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: A configurable scribe client
|
107
|
+
test_files: []
|
108
|
+
|