class Martilla::Slack
Public Instance Methods
error(msg, data)
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 9 def error(msg, data) slack_notify(error_txt(msg, data)) end
success(data)
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 5 def success(data) slack_notify(success_txt(data)) end
Private Instance Methods
error_txt(msg, data)
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 46 def error_txt(msg, data) error_msg = "*The backup attempt failed with the following error:*\n #{msg} \n\n" error_msg + data.map { |d| "- #{d}" }.join("\n") end
notifier()
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 23 def notifier ::Slack::Notifier.new(slack_webhook_url, channel: slack_channel, username: slack_username) end
slack_channel()
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 33 def slack_channel @options['slack_channel'] || "#general" end
slack_notify(message)
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 15 def slack_notify(message) begin notifier.ping message rescue StandardError => e puts "Slack notification not sent. Error message: #{e}" end end
slack_username()
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 37 def slack_username @options['slack_username'] || "Martilla" end
slack_webhook_url()
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 27 def slack_webhook_url webhook_url = @options['slack_webhook_url'] || ENV['SLACK_WEBHOOK_URL'] raise config_error('slack_webhook_url') if webhook_url.nil? webhook_url end
success_txt(data)
click to toggle source
# File lib/martilla/notifiers/slack.rb, line 41 def success_txt(data) success_msg = "*The backup was created successfully*\n\n" success_msg + data.map { |d| "- #{d}" }.join("\n") end