fluent-plugin-mattermost 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/README.md +50 -0
- data/Rakefile +13 -0
- data/documentation/docker-installation.md +14 -0
- data/documentation/installation.md +18 -0
- data/fluent-plugin-mattermost.gemspec +27 -0
- data/lib/fluent/plugin/out_mattermost.rb +109 -0
- data/test/helper.rb +8 -0
- data/test/plugin/test_out_mattermost.rb +18 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 137190fc7cefe9e27caccfe3ae5367ea51bd8cd8121d5bd24b5b9df9c212a4b9
|
4
|
+
data.tar.gz: 9fdee0c49ee52085529a35f427e1ac22cd285ec441f9146565b2ddc7facb405e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 462bcc71f9d39527e2e9ee6ad69987feb5fc7e49b8a4b10bee5c7cfca39be373e1b6790e17dfc0b611e88790e2a467f5724ac7cb3a4e891f2d2c715e6e780788
|
7
|
+
data.tar.gz: cdcff519b3dbcdfe50db16e2e46b5b8b372663eb0c540a386e883e85dbf00bc08e852b8a8be1a2a51c9a3ed7f2ae1f5c49b4616d02b5d6c206ef0bf9d12ad1d1
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# fluent-plugin-mattermost
|
2
|
+
|
3
|
+
[Fluentd](https://fluentd.org/) output plugin to send message to Mattermost.
|
4
|
+
|
5
|
+
With this plugin you can send messages directly to a channel in Mattermost (for example in case of errors).
|
6
|
+
|
7
|
+
# Installation requirement
|
8
|
+
|
9
|
+
For the plugin to work properly, you need to have the following gems installed
|
10
|
+
- fluent-logger
|
11
|
+
```
|
12
|
+
$ gem install fluent-logger
|
13
|
+
```
|
14
|
+
|
15
|
+
# Installation
|
16
|
+
|
17
|
+
[Installation](documentation/installation.md)
|
18
|
+
[Docker-installation](documentation/docker-installation.md)
|
19
|
+
|
20
|
+
# Usage (Incoming Webhook)
|
21
|
+
Link for
|
22
|
+
[Mattermost incoming webhook](https://docs.mattermost.com/developer/webhooks-incoming.html)
|
23
|
+
|
24
|
+
```apache
|
25
|
+
<match mattermost>
|
26
|
+
@type mattermost
|
27
|
+
webhook_url https://xxx.xx/hooks/xxxxxxxxxxxxxxx
|
28
|
+
channel_id xxxxxxxxxxxxxxx
|
29
|
+
message_color "#FFA500"
|
30
|
+
message_title mattermost
|
31
|
+
message %s
|
32
|
+
enable_tls true
|
33
|
+
</match>
|
34
|
+
```
|
35
|
+
|
36
|
+
### Parameter
|
37
|
+
|
38
|
+
|parameter|description|type|dafault|
|
39
|
+
|---|---|---|---|
|
40
|
+
|webhook_url|Incoming Webhook URI (Required for Incoming Webhook mode). See https://docs.mattermost.com/developer/webhooks-incoming.html|string|nil|
|
41
|
+
|channel_id|the id of the channel where you want to receive the information|string|nil|
|
42
|
+
|message_color|color of the message you are sending, the format is hex code|string|#A9A9A9|
|
43
|
+
|message_title|title you want to add to the message|string|fluent_title_default
|
44
|
+
|message|The message you want to send, can be a static message, which you add at this point, or you can receive the fluent infos with the %s|string|nil
|
45
|
+
|enable_tls|you can set the communication channel if it uses tls|bool|true|
|
46
|
+
|
47
|
+
## Copyright
|
48
|
+
|
49
|
+
* Copyright(c) 2021- [levigo gruppe](https://www.levigo.de/)
|
50
|
+
* License
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs.push("lib", "test")
|
8
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
9
|
+
t.verbose = true
|
10
|
+
t.warning = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: [:test]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Docker installation
|
2
|
+
|
3
|
+
### Dockerfile
|
4
|
+
|
5
|
+
You need to enter the repository where you can download and later install the plugin. Here is a snippet code
|
6
|
+
**Attention:** If you use gitlab, don't forget to enter the token for oauth2
|
7
|
+
|
8
|
+
```docker
|
9
|
+
...
|
10
|
+
|
11
|
+
RUN gem install fluent-plugin-mattermost
|
12
|
+
|
13
|
+
...
|
14
|
+
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Installation
|
2
|
+
|
3
|
+
To install the plugin you need to download the package directly from Gitlab and run the installation.
|
4
|
+
Link to repository:
|
5
|
+
|
6
|
+
[fluent-plugin-mattermost](https://gitlab.levigo.systems/codefactory/fluent-plugin-mattermost)
|
7
|
+
|
8
|
+
```
|
9
|
+
$ gem install bundler
|
10
|
+
```
|
11
|
+
```
|
12
|
+
$ rake build
|
13
|
+
```
|
14
|
+
```
|
15
|
+
$ gem install --local ./pkg/fluent-plugin-mattermost-0.1.0.gem
|
16
|
+
```
|
17
|
+
|
18
|
+
The installation is completed
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "fluent-plugin-mattermost"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.authors = ["Pierluigi Minardi"]
|
8
|
+
spec.email = ["p.minardi@levigo.de"]
|
9
|
+
|
10
|
+
spec.summary = "fluent-plugin-mattemost"
|
11
|
+
spec.description = "This plugin allows you to send messages to mattermost in case of errors"
|
12
|
+
spec.homepage = "https://www.levigo.de"
|
13
|
+
spec.license = "Apache-2.0"
|
14
|
+
|
15
|
+
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.files = files
|
19
|
+
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = test_files
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.2.31"
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0.6"
|
25
|
+
spec.add_development_dependency "test-unit", "~> 3.3.9"
|
26
|
+
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
27
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require "fluent/plugin/output"
|
2
|
+
require 'fluent-logger'
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'logger'
|
7
|
+
require "json"
|
8
|
+
|
9
|
+
module Fluent
|
10
|
+
module Plugin
|
11
|
+
class MattermostOutput < Fluent::Plugin::Output
|
12
|
+
Fluent::Plugin.register_output("mattermost", self)
|
13
|
+
|
14
|
+
# Required parameter: The configuration must have this parameter like 'param1 10'.
|
15
|
+
config_param :webhook_url, :string, default: nil
|
16
|
+
|
17
|
+
config_param :channel_id, :string, default: nil
|
18
|
+
|
19
|
+
config_param :message_title, :string, default: "fluent_title_default"
|
20
|
+
|
21
|
+
config_param :message_color, :string, default: "#A9A9A9"
|
22
|
+
|
23
|
+
config_param :message, :string, default: nil
|
24
|
+
|
25
|
+
config_param :enable_tls, :bool, default: true
|
26
|
+
|
27
|
+
def configure(conf)
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
super
|
33
|
+
check_config_params
|
34
|
+
end
|
35
|
+
|
36
|
+
def write(chunk)
|
37
|
+
begin
|
38
|
+
message = get_infos(chunk)
|
39
|
+
|
40
|
+
post(message)
|
41
|
+
rescue Timeout::Error => e
|
42
|
+
log.warn "out_mattermost:", :error => e.to_s, :error_class => e.class.to_s
|
43
|
+
raise e # let Fluentd retry
|
44
|
+
rescue => e
|
45
|
+
log.error "out_mattermost:", :error => e.to_s, :error_class => e.class.to_s
|
46
|
+
log.warn_backtrace e.backtrace
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def post(payload)
|
51
|
+
|
52
|
+
url = URI(@webhook_url)
|
53
|
+
|
54
|
+
https = Net::HTTP.new(url.host, url.port)
|
55
|
+
https.use_ssl = @enable_tls
|
56
|
+
|
57
|
+
request = Net::HTTP::Post.new(url)
|
58
|
+
request["Content-Type"] = "application/json"
|
59
|
+
request.body = JSON.dump({
|
60
|
+
"channel_id": @channel_id,
|
61
|
+
"attachments": message(payload)
|
62
|
+
})
|
63
|
+
response = https.request(request)
|
64
|
+
|
65
|
+
if response.read_body != "ok"
|
66
|
+
log.error "response from mattermost: ", response.read_body
|
67
|
+
else
|
68
|
+
puts response.read_body
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def message(record)
|
73
|
+
payload = [{
|
74
|
+
"author_name": "Fluentd",
|
75
|
+
"thumb_url": "https://coralogix.com/wp-content/uploads/2020/04/fluentd-guide-700x430.png",
|
76
|
+
"color": @message_color,
|
77
|
+
"fields": [
|
78
|
+
{
|
79
|
+
"short": false,
|
80
|
+
"title": @message_title,
|
81
|
+
"value": record
|
82
|
+
}]
|
83
|
+
}]
|
84
|
+
return payload
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_infos(chunk)
|
88
|
+
messages = []
|
89
|
+
messages << "\n"
|
90
|
+
chunk.msgpack_each do |time, record|
|
91
|
+
messages << "#{build_message(record)}\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
return messages
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_message(record)
|
98
|
+
@message % record.to_json
|
99
|
+
end
|
100
|
+
|
101
|
+
def check_config_params()
|
102
|
+
if @webhook_url.nil? || @channel_id.nil? || @message.nil?
|
103
|
+
raise "Check in your Mattermost config, that all parameters in the configuration file are filled"
|
104
|
+
abort
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
2
|
+
require "test-unit"
|
3
|
+
require "fluent/test"
|
4
|
+
require "fluent/test/driver/output"
|
5
|
+
require "fluent/test/helpers"
|
6
|
+
|
7
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
8
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/out_mattermost.rb"
|
3
|
+
|
4
|
+
class MattermostOutputTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
test "failure" do
|
10
|
+
flunk
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_driver(conf)
|
16
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::MattermostOutput).configure(conf)
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-mattermost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pierluigi Minardi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-29 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: 2.2.31
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.31
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 13.0.6
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 13.0.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.9
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.10
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.14.10
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
75
|
+
description: This plugin allows you to send messages to mattermost in case of errors
|
76
|
+
email:
|
77
|
+
- p.minardi@levigo.de
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- Gemfile
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- documentation/docker-installation.md
|
87
|
+
- documentation/installation.md
|
88
|
+
- fluent-plugin-mattermost.gemspec
|
89
|
+
- lib/fluent/plugin/out_mattermost.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/plugin/test_out_mattermost.rb
|
92
|
+
homepage: https://www.levigo.de
|
93
|
+
licenses:
|
94
|
+
- Apache-2.0
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.2.22
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: fluent-plugin-mattemost
|
115
|
+
test_files:
|
116
|
+
- test/helper.rb
|
117
|
+
- test/plugin/test_out_mattermost.rb
|