Class: ServerBackups::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/server_backups/notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Notifier

Returns a new instance of Notifier.



7
8
9
# File 'lib/server_backups/notifier.rb', line 7

def initialize(config_path)
    @config = Config.new(config_path)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/server_backups/notifier.rb', line 5

def config
  @config
end

Instance Method Details

#notify_failure(errors) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/server_backups/notifier.rb', line 20

def notify_failure(errors)
    return unless config.slack_webhook

    notifier = Slack::Notifier.new config.slack_webhook
    message = "Backups at `#{config.prefix}` failed. "
    message += config.slack_mention_on_failure.map{|t| "<@#{t}>"}.to_sentence
    attachments = []
    for error in errors do
        attachments << {text: error.message + "\n" + error.backtrace.join("\n")}
    end
    notifier.post text: message, icon_emoji: ':bomb:', attachments: attachments
end

#notify_successObject



11
12
13
14
15
16
17
18
# File 'lib/server_backups/notifier.rb', line 11

def notify_success
    return unless config.slack_webhook && config.notify_on_success

    notifier = Slack::Notifier.new config.slack_webhook
    message = "Backups at `#{config.prefix}` succeeded. "
    message += config.slack_mention_on_success.map{|t| "<@#{t}>"}.to_sentence
    notifier.post text: message, icon_emoji: ':100:'
end