Class: Nexpose::SMTPAlert

Inherits:
Object
  • Object
show all
Includes:
Sanitize
Defined in:
lib/nexpose/alert.rb

Overview

SMTP (e-mail) Alert This class should only exist as an element of an Alert.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sanitize

#replace_entities

Constructor Details

#initialize(sender, server, limit_text = 0) ⇒ SMTPAlert

Returns a new instance of SMTPAlert.



199
200
201
202
203
204
# File 'lib/nexpose/alert.rb', line 199

def initialize(sender, server, limit_text = 0)
  @sender = sender
  @server = server
  @limit_text = limit_text
  @recipients = []
end

Instance Attribute Details

#limit_textObject

Limit the text for mobile devices.



195
196
197
# File 'lib/nexpose/alert.rb', line 195

def limit_text
  @limit_text
end

#recipientsObject

Array of strings with the e-mail addresses of the intended recipients.



197
198
199
# File 'lib/nexpose/alert.rb', line 197

def recipients
  @recipients
end

#senderObject

The e-mail address of the sender.



191
192
193
# File 'lib/nexpose/alert.rb', line 191

def sender
  @sender
end

#serverObject

The server to sent this alert.



193
194
195
# File 'lib/nexpose/alert.rb', line 193

def server
  @server
end

Class Method Details

.parse(xml) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/nexpose/alert.rb', line 224

def self.parse(xml)
  alert = new(xml.attributes['sender'], xml.attributes['server'], xml.attributes['limitText'].to_i)
  xml.elements.each("//recipient") do |recipient|
    alert.recipients << recipient.text
  end
  alert
end

Instance Method Details

#add_recipient(recipient) ⇒ Object

Adds a new recipient to the alert.



207
208
209
# File 'lib/nexpose/alert.rb', line 207

def add_recipient(recipient)
  @recipients << recipient
end

#to_xmlObject



213
214
215
216
217
218
219
220
221
222
# File 'lib/nexpose/alert.rb', line 213

def to_xml
  xml = '<smtpAlert'
  xml << %( sender="#{replace_entities(sender)}")
  xml << %( server="#{replace_entities(server)}")
  xml << %( limitText="#{limit_text}">)
  recipients.each do |recpt|
    xml << "<recipient>#{replace_entities(recpt)}</recipient>"
  end
  xml << '</smtpAlert>'
end