Class: Nexpose::SMTPAlert

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

Overview

SMTP (e-mail) Alert

Instance Attribute Summary collapse

Attributes included from Alert

#alert_type, #enabled, #id, #max_alerts, #name, #server, #server_port

Instance Method Summary collapse

Methods included from Alert

#delete, json_initializer, list_alerts, load, load_alerts, #save, #to_h, #to_json, #validate

Methods included from TypedAccessor

#typed_accessor

Methods included from JsonSerializer

#deserialize, #serialize, #to_hash

Constructor Details

#initialize(name, sender, server, recipients, enabled = 1, max_alerts = -1,, verbose = 0) ⇒ SMTPAlert

Returns a new instance of SMTPAlert.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/nexpose/alert.rb', line 176

def initialize(name, sender, server, recipients, enabled = 1, max_alerts = -1, verbose = 0)
  unless recipients.is_a?(Array) && recipients.length > 0
    raise 'An SMTP alert must contain an array of recipient emails with at least 1 recipient'
  end
  recipients.each do |recipient| 
    unless recipient =~ /^.+@.+\..+$/
      raise "Recipients must contain valid emails, #{recipient} has an invalid format"
    end
  end

  @alert_type = 'SMTP'
  @name = name
  @enabled = enabled
  @max_alerts = max_alerts
  @sender = sender
  @server = server
  @verbose = verbose
  @recipients = recipients.nil? ? [] : recipients
end

Instance Attribute Details

#recipientsObject

Returns the value of attribute recipients.



174
175
176
# File 'lib/nexpose/alert.rb', line 174

def recipients
  @recipients
end

#senderObject

Returns the value of attribute sender.



174
175
176
# File 'lib/nexpose/alert.rb', line 174

def sender
  @sender
end

#verboseObject

Returns the value of attribute verbose.



174
175
176
# File 'lib/nexpose/alert.rb', line 174

def verbose
  @verbose
end

Instance Method Details

#add_email_recipient(recipient) ⇒ Object



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

def add_email_recipient(recipient)
  @recipients << recipient
end

#remove_email_recipient(recipient) ⇒ Object



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

def remove_email_recipient(recipient)
  @recipients.delete(recipient)
end