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
-
#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.
-
#type ⇒ Object
Alert type and its configuration.
-
#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
- #as_xml ⇒ Object
-
#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.
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
#enabled ⇒ Object
Whether or not this alert is currently active.
11 12 13 |
# File 'lib/nexpose/alert.rb', line 11 def enabled @enabled end |
#max_alerts ⇒ Object
Send at most this many alerts per scan.
13 14 15 |
# File 'lib/nexpose/alert.rb', line 13 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.
15 16 17 |
# File 'lib/nexpose/alert.rb', line 15 def scan_filter @scan_filter end |
#type ⇒ Object
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_filter ⇒ Object
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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nexpose/alert.rb', line 45 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
#as_xml ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nexpose/alert.rb', line 25 def as_xml xml = REXML::Element.new('Alert') xml.attributes['name'] = @name xml.attributes['enabled'] = @enabled xml.attributes['maxAlerts'] = @max_alerts xml.add_element(scan_filter.as_xml) xml.add_element(vuln_filter.as_xml) xml.add_element(type.as_xml) xml end |
#to_xml ⇒ Object
36 37 38 |
# File 'lib/nexpose/alert.rb', line 36 def to_xml as_xml.to_s end |