Class: Nexpose::Alert

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

Overview

Alert parent object. The three alert types should be wrapped in this object to store data.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, enabled = 1, max_alerts = -1)) ⇒ Alert

Returns a new instance of Alert.



21
22
23
# File 'lib/nexpose/alert.rb', line 21

def initialize(name, enabled = 1, max_alerts = -1)
  @name, @enabled, @max_alerts = name, enabled, max_alerts
end

Instance Attribute Details

#enabledObject

Whether or not this alert is currently active.



11
12
13
# File 'lib/nexpose/alert.rb', line 11

def enabled
  @enabled
end

#max_alertsObject

Send at most this many alerts per scan.



13
14
15
# File 'lib/nexpose/alert.rb', line 13

def max_alerts
  @max_alerts
end

#nameObject

Name for this alert.



9
10
11
# File 'lib/nexpose/alert.rb', line 9

def name
  @name
end

#scan_filterObject

Send alerts based upon scan status.



15
16
17
# File 'lib/nexpose/alert.rb', line 15

def scan_filter
  @scan_filter
end

#typeObject

Alert type and its configuration. One of SMTPAlert, SyslogAlert, SNMPAlert



19
20
21
# File 'lib/nexpose/alert.rb', line 19

def type
  @type
end

#vuln_filterObject

Send alerts based upon vulnerability finding status.



17
18
19
# File 'lib/nexpose/alert.rb', line 17

def vuln_filter
  @vuln_filter
end

Class Method Details

.parse(rexml) ⇒ Alert

Parse a response from a Nexpose console into a valid Alert object.

Parameters:

  • rexml (REXML::Document)

    XML document to parse.

Returns:

  • (Alert)

    Alert object represented by the XML.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/nexpose/alert.rb', line 42

def self.parse(rexml)
  name = rexml.attributes['name']
  rexml.elements.each("//Alert[@name='#{name}']") do |xml|
    alert = new(name,
                xml.attributes['enabled'].to_i,
                xml.attributes['maxAlerts'].to_i)
    alert.scan_filter = ScanFilter.parse(REXML::XPath.first(xml, "//Alert[@name='#{name}']/scanFilter"))
    alert.vuln_filter = VulnFilter.parse(REXML::XPath.first(xml, "//Alert[@name='#{name}']/vulnFilter"))
    if (type = REXML::XPath.first(xml, "//Alert[@name='#{name}']/smtpAlert"))
      alert.type = SMTPAlert.parse(type)
    elsif (type = REXML::XPath.first(xml, "//Alert[@name='#{name}']/syslogAlert"))
      alert.type = SyslogAlert.parse(type)
    elsif (type = REXML::XPath.first(xml, "//Alert[@name='#{name}']/snmpAlert"))
      alert.type = SNMPAlert.parse(type)
    end
    return alert
  end
  nil
end

Instance Method Details

#to_xmlObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nexpose/alert.rb', line 25

def to_xml
  xml = '<Alert'
  xml << %( name="#{@name}")
  xml << %( enabled="#{@enabled}")
  xml << %( maxAlerts="#{@max_alerts}")
  xml << '>'
  xml << scan_filter.to_xml
  xml << vuln_filter.to_xml
  xml << type.to_xml
  xml << '</Alert>'
end