Class: Rundock::Hook::Slack

Inherits:
Base
  • Object
show all
Defined in:
lib/rundock/plugin/hook/slack.rb

Instance Method Summary collapse

Instance Method Details

#hook(operation_attributes, log_buffer) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rundock/plugin/hook/slack.rb', line 7

def hook(operation_attributes, log_buffer)

  ::Slack.configure do |config|
    config.token = @contents[:token]
  end

  @contents[:channel] = '#' + @contents[:channel]
  Logger.info("send slack to #{@contents[:channel]} channel")
  post_args = @contents.dup.reject {|k, v| k == :token}

  out_msg = ''
  log_buffer.each do |log|
    out_msg += log.formatted_message
  end

  Logger.debug("post args: #{post_args.to_s}")

  post_args[:text] = out_msg
  ::Slack.chat_postMessage(post_args) unless operation_attributes[0][:dry_run]
end