logflume 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/logflume/exceptions.rb +2 -1
- data/lib/logflume/flume.rb +12 -6
- data/lib/logflume/version.rb +1 -1
- data/spec/logflume/logflume_spec.rb +49 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fb29b01822f89e457a933bc04be3d495bf5b66b
|
4
|
+
data.tar.gz: 3703168b9dd36733ec70c53a6f2d1c45f22fa5a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a51d4eccc0630fbb3817e3e7dc3cd1f64bebcd4b53d975f5cb94de9ca96bcb36671431c80f274b4819c78d9693139aae03c62144aaa834d588b555f1b60bae6
|
7
|
+
data.tar.gz: 93158fe633e007948d20725f96fc7d24fe8d4f47451edbddfadb18693fb7554bf855369367429400d9de61bcf7fbc8f3f1e03e634629d435bd37c83d5ba0f855
|
data/lib/logflume/exceptions.rb
CHANGED
data/lib/logflume/flume.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Logflume
|
2
2
|
class Flume
|
3
|
-
attr_accessor :dir, :glob, :logger, :pipe, :pre_load, :interval, :blocking, :prefix_syslog, :syslog_sourceip, :syslog_level, :syslog_facility, :syslog_priority, :syslog_progname, :syslog_severity
|
3
|
+
attr_accessor :dir, :glob, :logger, :pipe, :pre_load, :interval, :blocking, :prefix_syslog, :syslog_sourceip, :syslog_level, :syslog_facility, :syslog_priority, :syslog_progname, :syslog_severity, :shift, :bookmark
|
4
4
|
|
5
5
|
def initialize(opts = {})
|
6
6
|
@dir = opts[:dir] || './flume/'
|
@@ -9,6 +9,8 @@ module Logflume
|
|
9
9
|
@interval = opts[:interval] || 5.0
|
10
10
|
@pre_load = opts[:pre_load] || false
|
11
11
|
@blocking = opts[:blocking] || false
|
12
|
+
@bookmark = opts[:bookmark] || false
|
13
|
+
@shift = opts[:shift] || false
|
12
14
|
@prefix_syslog = opts[:prefix_syslog] || false
|
13
15
|
@syslog_sourceip = opts[:syslog_sourceip] || "127.0.0.1"
|
14
16
|
@syslog_facility = opts[:syslog_facility] || "local7"
|
@@ -25,7 +27,11 @@ module Logflume
|
|
25
27
|
|
26
28
|
def load
|
27
29
|
raise InvalidDirectory unless directory_exists?(@dir)
|
30
|
+
if @shift
|
31
|
+
raise InvalidShiftDirectory unless directory_exists?(@shift)
|
32
|
+
end
|
28
33
|
@dw = DirectoryWatcher.new(@dir, :glob => @glob, :logger => @logger, :interval => @interval, :pre_load => @pre_load)
|
34
|
+
@dw.persist = @bookmark if @bookmark
|
29
35
|
@configured = true unless @dw.nil?
|
30
36
|
route_pipe
|
31
37
|
end
|
@@ -45,7 +51,7 @@ module Logflume
|
|
45
51
|
end
|
46
52
|
|
47
53
|
def shutdown
|
48
|
-
|
54
|
+
running? ? stop : true
|
49
55
|
@dw = nil
|
50
56
|
@configure = false
|
51
57
|
destroy_pipe
|
@@ -81,11 +87,7 @@ module Logflume
|
|
81
87
|
def hookup_pipe
|
82
88
|
@dw.add_observer do |*args|
|
83
89
|
args.each do |event|
|
84
|
-
|
85
90
|
if event.type == :added
|
86
|
-
#root = File.dirname(__FILE__)
|
87
|
-
#infile = File.join(root, event.path)
|
88
|
-
#@logger.info "new File found => #{infile}"
|
89
91
|
@logger.info "new File found => #{event.path}"
|
90
92
|
if @prefix_syslog
|
91
93
|
File.open(event.path).each_line do |line|
|
@@ -96,6 +98,10 @@ module Logflume
|
|
96
98
|
@pipe_handler.puts line
|
97
99
|
end
|
98
100
|
end
|
101
|
+
if @shift
|
102
|
+
@logger.info "shift # " + event.path + " -> " + @shift + '/' + File.basename(event.path)
|
103
|
+
File.rename(event.path, @shift + '/' + File.basename(event.path))
|
104
|
+
end
|
99
105
|
end
|
100
106
|
|
101
107
|
end
|
data/lib/logflume/version.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
|
2
2
|
|
3
3
|
describe Logflume do
|
4
4
|
|
5
|
-
#Standard working test of all fields
|
5
|
+
#Standard working test of all fields
|
6
6
|
it 'finds files in a directory' do
|
7
7
|
flume = Logflume::Flume.new
|
8
8
|
flume.dir='spec/data/flume'
|
@@ -32,7 +32,7 @@ describe Logflume do
|
|
32
32
|
flume.syslog_progname="dpkg"
|
33
33
|
#flume.blocking = true
|
34
34
|
expect(flume.start.class.to_s).to eq 'DirectoryWatcher'
|
35
|
-
sleep(
|
35
|
+
sleep(2) ## We need to ba able to catch PROC errors here..
|
36
36
|
flume.shutdown
|
37
37
|
end
|
38
38
|
|
@@ -43,6 +43,14 @@ describe Logflume do
|
|
43
43
|
expect{flume.start}.to raise_error(Logflume::InvalidDirectory)
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'should raise an InvalidShiftDirectory Error' do
|
47
|
+
flume = Logflume::Flume.new
|
48
|
+
flume.dir='spec/data/flume'
|
49
|
+
flume.glob='*.log'
|
50
|
+
flume.shift='/var/does/not/exist'
|
51
|
+
expect{flume.start}.to raise_error(Logflume::InvalidShiftDirectory)
|
52
|
+
end
|
53
|
+
|
46
54
|
it 'finds files in a directory' do
|
47
55
|
flume = Logflume::Flume.new
|
48
56
|
flume.dir='spec/data/flume'
|
@@ -51,6 +59,45 @@ describe Logflume do
|
|
51
59
|
flume.start
|
52
60
|
#FileUtils.touch('spec/data/flume/test.log')
|
53
61
|
expect(flume.shutdown).to eq true
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "shift group" do
|
65
|
+
before(:context) do
|
66
|
+
require 'fileutils'
|
67
|
+
@data = 'spec/data/flume'
|
68
|
+
@monitor = '/tmp/flume'
|
69
|
+
@shift = '/tmp/flume-shift'
|
70
|
+
#Cleanup
|
71
|
+
FileUtils.rm_rf @monitor
|
72
|
+
FileUtils.rm_rf @shift
|
73
|
+
end
|
74
|
+
|
75
|
+
before(:example) do
|
76
|
+
#Setup
|
77
|
+
FileUtils.cp_r @data, @monitor
|
78
|
+
FileUtils.mkdir_p @shift
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'handles fifo pipes' do
|
82
|
+
flume = Logflume::Flume.new
|
83
|
+
flume.dir=@monitor
|
84
|
+
flume.glob='*.log'
|
85
|
+
flume.pipe="/tmp/tmp.flume.#{$$}.fifo"
|
86
|
+
flume.logger = Logger.new('/dev/null')
|
87
|
+
flume.prefix_syslog=true
|
88
|
+
flume.syslog_progname="dpkg"
|
89
|
+
flume.shift = @shift
|
90
|
+
#flume.blocking = true
|
91
|
+
expect(flume.start.class.to_s).to eq 'DirectoryWatcher'
|
92
|
+
sleep(2) ## We need to ba able to catch PROC errors here..
|
93
|
+
flume.shutdown
|
94
|
+
end
|
95
|
+
|
96
|
+
after(:example) do
|
97
|
+
#Cleanup
|
98
|
+
FileUtils.rm_rf @monitor
|
99
|
+
FileUtils.rm_rf @shift
|
100
|
+
end
|
54
101
|
|
55
102
|
end
|
56
103
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logflume
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shadowbq
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: directory_watcher
|