Sha256: 78d98c586fda7a5ffe7bede12bc157aa586b23d500221651a3403378786718d5

Contents?: true

Size: 1.61 KB

Versions: 13

Compression:

Stored size: 1.61 KB

Contents

module Backup
  module Notifier
    class Zabbix < Base
      attr_accessor :zabbix_host

      attr_accessor :zabbix_port

      attr_accessor :service_name

      attr_accessor :service_host

      attr_accessor :item_key

      def initialize(model, &block)
        super
        instance_eval(&block) if block_given?

        @zabbix_host  ||= Config.hostname
        @zabbix_port  ||= 10_051
        @service_name ||= "Backup #{model.trigger}"
        @service_host ||= Config.hostname
        @item_key     ||= "backup_status"
      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` is `true`.
      #
      # `:warning`
      # : The backup completed successfully, but warnings were logged.
      # : Notification will be sent if `on_warning` or `on_success` is `true`.
      #
      # `:failure`
      # : The backup operation failed.
      # : Notification will be sent if `on_warning` or `on_success` is `true`.
      #
      def notify!(status)
        send_message(message.call(model, status: status_data_for(status)))
      end

      def send_message(message)
        msg = [service_host, service_name, model.exit_status, message].join("\t")
        cmd = utility(:zabbix_sender).to_s +
          " -z '#{zabbix_host}'" \
          " -p '#{zabbix_port}'" \
          " -s #{service_host}"  \
          " -k #{item_key}"      \
          " -o '#{msg}'"
        run("echo '#{msg}' | #{cmd}")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
backup-5.0.0.beta.3 lib/backup/notifier/zabbix.rb
backedup-5.0.0.beta.5 lib/backup/notifier/zabbix.rb
backedup-5.0.0.beta.4 lib/backup/notifier/zabbix.rb
backedup-5.0.0.beta.3 lib/backup/notifier/zabbix.rb
ext_backup-5.0.0.beta.2.1 lib/backup/notifier/zabbix.rb
ext_backup-5.0.0.beta.2.ext.0.1.2 lib/backup/notifier/zabbix.rb
ext_backup-5.0.0.beta.2.ext.0.1.1 lib/backup/notifier/zabbix.rb
ext_backup-5.0.0.beta.2.ext.0.1.0 lib/backup/notifier/zabbix.rb
backup-5.0.0.beta.2 lib/backup/notifier/zabbix.rb
backup-5.0.0.beta.1 lib/backup/notifier/zabbix.rb
backup-bouchard-4.4.4 lib/backup/notifier/zabbix.rb
backup-bouchard-4.4.2 lib/backup/notifier/zabbix.rb
backup-bouchard-4.4.1 lib/backup/notifier/zabbix.rb