Class: Alerty::Plugin::Slack
- Inherits:
-
Object
- Object
- Alerty::Plugin::Slack
- Defined in:
- lib/alerty/plugin/slack.rb,
lib/alerty/plugin/slack/version.rb,
lib/alerty/plugin/slack/slack_client.rb
Defined Under Namespace
Modules: SlackClient
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #alert(record) ⇒ Object
-
#initialize(config) ⇒ Slack
constructor
A new instance of Slack.
Constructor Details
#initialize(config) ⇒ Slack
Returns a new instance of Slack.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/alerty/plugin/slack.rb', line 8 def initialize(config) @payload = config.payload || {} if config.webhook_url raise ConfigError.new('slack: webhook_url is given, but empty') if config.webhook_url.empty? @client = SlackClient::IncomingWebhook.new(config.webhook_url) elsif config.slackbot_url raise ConfigError.new('slack: slackbot_url is given, but empty') if config.slackbot_url.empty? @client = SlackClient::Slackbot.new(config.slackbot_url) elsif config.webapi_token raise ConfigError.new('slack: webapi_token is given, but empty') if config.webapi_token.empty? @client = SlackClient::Webapi.new @payload['token'] = config.webapi_token end @client.log = Alerty.logger @client.https_proxy = config.https_proxy if config.https_proxy @num_retries = config.num_retries || 3 end |
Instance Method Details
#alert(record) ⇒ Object
27 28 29 30 |
# File 'lib/alerty/plugin/slack.rb', line 27 def alert(record) payload = build_payload(record).to_h with_retry(@num_retries) { @client.(payload) } end |