Class: OpsDeploy::CLI::Notifier::Slack
- Defined in:
- lib/ops_deploy/cli/notifier.rb
Overview
A notification class for Slack
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#slack_notifier ⇒ Object
Returns the value of attribute slack_notifier.
Instance Method Summary collapse
- #failure_notify(message) ⇒ Object
-
#initialize(stack, options) ⇒ Slack
constructor
A new instance of Slack.
- #notify(message) ⇒ Object
- #stack_link(stack) ⇒ Object
- #success_notify(message) ⇒ Object
Constructor Details
#initialize(stack, options) ⇒ Slack
Returns a new instance of Slack.
76 77 78 79 80 81 |
# File 'lib/ops_deploy/cli/notifier.rb', line 76 def initialize(stack, ) @stack = stack = [:username] = 'OpsDeploy' unless [:username] @slack_notifier = Slack::Notifier.new [:webhook_url], end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
74 75 76 |
# File 'lib/ops_deploy/cli/notifier.rb', line 74 def end |
#slack_notifier ⇒ Object
Returns the value of attribute slack_notifier.
73 74 75 |
# File 'lib/ops_deploy/cli/notifier.rb', line 73 def slack_notifier @slack_notifier end |
Instance Method Details
#failure_notify(message) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ops_deploy/cli/notifier.rb', line 108 def failure_notify() = .gsub(/\[[0-9;]+?m/, '') @slack_notifier.ping '', channel: [:channel], attachments: [ { fallback: , text: "#{message} <!channel>", author_name: @stack.name, author_link: stack_link(@stack), color: 'danger' } ] end |
#notify(message) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ops_deploy/cli/notifier.rb', line 83 def notify() = .gsub(/\[[0-9;]+?m/, '') @slack_notifier.ping '', channel: [:channel], attachments: [ { fallback: , author_name: @stack.name, author_link: stack_link(@stack), text: } ] end |
#stack_link(stack) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/ops_deploy/cli/notifier.rb', line 121 def stack_link(stack) region = OpsDeploy::CLI.argument('aws-region', 'AWS_REGION') || 'us-east-1' params = "?region=#{region}#/stack/#{stack.stack_id}/stack" "https://console.aws.amazon.com/opsworks/home#{params}" end |
#success_notify(message) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ops_deploy/cli/notifier.rb', line 95 def success_notify() = .gsub(/\[[0-9;]+?m/, '') @slack_notifier.ping '', channel: [:channel], attachments: [ { fallback: , text: , author_name: @stack.name, author_link: stack_link(@stack), color: 'good' } ] end |