class Backup::Notifier::Nagios

Attributes

nagios_host[RW]

Host of Nagios server to notify on backup completion.

nagios_port[RW]

Port of Nagios server to notify on backup completion.

send_nsca_cfg[RW]

Nagios nrpe configuration file.

service_host[RW]

Host name in Nagios for the backup check.

service_name[RW]

Name of the Nagios service for the backup check.

Public Class Methods

new(model, &block) click to toggle source
Calls superclass method Backup::Notifier::Base::new
# File lib/backup/notifier/nagios.rb, line 27
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 Instance Methods

notify!(status) click to toggle source

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`.

# File lib/backup/notifier/nagios.rb, line 57
def notify!(status)
  send_message(message.call(model, :status => status_data_for(status)))
end
send_message(message) click to toggle source
# File lib/backup/notifier/nagios.rb, line 61
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