Class: Nexpose::Alert
- Inherits:
-
Object
- Object
- Nexpose::Alert
- 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
-
#alert ⇒ Object
Alert type and its configuration.
-
#enabled ⇒ Object
Whether or not this alert is currently active.
-
#max_alerts ⇒ Object
Send at most this many alerts per scan.
-
#name ⇒ Object
Name for this alert.
-
#scan_filter ⇒ Object
Send alerts based upon scan status.
-
#vuln_filter ⇒ Object
Send alerts based upon vulnerability finding status.
Class Method Summary collapse
-
.parse(rexml) ⇒ Alert
Parse a response from a Nexpose console into a valid Alert object.
Instance Method Summary collapse
-
#initialize(name, enabled = 1, max_alerts = -1)) ⇒ Alert
constructor
A new instance of Alert.
- #to_xml ⇒ Object
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
#alert ⇒ Object
Alert type and its configuration. One of SMTPAlert, SyslogAlert, SNMPAlert
24 25 26 |
# File 'lib/nexpose/alert.rb', line 24 def alert @alert end |
#enabled ⇒ Object
Whether or not this alert is currently active.
12 13 14 |
# File 'lib/nexpose/alert.rb', line 12 def enabled @enabled end |
#max_alerts ⇒ Object
Send at most this many alerts per scan.
15 16 17 |
# File 'lib/nexpose/alert.rb', line 15 def max_alerts @max_alerts end |
#name ⇒ Object
Name for this alert.
9 10 11 |
# File 'lib/nexpose/alert.rb', line 9 def name @name end |
#scan_filter ⇒ Object
Send alerts based upon scan status.
18 19 20 |
# File 'lib/nexpose/alert.rb', line 18 def scan_filter @scan_filter end |
#vuln_filter ⇒ Object
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.
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_xml ⇒ Object
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 |