Sha256: 12c81a28a5fa99005dfc76b85db2ba17a0d01ae98df5b123a196faae2f43264b

Contents?: true

Size: 1.8 KB

Versions: 20

Compression:

Stored size: 1.8 KB

Contents

# encoding: utf-8

##
# Only load the Prowler gem when using Prowler notifications
Backup::Dependency.load('prowler')

module Backup
  module Notifier
    class Prowl < Base

      ##
      # Application name
      # Tell something like your server name. Example: "Server1 Backup"
      attr_accessor :application

      ##
      # API-Key
      # Create a Prowl account and request an API key on prowlapp.com.
      attr_accessor :api_key

      def initialize(model, &block)
        super(model)

        instance_eval(&block) if block_given?
      end

      private

      ##
      # Notify the user of the backup operation results.
      # `status` indicates one of the following:
      #
      # `:success`
      # : The backup completed successfully.
      # : Notification will be sent if `on_success` was set to `true`
      #
      # `:warning`
      # : The backup completed successfully, but warnings were logged
      # : Notification will be sent, including a copy of the current
      # : backup log, if `on_warning` was set to `true`
      #
      # `:failure`
      # : The backup operation failed.
      # : Notification will be sent, including the Exception which caused
      # : the failure, the Exception's backtrace, a copy of the current
      # : backup log and other information if `on_failure` was set to `true`
      #
      def notify!(status)
        name = case status
               when :success then 'Success'
               when :warning then 'Warning'
               when :failure then 'Failure'
               end
        message = '[Backup::%s]' % name
        send_message(message)
      end

      def send_message(message)
        client = Prowler.new(:application => application, :api_key => api_key)
        client.notify(message, "#{@model.label} (#{@model.trigger})")
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
backup-3.4.0 lib/backup/notifier/prowl.rb
backup-3.3.2 lib/backup/notifier/prowl.rb
backup-3.3.1 lib/backup/notifier/prowl.rb
backup-3.3.0 lib/backup/notifier/prowl.rb
backup-3.2.0 lib/backup/notifier/prowl.rb
backup-3.1.3 lib/backup/notifier/prowl.rb
backup-3.1.2 lib/backup/notifier/prowl.rb
backup-3.1.1 lib/backup/notifier/prowl.rb
backup-3.1.0 lib/backup/notifier/prowl.rb
backup-agoddard-3.0.28 lib/backup/notifier/prowl.rb
backup-agoddard-3.0.27 lib/backup/notifier/prowl.rb
ey-vendored-backup-3.0.27 lib/backup/notifier/prowl.rb
backup-3.0.27 lib/backup/notifier/prowl.rb
backup-3.0.26 lib/backup/notifier/prowl.rb
backup-3.0.25 lib/backup/notifier/prowl.rb
backup-3.0.24 lib/backup/notifier/prowl.rb
backup_checksum-3.0.23 lib/backup/notifier/prowl.rb
backup-3.0.23 lib/backup/notifier/prowl.rb
backup-3.0.22 lib/backup/notifier/prowl.rb
backup-3.0.21 lib/backup/notifier/prowl.rb