Class: Nexpose::SMTPAlert

Inherits:
Object
  • Object
show all
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

Constructor Details

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

Returns a new instance of SMTPAlert.



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

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.



210
211
212
# File 'lib/nexpose/alert.rb', line 210

def limit_text
  @limit_text
end

#recipientsObject

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



212
213
214
# File 'lib/nexpose/alert.rb', line 212

def recipients
  @recipients
end

#senderObject

The e-mail address of the sender.



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

def sender
  @sender
end

#serverObject

The server to sent this alert.



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

def server
  @server
end

Class Method Details

.parse(xml) ⇒ Object



243
244
245
246
247
248
249
# File 'lib/nexpose/alert.rb', line 243

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.



222
223
224
# File 'lib/nexpose/alert.rb', line 222

def add_recipient(recipient)
  @recipients << recipient
end

#as_xmlObject



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/nexpose/alert.rb', line 226

def as_xml
  xml = REXML::Element.new('smtpAlert')
  xml.attributes['sender'] = @sender
  xml.attributes['server'] = @server
  xml.attributes['limitText'] = @limit_text
  recipients.each do |recpt|
    elem = REXML::Element.new('recipient')
    elem.text = recpt
    xml.add_element(elem)
  end
  xml
end

#to_xmlObject



239
240
241
# File 'lib/nexpose/alert.rb', line 239

def to_xml
  as_xml.to_s
end