Code Monkey home page Code Monkey logo

fluent-plugin-slack's Introduction

fluent-plugin-slack Build Status

Installation

$ fluent-gem install fluent-plugin-slack

Usage (Incoming Webhook)

<match slack>
  @type slack
  webhook_url https://hooks.slack.com/services/XXX/XXX/XXX
  channel general
  username sowasowa
  icon_emoji :ghost:
  flush_interval 60s
</match>
fluent_logger.post('slack', {
  :message  => 'Hello<br>World!'
})

Usage (Slackbot)

<match slack>
  @type slack
  slackbot_url https://xxxx.slack.com/services/hooks/slackbot?token=XXXXXXXXX
  channel general
  flush_interval 60s
</match>
fluent_logger.post('slack', {
  :message  => 'Hello<br>World!'
})

Usage (Web API a.k.a. Bots)

<match slack>
  @type slack
  token xoxb-XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX
  channel C061EG9SL
  username sowasowa
  icon_emoji :ghost:
  flush_interval 60s
</match>
fluent_logger.post('slack', {
  :message  => 'Hello<br>World!'
})

Parameter

parameter description default
webhook_url Incoming Webhook URI (Required for Incoming Webhook mode). See https://api.slack.com/incoming-webhooks
slackbot_url Slackbot URI (Required for Slackbot mode). See https://api.slack.com/slackbot. NOTE: most of optional parameters such as username, color, icon_emoji, icon_url, and title are not available for this mode, but Desktop Notification via Highlight Words works with only this mode
token Token for Web API (Required for Web API mode). See https://api.slack.com/web
as_user post messages as a bot user. See https://api.slack.com/bot-users#post_messages_and_react_to_users. NOTE: This parameter is only enabled if you use the Web API with your bot token. You cannot use both of username and icon_emoji(icon_url) when you set this parameter to true. nil
username name of bot nil
color color to use such as good or bad. See Color section of https://api.slack.com/docs/attachments. NOTE: This parameter must not be specified to receive Desktop Notification via Mentions in cases of Incoming Webhook and Slack Web API nil
icon_emoji emoji to use as the icon. either of icon_emoji or icon_url can be specified nil
icon_url url to an image to use as the icon. either of icon_emoji or icon_url can be specified nil
mrkdwn enable formatting. see https://api.slack.com/docs/formatting true
link_names find and link channel names and usernames. NOTE: This parameter must be true to receive Desktop Notification via Mentions in cases of Incoming Webhook and Slack Web API true
parse change how messages are treated. none or full can be specified. See Parsing mode section of https://api.slack.com/docs/formatting nil
channel Channel name or id to send messages (without first '#'). Channel ID is recommended because it is unchanged even if a channel is renamed
channel_keys keys used to format channel. %s will be replaced with value specified by channel_keys if this option is used nil
title title format. %s will be replaced with value specified by title_keys. title is created from the first appeared record on each tag. NOTE: This parameter must not be specified to receive Desktop Notification via Mentions in cases of Incoming Webhook and Slack Web API nil
title_keys keys used to format the title nil
message message format. %s will be replaced with value specified by message_keys %s
message_keys keys used to format messages message
auto_channels_create Create channels if not exist. Not available for Incoming Webhook mode (since Incoming Webhook is specific to a channel). A web api token for Normal User is required (Bot User can not create channels. See https://api.slack.com/bot-users) false
https_proxy https proxy url such as https://proxy.foo.bar:443 nil
verbose_fallback Originally, only title is used for the fallback which is the message shown on popup if title is given. If this option is set to be true, messages are also included to the fallback attribute false

fluent-plugin-slack uses SetTimeKeyMixin and SetTagKeyMixin, so you can also use:

parameter description default
timezone timezone such as Asia/Tokyo
localtime use localtime as timezone true
utc use utc as timezone
time_key key name for time used in xxx_keys time
time_format time format. This will be formatted with Time#strftime. %H:%M:%S
tag_key key name for tag used in xxx_keys tag

fluent-plugin-slack is a kind of BufferedOutput plugin, so you can also use Buffer Parameters.

FAQ

Desktop Notification seems not working?

Currently, slack.com has following limitations:

  1. Desktop Notification via both Highlight Words and Mentions works only with Slackbot Remote Control
  2. Desktop Notification via Mentions works for the text field if link_names parameter is specified in cases of Incoming Webhook and Slack Web API, that is,
  • Desktop Notification does not work for the attachments filed (used in color and title)
  • Desktop Notification via Highlight Words does not work for Incoming Webhook and Slack Web API anyway

ChangeLog

See CHANGELOG.md for details.

Contributors

Copyright

  • Copyright:: Copyright (c) 2014- Keisuke SOGAWA
  • License:: Apache License, Version 2.0

fluent-plugin-slack's People

Contributors

cosmo0920 avatar eisuke avatar fujiwara avatar hirakiuc avatar hokkai7go avatar jwyjoy avatar kenjiskywalker avatar okkez avatar sett4 avatar sonots avatar sowawa avatar sue445 avatar yacchin1205 avatar yoheimuta avatar yoichi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluent-plugin-slack's Issues

multi worker start failed

when i use:

<system>
  workers 4
</system>

[error]: config error file="/fluentd/etc/fluent.conf" error_class=Fluent::ConfigError error="Plugin 'buffered_slack' does not support multi workers configuration (Fluent::SlackOutput)"

The specified key 'message' not found

I'm trying to use your slack plugin, but the logs generated by my docker engine seem to be formatted as a json with a log entry instead of a message one.

I'm using docker 1.9.1 (API version 1.21), fluentd 0.12.22 and fluent-plugin-slack (0.6.2). My fluentd configuration is:

<match slack.*>
  type slack
  webhook_url  https://hooks.slack.com/services/x/y/z
  channel monitoring
  username microservices
  icon_emoji :ghost:
  flush_interval 60s
</match>

And after trying a docker run -d --log-driver=fluentd --log-opt fluentd-tag="slack.test" alpine echo "hello", I obtain the next warning from fluentd:

2016-05-03 14:30:17 +0000 [warn]: out_slack: the specified key 'message' not found in record. [{"container_id"=>"7e4dde134cc57379c0a924b8c5ad3f5b463d5d490ca2061561a6261e98da4c34", "container_name"=>"/goofy_babbage", "source"=>"stdout", "log"=>"hello", "time"=>"14:29:35", "tag"=>"slack.test"}]
2016-05-03 14:30:17 +0000 [info]: out_slack: post_message {:channel=>"#devops", :text=>"\n", :username=>"ecs", :icon_emoji=>":ghost:", :mrkdwn=>true, :link_names=>true}

Any idea?

Can't send

I try to send logs to my slack team using this but it won't send any logs.

2015-05-14 21:18:04 +0900 [info]: out_slack: post_message {:channel=>"#logs", :text=>"oijwef\n", :mrkdwn=>true, :link_names=>true}
2015-05-14 21:18:04 +0900 [warn]: temporarily failed to flush the buffer. next_retry=2015-05-14 21:20:03 +0900 error_class="NameError" error="uninitialized constant Net::OpenTimeout" instance=70183716234940
  2015-05-14 21:18:04 +0900 [warn]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluent-plugin-slack-0.6.0/lib/fluent/plugin/out_slack.rb:131:in `rescue in write'
  2015-05-14 21:18:04 +0900 [warn]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluent-plugin-slack-0.6.0/lib/fluent/plugin/out_slack.rb:128:in `write'
  2015-05-14 21:18:04 +0900 [warn]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluentd-0.10.55/lib/fluent/buffer.rb:296:in `write_chunk'
  2015-05-14 21:18:04 +0900 [warn]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluentd-0.10.55/lib/fluent/buffer.rb:276:in `pop'
  2015-05-14 21:18:04 +0900 [warn]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluentd-0.10.55/lib/fluent/output.rb:311:in `try_flush'
  2015-05-14 21:18:04 +0900 [warn]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluentd-0.10.55/lib/fluent/output.rb:132:in `run'
2015-05-14 21:18:06 +0900 applicationlog.testtest: {"message":"oijwef"}

my config

<match applicationlog.testtest>
type copy
<store>
  type stdout
</store>
<store>
  type slack
  webhook_url http://hooks.slack.com/services/xxxxxx/xxxxx/xxxxxxxxx
  channel logs
  flush_interval 1s
</store>
</match>

Travis

@sowawa Could you turn on travis and put a badge to it on README.md?

Toward v2

This issue describes a loadmap to v2.

Once release v1 (nothing is changed with v0.xx) to do semantic versioning, then work for v2.

Breaking changes:

  1. To fix #28, revert escaping special characters in message.
  2. By historical reasons, default values of some parameters are different with Slack API default values. Align with Slack API default values.
  3. Allow adding arbitrary slack parameters
  4. Migrate to Fluentd v0.14 (v1) API.

Allow adding arbitrary slack parameters

Slack API itself evolves, and will support new parameters. I want to support new parameters without updating slack plugin.

Maybe we can achieve by changing interfaces as:

<match slack>
  @type slack
  webhook_url https://hooks.slack.com/services/XXX/XXX/XXX
  <payload>
    channel general
    username sonots
    # arbitrary key=val parameters can be added
  </payload>
</match>

If we support only Fluentd >= v0.14.20, users can get dynamic values from nested records via record accessor as:

ref. https://www.fluentd.org/blog/fluentd-v0.14.20-has-been-released

<match slack>
  @type slack
  webhook_url https://hooks.slack.com/services/XXX/XXX/XXX
  <payload>
    channel $.foo.channel
    username $["username"]
    # arbitrary key=val parameters can be added
  </payload>
</match>

TODO: Test whether we can write ruby codes combined with record accessor as #{$.text..gsub(/&/, '&amp;').gsub(/</, '&lt;').gsub(/>/, '&gt;')} (hmm, looks not possible) so that users can write their own escaping function by themselves to support #22.

TODO: Think how to support nested parameters. Create config_section dynamically?

payload
  channel
  username
  attachments
     blah blah

Question: Use mulitple fields

Thank you for the awesome slack plugin. I am trying to post a slack attachment message with multiple fields but i unable to achieve it. I am only able to create single field per msg using the following configuration

<match kube.**>
      @type slack
      webhook_url "#{ENV['SLACK_WEBHOOK_URL']}"
      channel "#{ENV['SLACK_CHANNEL']}"
      username fluentd
      message %s
      message_keys log
      title Pod: %s
      title_keys kube_tag
      icon_emoji :ghost:
      flush_interval 1s
      mrkdwn true
      color danger
</match>

screen shot 2017-12-20 at 6 51 44 pm

I would like to add other fields as well but not able to figure out how can we achieve it.

Truncating of messages

I have recently come to this issue, which is still a problem. My messages are truncated even after not that many characters roughly 2k. Any idea how to solve that?

How come no examples for sending to Slack?

The examples seem to show how to receive messages from Slack, rather than sending to Slack. I'm not sure why anyone would want the former. I tried to get it working but failed. I've documented the issue here: https://serverfault.com/questions/1160392/how-can-i-resolve-fluentd-plugin-slack-error-when-starting-fluentd-daemon-undef

It would be awesome if someone could help me get this working, or post some examples of sending to Slack to the README. I tried getting help on the Slack server for Fluent but no-one bit.

`encode' / "\xE3" from ASCII-8BIT to UTF-8

In our production environment, to_json errors have occurred after updating td-agent v2.3.5.

2017-05-16 17:20:23 +0900 [error]: plugin/out_slack.rb:231:rescue in write: out_slack: error="\"\\xE3\" from ASCII-8BIT to UTF-8" error_class="Encoding::UndefinedConversionError"

This error is when fluent-plugin-slack to_json the output of fluent-plugin-rds-slowlog (v0.7.0).
Specifically, in-rds-slowlog outputs ASCII-8BIT encoded character string, but out_slack's to_json expects UTF-8 encoded character string, so it is an error.

Since the same thing can happen besides in-rds-slowlog, I want to use Yajl instead of JSON, because to_json method raise error when receive multibyte text.

How about that? If so, I will make a PR.

Escaping < and > breaks formatted links

In c5b7158 code was added to escape <, >, and & per Slack's formatting Docs. However, by escaping these values across the board, formatted links like the following no longer work: <https://google.com|My Link>

can not find slack plugin

I have installed the slack plugin. When checked with "gem list", it shows "fluent-plugin-slack (0.6.7)". And when i started fluentd, it shows "config error file="/etc/td-agent/td-agent.conf" error_class=Fluent::ConfigError error="Unknown output plugin 'slack'. Run 'gem search -rd fluent-plugin' to find plugins". It seems the plugin does not install, why?

Ability to use more than one slack plugin with custom icons/username options

Hi there,

I have the following use case:

  • in my fluentd config I'm splitting logs into error and performance channels (tags)
  • so I want to apply different slack icons/usernames per each slack plugin (Now it's impossible because slack plugin caches the common config and icon_emoji/username options are part of it)

Can not find slack plugin

After using "fluent-gem install fluent-plugin-slack" to install slack plugin, when start td-agent.service, failed due to config error file="/etc/td-agent/td-agent.conf" error_class=Fluent::ConfigError error="Unknown output plugin 'slack'. Run 'gem search -rd fluent-plugin' to find plugins". It's seems strange.

multiple fluentd events are getting aggregated to single event

How to split it to individual events ?
I m using labels to route from fluentd source to slack output,
Using buffered parameters :

chunk_limit_size 1k
chunk_limit_records 1
flush_interval 1s

How to convert them to single message with one event ?
Also the message is not getting truncated.

Any help ?

Line breaks in posted value are ignored

Running into an issue with the posted value data not actually honouring line breaks.

From the log:
out_slack: post_message {:attachments=>[{:fallback=>"Log:logs.one.one-api.err.err.log Host:one-prod-ip-10-0-7-52", :fields=>[{:title=>"Log:logs.foo.foo-api.err.err.log Host:foo-prod-ip-10-0-7-52", :value=>"Error: Invalid LocationID \nStatus Code: 404\nType: notFoundError\n"}], :color=>"danger", :mrkdwn_in=>["text", "fields"]}], :channel=>"#jenkins", :username=>"fluentd", :icon_emoji=>":ghost:", :mrkdwn=>true, :link_names=>true}

I am new to fluentd, is there a trick to adding line breaks?
This is what was posted into slack:
Log:logs.foo.foo-api.err.err.log Host:foo-prod-ip-10-0-7-52
Error: Invalid LocationID \nStatus Code: 404\nType: notFoundError
I did try <br> as well, and that just posted <br> into the slack channel.

I am using the webhooks implementation for this.
Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.