Class: Chef::Handler::Slack
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- Chef::Handler::Slack
- Defined in:
- lib/cookbook_sdk/handlers/slack.rb
Overview
Slack Handler goal is send messages to a Slack channel with Chef run status. It can be used as a start, failure or success handler.
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#on_failure ⇒ Object
readonly
Returns the value of attribute on_failure.
-
#on_start ⇒ Object
readonly
Returns the value of attribute on_start.
-
#on_success ⇒ Object
readonly
Returns the value of attribute on_success.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Slack
constructor
A new instance of Slack.
- #report ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Slack
Returns a new instance of Slack.
14 15 16 17 18 19 20 21 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 14 def initialize( = {}) @token = .fetch(:token) { raise Exceptions::ConfigurationError, "Slack 'token' should be provided!" } @channel = .fetch(:channel, '#chef') @username = .fetch(:username, 'Chef') @on_start = .fetch(:on_start, true) @on_success = .fetch(:on_success, true) @on_failure = .fetch(:on_failure, true) end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
12 13 14 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 12 def channel @channel end |
#on_failure ⇒ Object (readonly)
Returns the value of attribute on_failure.
12 13 14 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 12 def on_failure @on_failure end |
#on_start ⇒ Object (readonly)
Returns the value of attribute on_start.
12 13 14 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 12 def on_start @on_start end |
#on_success ⇒ Object (readonly)
Returns the value of attribute on_success.
12 13 14 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 12 def on_success @on_success end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
12 13 14 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 12 def token @token end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 12 def username @username end |
Instance Method Details
#report ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cookbook_sdk/handlers/slack.rb', line 23 def report = { :pretext => "Run at #{run_status.node.name}" } if !run_status.is_a?(Chef::RunStatus) || elapsed_time.nil? report_start() elsif run_status.success? report_success() else report_failure() end end |