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

create, #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.



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

def initialize(name, sender, server, recipients, enabled = 1, max_alerts = -1, verbose = 0)
  unless recipients.is_a?(Array) && !recipients.empty?
    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.



172
173
174
# File 'lib/nexpose/alert.rb', line 172

def recipients
  @recipients
end

#senderObject

Returns the value of attribute sender.



172
173
174
# File 'lib/nexpose/alert.rb', line 172

def sender
  @sender
end

#verboseObject

Returns the value of attribute verbose.



172
173
174
# File 'lib/nexpose/alert.rb', line 172

def verbose
  @verbose
end

Instance Method Details

#add_email_recipient(recipient) ⇒ Object



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

def add_email_recipient(recipient)
  @recipients << recipient
end

#remove_email_recipient(recipient) ⇒ Object



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

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