fluent-plugin-slackboard 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65936dad12c5ddd86bc0b0f0f21e60e8aced9363
4
+ data.tar.gz: 570f656b53244c703762a4307e68cad385ba4c58
5
+ SHA512:
6
+ metadata.gz: 80f3f4d9e75557930e1267b8bde9877006e52129b47ea71ec2a0d4ed2407ed068b71c31a24fffb11ad695c5ba3961ba07913e4de3fd082505b5bea131a50617d
7
+ data.tar.gz: 1d60ec05bbc2dc08ac5aa1cf4f911416f6f8a5ebf696e6ff2efa9a082fe7a63f45b8b3248499136161548973e5e40fa515f22714572337ba8ce1496896fc743b
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ Vagrantfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-slackboard.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Tatsuhiko Kubo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # fluent-plugin-slackboard
2
+
3
+ fluent-plugin-slackboard proxies a message to [slackboard](https://github.com/cubicdaiya/slackboard).
4
+
5
+ <!--
6
+ ## Installation
7
+
8
+ Install it using gem:
9
+
10
+ ```
11
+ gem install fluent-plugin-slackboard
12
+ ```
13
+ -->
14
+
15
+ ## Usage
16
+
17
+ ```
18
+ <match>
19
+ type slackboard
20
+ # required
21
+ slackboard_host host
22
+ slackboard_port port
23
+ slackboard_channel random
24
+ slackboard_fetch_key message
25
+ # optional
26
+ slackboard_username slackboard
27
+ slackboard_icon_emoji :clipboard:
28
+ slackboard_parse true
29
+ slackboard_sync false
30
+ </match>
31
+ ```
32
+
33
+ ## License
34
+
35
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-slackboard"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Tatsuhiko Kubo"]
9
+ spec.email = ["cubicdaiya@gmail.com"]
10
+ spec.summary = %q{plugin for proxying message to slackboard}
11
+ spec.description = %q{plugin for proxying message to slackboard}
12
+ spec.homepage = "https://github.com/cubicdaiya/fluent-plugin-slackboard"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,102 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'net/http'
4
+
5
+ module Fluent
6
+ class SlackboardOutput < BufferedOutput
7
+ Fluent::Plugin.register_output('slackboard', self)
8
+
9
+ include SetTimeKeyMixin
10
+ include SetTagKeyMixin
11
+
12
+ config_set_default :include_time_key, true
13
+ config_set_default :include_tag_key, true
14
+
15
+ config_param :slackboard_host, :string, default: "" # slackboard hostname
16
+ config_param :slackboard_port, :string, default: "" # slackboard port
17
+ config_param :slackboard_channel, :string, default: "" # slack channel
18
+ config_param :slackboard_fetch_key, :string, default: "" # fetched key
19
+ config_param :slackboard_username, :string, default: "" # slack username
20
+ config_param :slackboard_icon_emoji, :string, default: "" # slack icon emoji
21
+ config_param :slackboard_parse, :string, default: "full" # parse option for slack
22
+ config_param :slackboard_sync, :bool, default: false # synchronous proxing
23
+
24
+ def initialize
25
+ super
26
+ end
27
+
28
+ def configure(conf)
29
+ super
30
+
31
+ if @slackboard_host == ""
32
+ raise Fluent::ConfigError.new "`slackboard_host` is empty"
33
+ end
34
+
35
+ if @slackboard_port == ""
36
+ raise Fluent::ConfigError.new "`slackboard_port` is empty"
37
+ end
38
+
39
+ @slackboard_uri = URI.parse "http://" + @slackboard_host + ":" + @slackboard_port + "/notify-directly"
40
+
41
+ if @slackboard_channel == ""
42
+ raise Fluent::ConfigError.new "`slackboard_channel` is empty"
43
+ end
44
+ @slackboard_channel = '#' + @slackboard_channel unless @slackboard_channel.start_with? '#'
45
+
46
+ if @slackboard_fetch_key == ""
47
+ raise Fluent::ConfigError.new "`slackboard_fetch_key` is empty"
48
+ end
49
+
50
+ if @slackboard_username == ""
51
+ @slackboard_username = "slackboard"
52
+ end
53
+
54
+ if @slackboard_icon_emoji == ""
55
+ @slackboard_icon_emoji = ":clipboard:"
56
+ end
57
+ end
58
+
59
+ def format(tag, time, record)
60
+ [tag, time, record].to_msgpack
61
+ end
62
+
63
+ def write(chunk)
64
+ begin
65
+ payloads = build_payloads chunk
66
+ payloads.each { |payload|
67
+ req = Net::HTTP::Post.new @slackboard_uri.path
68
+ req.body = payload.to_json
69
+ res = Net::HTTP.start(@slackboard_uri.host, @slackboard_uri.port) { |http|
70
+ http.request req
71
+ }
72
+ }
73
+ rescue Timeout::Error => e
74
+ log.warn "out_slackboard:", :error => e.to_s, :error_class => e.class.to_s
75
+ raise e
76
+ rescue => e
77
+ log.error "out_slackboard:", :error => e.to_s, :error_class => e.class.to_s
78
+ log.warn_backtrace e.backtrace
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def build_payloads(chunk)
85
+ payloads = []
86
+ chunk.msgpack_each do |tag, time, record|
87
+ payload = {}
88
+ payload["payload"] = {
89
+ :channel => @slackboard_channel,
90
+ :username => @slackboard_username,
91
+ :icon_emoji => @slackboard_icon_emoji,
92
+ :text => record[@slackboard_fetch_key],
93
+ :parse => @slackboard_parse,
94
+ }
95
+ payload["sync"] = @slackboard_sync
96
+ payloads << payload
97
+ end
98
+ payloads
99
+ end
100
+
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-slackboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuhiko Kubo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: plugin for proxying message to slackboard
42
+ email:
43
+ - cubicdaiya@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - fluent-plugin-slackboard.gemspec
54
+ - lib/fluent/plugin/out_slackboard.rb
55
+ homepage: https://github.com/cubicdaiya/fluent-plugin-slackboard
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: plugin for proxying message to slackboard
79
+ test_files: []