Sha256: 031480a040a70ca4e91c44f86ceb74d4951e39b98d3014f427680c279e9bc369

Contents?: true

Size: 1.86 KB

Versions: 30

Compression:

Stored size: 1.86 KB

Contents

# encoding: utf-8

module Backup
  module Notifier
    class Nagios < Base

      ##
      # Host of Nagios server to notify on backup completion.
      attr_accessor :nagios_host

      ##
      # Port of Nagios server to notify on backup completion.
      attr_accessor :nagios_port

      ##
      # Nagios nrpe configuration file.
      attr_accessor :send_nsca_cfg

      ##
      # Name of the Nagios service for the backup check.
      attr_accessor :service_name

      ##
      # Host name in Nagios for the backup check.
      attr_accessor :service_host

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

        @nagios_host  ||= Config.hostname
        @nagios_port  ||= 5667
        @send_nsca_cfg||= "/etc/nagios/send_nsca.cfg"
        @service_name ||= "Backup #{ model.trigger }"
        @service_host ||= Config.hostname
      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)
        cmd = "#{ utility(:send_nsca) } -H '#{ nagios_host }' -p '#{ nagios_port }' -c '#{ send_nsca_cfg }'"
        msg = [service_host, service_name, model.exit_status, message].join("\t")
        run("echo '#{ msg }' | #{ cmd }")
      end

    end
  end
end

Version data entries

30 entries across 30 versions & 5 rubygems

Version Path
backup-ssh-4.4.5 lib/backup/notifier/nagios.rb
backup-remote-0.0.19 lib/backup/notifier/nagios.rb
cm-backup-1.0.0 lib/backup/notifier/nagios.rb
backup-ssh-4.4.4 lib/backup/notifier/nagios.rb
backup-ssh-4.4.3 lib/backup/notifier/nagios.rb
backup-4.4.1 lib/backup/notifier/nagios.rb
backup-remote-0.0.18 lib/backup/notifier/nagios.rb
backup-remote-0.0.17 lib/backup/notifier/nagios.rb
backup-remote-0.0.16 lib/backup/notifier/nagios.rb
backup-remote-0.0.15 lib/backup/notifier/nagios.rb
backup-ssh-4.4.2 lib/backup/notifier/nagios.rb
backup-ssh-4.4.1 lib/backup/notifier/nagios.rb
backup-remote-0.0.14 lib/backup/notifier/nagios.rb
backup-remote-0.0.13 lib/backup/notifier/nagios.rb
backup-remote-0.0.12 lib/backup/notifier/nagios.rb
backup-remote-0.0.11 lib/backup/notifier/nagios.rb
backup-ssh-4.4.0 lib/backup/notifier/nagios.rb
backup-remote-0.0.10 lib/backup/notifier/nagios.rb
backup-remote-0.0.9 lib/backup/notifier/nagios.rb
backup-remote-0.0.8 lib/backup/notifier/nagios.rb