md-logstasher 1.0.0.rc3 → 1.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstasher/device/redis.rb +9 -6
- data/lib/logstasher/device/syslog.rb +16 -12
- data/lib/logstasher/device.rb +13 -7
- data/lib/logstasher/version.rb +1 -1
- data/spec/lib/logstasher/device/redis_spec.rb +4 -4
- data/spec/lib/logstasher/device/syslog_spec.rb +4 -4
- data/spec/lib/logstasher/device_spec.rb +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1da4bf654fde44e013c54012909145df5a0bcf59
|
4
|
+
data.tar.gz: 21a9cddde75b6ceedad8dcc02f27c269a1d52562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da02d119cab4da5ebcf20030a60a6754881c435217c1018797a0e2158d8ce9a492b76c3d51d1f9b4a02eb633c0f1bd8e1805c04839599a4a5d0ddb8e0a057881
|
7
|
+
data.tar.gz: 85ef7becae5957c2da39587d141b652ed5d874c0e36a5fcdf31fe7831de650d3c51fc88b52838705fbbf9fa5ebe143c9abda4895d89d1974887e6562a41d27fc
|
@@ -1,23 +1,26 @@
|
|
1
|
+
require 'logstasher/device'
|
1
2
|
require 'redis'
|
2
3
|
|
3
4
|
module LogStasher
|
4
5
|
module Device
|
5
6
|
class Redis
|
7
|
+
include ::LogStasher::Device
|
6
8
|
|
7
9
|
attr_reader :options, :redis
|
8
10
|
|
9
11
|
def initialize(options = {})
|
10
|
-
@options = default_options.merge(options)
|
12
|
+
@options = default_options.merge(stringify_keys(options))
|
13
|
+
|
11
14
|
validate_options
|
12
15
|
configure_redis
|
13
16
|
end
|
14
17
|
|
15
18
|
def data_type
|
16
|
-
options[
|
19
|
+
options['data_type']
|
17
20
|
end
|
18
21
|
|
19
22
|
def key
|
20
|
-
options[
|
23
|
+
options['key']
|
21
24
|
end
|
22
25
|
|
23
26
|
def redis_options
|
@@ -51,12 +54,12 @@ module LogStasher
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def default_options
|
54
|
-
{ key
|
57
|
+
{ 'key' => 'logstash', 'data_type' => 'list' }
|
55
58
|
end
|
56
59
|
|
57
60
|
def validate_options
|
58
|
-
unless ['list', 'channel'].include?(options[
|
59
|
-
fail 'Expected
|
61
|
+
unless ['list', 'channel'].include?(options['data_type'])
|
62
|
+
fail 'Expected data_type to be either "list" or "channel"'
|
60
63
|
end
|
61
64
|
end
|
62
65
|
end
|
@@ -1,18 +1,22 @@
|
|
1
1
|
# inspired by [lumberjack](https://github.com/bdurand/lumberjack_syslog_device)
|
2
2
|
|
3
|
+
require 'logstasher/device'
|
3
4
|
require 'syslog'
|
4
5
|
require 'thread'
|
5
6
|
|
6
7
|
module LogStasher
|
7
8
|
module Device
|
8
9
|
class Syslog
|
10
|
+
include ::LogStasher::Device
|
9
11
|
|
10
12
|
SEMAPHORE = Mutex.new
|
11
13
|
|
12
14
|
attr_reader :options
|
13
15
|
|
14
16
|
def initialize(options = {})
|
15
|
-
|
17
|
+
raw_options = default_options.merge(stringify_keys(options))
|
18
|
+
|
19
|
+
@options = parse_options(raw_options)
|
16
20
|
@closed = false
|
17
21
|
end
|
18
22
|
|
@@ -29,19 +33,19 @@ module LogStasher
|
|
29
33
|
end
|
30
34
|
|
31
35
|
def facility
|
32
|
-
options[
|
36
|
+
options['facility']
|
33
37
|
end
|
34
38
|
|
35
39
|
def flags
|
36
|
-
options[
|
40
|
+
options['flags']
|
37
41
|
end
|
38
42
|
|
39
43
|
def identity
|
40
|
-
options[
|
44
|
+
options['identity']
|
41
45
|
end
|
42
46
|
|
43
47
|
def priority
|
44
|
-
options[
|
48
|
+
options['priority']
|
45
49
|
end
|
46
50
|
|
47
51
|
def write(log)
|
@@ -56,10 +60,10 @@ module LogStasher
|
|
56
60
|
|
57
61
|
def default_options
|
58
62
|
{
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
'identity' => 'logstasher',
|
64
|
+
'facility' => ::Syslog::LOG_LOCAL0,
|
65
|
+
'priority' => ::Syslog::LOG_INFO,
|
66
|
+
'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
|
63
67
|
}
|
64
68
|
end
|
65
69
|
|
@@ -75,9 +79,9 @@ module LogStasher
|
|
75
79
|
end
|
76
80
|
|
77
81
|
def parse_options(options)
|
78
|
-
options[
|
79
|
-
options[
|
80
|
-
options[
|
82
|
+
options['facility'] = parse_option(options['facility'])
|
83
|
+
options['priority'] = parse_option(options['priority'])
|
84
|
+
options['flags'] = parse_option(options['flags'])
|
81
85
|
options
|
82
86
|
end
|
83
87
|
|
data/lib/logstasher/device.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
module LogStasher
|
2
2
|
module Device
|
3
3
|
def self.factory(config)
|
4
|
-
config = config
|
5
|
-
type = config.delete(
|
4
|
+
config = stringify_keys(config)
|
5
|
+
type = config.delete('type') or fail ArgumentError, 'No "type" given'
|
6
6
|
|
7
7
|
case type
|
8
|
-
when
|
9
|
-
require
|
10
|
-
|
8
|
+
when 'redis', :redis then
|
9
|
+
require 'logstasher/device/redis'
|
11
10
|
::LogStasher::Device::Redis.new(config)
|
12
11
|
when "syslog", :syslog then
|
13
|
-
require
|
14
|
-
|
12
|
+
require 'logstasher/device/syslog'
|
15
13
|
::LogStasher::Device::Syslog.new(config)
|
16
14
|
else
|
17
15
|
fail ArgumentError, "Unknown type: #{type}"
|
18
16
|
end
|
19
17
|
end
|
18
|
+
|
19
|
+
def stringify_keys(hash)
|
20
|
+
hash.inject({}) do |stringified_hash, (key, value)|
|
21
|
+
stringified_hash[key.to_s] = value
|
22
|
+
stringified_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
module_function :stringify_keys
|
20
26
|
end
|
21
27
|
end
|
data/lib/logstasher/version.rb
CHANGED
@@ -7,8 +7,8 @@ describe LogStasher::Device::Redis do
|
|
7
7
|
let(:redis_mock) { double('Redis') }
|
8
8
|
|
9
9
|
let(:default_options) {{
|
10
|
-
key
|
11
|
-
data_type
|
10
|
+
'key' => 'logstash',
|
11
|
+
'data_type' => 'list'
|
12
12
|
}}
|
13
13
|
|
14
14
|
it 'has default options' do
|
@@ -22,9 +22,9 @@ describe LogStasher::Device::Redis do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'assumes unknown options are for redis' do
|
25
|
-
::Redis.should_receive(:new).with(hash_including(db
|
25
|
+
::Redis.should_receive(:new).with(hash_including('db' => '0'))
|
26
26
|
device = LogStasher::Device::Redis.new(db: '0')
|
27
|
-
device.redis_options.should eq(db
|
27
|
+
device.redis_options.should eq('db' => '0')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'has a key' do
|
@@ -5,10 +5,10 @@ require 'logstasher/device/syslog'
|
|
5
5
|
describe LogStasher::Device::Syslog do
|
6
6
|
|
7
7
|
let(:default_options) {{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
'identity' => 'logstasher',
|
9
|
+
'facility' => ::Syslog::LOG_LOCAL0,
|
10
|
+
'priority' => ::Syslog::LOG_INFO,
|
11
|
+
'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
|
12
12
|
}}
|
13
13
|
|
14
14
|
before { ::Syslog.stub(:log) }
|
@@ -9,15 +9,24 @@ describe LogStasher::Device do
|
|
9
9
|
it "expects a type" do
|
10
10
|
expect {
|
11
11
|
::LogStasher::Device.factory(:no => "type given")
|
12
|
-
}.to raise_error(ArgumentError,
|
12
|
+
}.to raise_error(ArgumentError, 'No "type" given')
|
13
13
|
end
|
14
14
|
|
15
15
|
it "forwards configuration options to the device" do
|
16
16
|
::LogStasher::Device::Redis.should_receive(:new).with(
|
17
|
-
|
17
|
+
'options' => "other", 'than' => "type"
|
18
18
|
)
|
19
19
|
::LogStasher::Device.factory(
|
20
|
-
|
20
|
+
'type' => 'redis', 'options' => 'other', :than => "type"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "accepts symbolized configuration keys" do
|
25
|
+
::LogStasher::Device::Redis.should_receive(:new).with(
|
26
|
+
'options' => "other", 'than' => "type"
|
27
|
+
)
|
28
|
+
::LogStasher::Device.factory(
|
29
|
+
:type => "redis", :options => "other", :than => "type"
|
21
30
|
)
|
22
31
|
end
|
23
32
|
|