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.



26
27
28
# File 'lib/nexpose/alert.rb', line 26

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

Instance Attribute Details

#alertObject

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



24
25
26
# File 'lib/nexpose/alert.rb', line 24

def alert
  @alert
end

#enabledObject

Whether or not this alert is currently active.



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

def enabled
  @enabled
end

#max_alertsObject

Send at most this many alerts per scan.



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

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.



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

def scan_filter
  @scan_filter
end

#vuln_filterObject

Send alerts based upon vulnerability finding status.



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

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.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nexpose/alert.rb', line 47

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.alert = SMTPAlert.parse(type)
    elsif (type = REXML::XPath.first(xml, "//Alert[@name='#{name}']/syslogAlert"))
      alert.alert = SyslogAlert.parse(type)
    elsif (type = REXML::XPath.first(xml, "//Alert[@name='#{name}']/snmpAlert"))
      alert.alert = SNMPAlert.parse(type)
    end
    return alert
  end
  nil
end

Instance Method Details

#to_xmlObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nexpose/alert.rb', line 30

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