Class: NagiosHerald::Message::Pager

Inherits:
NagiosHerald::Message show all
Defined in:
lib/nagios-herald/messages/pager.rb

Instance Attribute Summary collapse

Attributes inherited from NagiosHerald::Message

#content, #recipients

Instance Method Summary collapse

Methods inherited from NagiosHerald::Message

inherited, message_types

Methods included from Util

#get_nagios_var, get_script_path, load_helper, underscore_to_camel_case, #unescape_text

Methods included from Logging

#configure_logger_for, #logger, #logger_for

Constructor Details

#initialize(recipients, options = {}) ⇒ Pager

Public: Initializes a new Message::Pager object.

recipients - A list of recipients for this message. options - The options hash from Executor. FIXME: Is that ^^ necessary now with Config.config available?

Returns a new Message::Pager object.



18
19
20
21
22
23
# File 'lib/nagios-herald/messages/pager.rb', line 18

def initialize(recipients, options = {})
  @replyto     = options[:replyto]
  @subject     = ""
  @text        = ""
  super(recipients, options)
end

Instance Attribute Details

#subjectObject

Returns the value of attribute subject.



8
9
10
# File 'lib/nagios-herald/messages/pager.rb', line 8

def subject
  @subject
end

#textObject

Returns the value of attribute text.



9
10
11
# File 'lib/nagios-herald/messages/pager.rb', line 9

def text
  @text
end

Instance Method Details

#build_messageObject

Public: Sends the pager message.

Returns nothing.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/nagios-herald/messages/pager.rb', line 51

def build_message
  @subject = self.content[:short_subject]
  curate_text


  mail = Mail.new({
    :from    => @replyto,
    :to      => @recipients,
    :subject => @subject,
    :body    => @text
  })

  if @no_send
    self.print
    return
  end


  return mail
end

#curate_textObject

Public: Generates the text portion of the content hash.

Returns the full text portion of the content hash.



28
29
30
31
32
33
34
35
36
37
# File 'lib/nagios-herald/messages/pager.rb', line 28

def curate_text
  notification_type = get_nagios_var('NAGIOS_NOTIFICATIONTYPE')
  if notification_type.eql?('ACKNOWLEDGEMENT')
    @text += self.content[:short_text][:ack_info] unless self.content[:short_text][:ack_info].empty?
  else
    [:state_info, :additional_info, :additional_details].each do |info|
      @text += self.content[:short_text][info] unless self.content[:short_text][info].empty?
    end
  end
end

Public: Prints the subject and text content to the terminal. Useful for debugging.

Returns nothing.



43
44
45
46
# File 'lib/nagios-herald/messages/pager.rb', line 43

def print
  puts @subject
  puts @text
end

#sendObject



72
73
74
75
# File 'lib/nagios-herald/messages/pager.rb', line 72

def send
  mail = self.build_message
  mail.deliver! unless mail.nil?
end