fluent-plugin-slack 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/fluent/plugin/out_buffered_slack.rb +14 -14
- data/test/plugin/out_buffered_slack.rb +24 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODA4MDM5NWYzOGM1MzhlYWRkMmUzZWI2Mjg4ODkzNDFiYjRkN2RhOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjYxOTZhMDQxY2VmODhhNDQyMGE1N2ZjODZlOTI1YjkwNTExYzVhMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzA0N2JiMGRjZmVjYWRmYmM2ZTM0ZDQ1OWM1YTNiYTJkNTQxZjhhNTc1ZDRj
|
10
|
+
YTJjZWUwY2RkZTc2Y2U3NGZlZTJlNTliN2RlMGM2OGI1NWNhZmNmMWE4OWIy
|
11
|
+
NTFjMzkxMmU1NjAxMWRlN2EyMjlhYTZlODM1NGNkYjA0OWU0Mjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTAzMDk3NWY3NTMzZWIyZGVlNTAwZjYzMmEzM2QzNTE5ZDgwOWI1MjQyODRi
|
14
|
+
ZWMzNTQwMTc0N2FiZDc5YTRhMjc4OGJhMGMyOTg3MmMzNWM2OGI2MDExM2Qz
|
15
|
+
MTA0YWU2NGU5MWVkZjg0ZTgyNzE5ZTM2MjNkZGJkYmViMTAyMTc=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -11,33 +11,33 @@ module Fluent
|
|
11
11
|
attr_reader :slack
|
12
12
|
|
13
13
|
def format(tag, time, record)
|
14
|
-
[tag, time, record].
|
14
|
+
[tag, time, record].to_msgpack
|
15
15
|
end
|
16
16
|
|
17
17
|
def write(chunk)
|
18
18
|
messages = {}
|
19
|
-
chunk.msgpack_each do |
|
20
|
-
messages[tag] = ''
|
19
|
+
chunk.msgpack_each do |tag, time, record|
|
20
|
+
messages[tag] = '' if messages[tag].nil?
|
21
21
|
messages[tag] << "[#{Time.at(time)}] #{record['message']}\n"
|
22
22
|
end
|
23
23
|
messages.each do |tag, value|
|
24
|
-
|
24
|
+
field = {
|
25
25
|
title: tag,
|
26
26
|
value: value
|
27
27
|
}
|
28
28
|
@slack.say(
|
29
29
|
nil,
|
30
|
-
channel: @channel,
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
{ channel: @channel,
|
31
|
+
username: @username,
|
32
|
+
icon_emoji: @icon_emoji,
|
33
|
+
attachments: [{
|
34
|
+
fallback: tag,
|
35
|
+
color: @color,
|
36
|
+
fields: [ field ]
|
37
|
+
}]})
|
38
38
|
end
|
39
39
|
rescue => e
|
40
|
-
$log.error("Slack Error: #{e} / #{e.message}")
|
40
|
+
$log.error("Slack Error: #{e.backtrace[0]} / #{e.message}")
|
41
41
|
end
|
42
42
|
|
43
43
|
def initialize
|
@@ -48,7 +48,7 @@ module Fluent
|
|
48
48
|
def configure(conf)
|
49
49
|
super
|
50
50
|
@slack = Slackr::Webhook.new(conf['team'], conf['api_key'])
|
51
|
-
@channel = conf['channel']
|
51
|
+
@channel = '#' + conf['channel']
|
52
52
|
@username = conf['username'] || 'fluentd'
|
53
53
|
@color = conf['color'] || 'good'
|
54
54
|
@icon_emoji = conf['icon_emoji'] || ':question:'
|
@@ -17,8 +17,8 @@ class BufferedSlackOutputTest < Test::Unit::TestCase
|
|
17
17
|
username testuser
|
18
18
|
color good
|
19
19
|
icon_emoji :ghost:
|
20
|
-
buffer_type memory
|
21
20
|
compress gz
|
21
|
+
buffer_path ./test/tmp
|
22
22
|
utc
|
23
23
|
]
|
24
24
|
|
@@ -29,8 +29,22 @@ class BufferedSlackOutputTest < Test::Unit::TestCase
|
|
29
29
|
def test_format
|
30
30
|
d = create_driver
|
31
31
|
time = Time.parse("2014-01-01 22:00:00 UTC").to_i
|
32
|
+
d.tag = 'test'
|
33
|
+
stub(d.instance.slack).say(
|
34
|
+
nil,
|
35
|
+
channel: '#test',
|
36
|
+
username: 'testuser',
|
37
|
+
icon_emoji: ':ghost:',
|
38
|
+
attachments: [{
|
39
|
+
fallback: d.tag,
|
40
|
+
color: 'good',
|
41
|
+
fields: [
|
42
|
+
{
|
43
|
+
title: d.tag,
|
44
|
+
value: "[#{Time.at(time)}] sowawa\n"
|
45
|
+
}]}])
|
32
46
|
d.emit({message: 'sowawa'}, time)
|
33
|
-
d.expect_format %[#{['test', time, {message: 'sowawa'}].
|
47
|
+
d.expect_format %[#{['test', time, {message: 'sowawa'}].to_msgpack}]
|
34
48
|
d.run
|
35
49
|
end
|
36
50
|
|
@@ -40,17 +54,18 @@ class BufferedSlackOutputTest < Test::Unit::TestCase
|
|
40
54
|
d.tag = 'test'
|
41
55
|
stub(d.instance.slack).say(
|
42
56
|
nil,
|
43
|
-
channel: 'test',
|
57
|
+
channel: '#test',
|
44
58
|
username: 'testuser',
|
45
|
-
icon_emoji: 'ghost',
|
46
|
-
attachments: {
|
59
|
+
icon_emoji: ':ghost:',
|
60
|
+
attachments: [{
|
47
61
|
fallback: d.tag,
|
48
62
|
color: 'good',
|
49
63
|
fields: [
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
{
|
65
|
+
title: d.tag,
|
66
|
+
value: "[#{Time.at(time)}] sowawa1\n" +
|
67
|
+
"[#{Time.at(time)}] sowawa2\n"
|
68
|
+
}]}])
|
54
69
|
d.emit({message: 'sowawa1'}, time)
|
55
70
|
d.emit({message: 'sowawa2'}, time)
|
56
71
|
d.run
|