Class: Fluent::Plugin::MattermostOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::MattermostOutput
- Defined in:
- lib/fluent/plugin/out_mattermost.rb
Instance Method Summary collapse
- #build_message(record) ⇒ Object
- #check_config_params ⇒ Object
- #configure(conf) ⇒ Object
- #get_infos(chunk) ⇒ Object
- #message(record) ⇒ Object
- #post(payload) ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Instance Method Details
#build_message(record) ⇒ Object
102 103 104 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 102 def (record) @message % record.to_json end |
#check_config_params ⇒ Object
106 107 108 109 110 111 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 106 def check_config_params() if @webhook_url.nil? || @channel_id.nil? || @message.nil? raise "Check in your Mattermost config, that all parameters in the configuration file are filled" abort end end |
#configure(conf) ⇒ Object
29 30 31 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 29 def configure(conf) super end |
#get_infos(chunk) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 92 def get_infos(chunk) = [] << "\n" chunk.msgpack_each do |time, record| << "#{(record)}\n" end return end |
#message(record) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 77 def (record) payload = [{ "author_name": "Fluentd", "thumb_url": "https://coralogix.com/wp-content/uploads/2020/04/fluentd-guide-700x430.png", "color": @message_color, "fields": [ { "short": false, "title": @message_title, "value": record }] }] return payload end |
#post(payload) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 52 def post(payload) url = URI(@webhook_url) https = Net::HTTP.new(url.host, url.port) https.use_ssl = @enable_tls if !@ca_path.nil? and @enable_tls == true https.ca_path = @ca_path end request = Net::HTTP::Post.new(url) request["Content-Type"] = "application/json" request.body = JSON.dump({ "channel_id": @channel_id, "attachments": (payload) }) response = https.request(request) if response.read_body != "ok" log.error "response from mattermost: ", response.read_body else puts response.read_body end end |
#start ⇒ Object
33 34 35 36 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 33 def start super check_config_params end |
#write(chunk) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fluent/plugin/out_mattermost.rb', line 38 def write(chunk) begin = get_infos(chunk) post() rescue Timeout::Error => e log.warn "out_mattermost:", :error => e.to_s, :error_class => e.class.to_s raise e # let Fluentd retry rescue => e log.error "out_mattermost:", :error => e.to_s, :error_class => e.class.to_s log.warn_backtrace e.backtrace end end |