Class: Nexpose::AssetGroup
- Inherits:
-
AssetGroupSummary
- Object
- AssetGroupSummary
- Nexpose::AssetGroup
- Includes:
- Sanitize
- Defined in:
- lib/nexpose/group.rb
Overview
Asset group configuration object containing Device details.
Instance Attribute Summary collapse
-
#assets ⇒ Object
(also: #devices)
Array of devices associated with this asset group.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tags ⇒ Object
Returns the value of attribute tags.
Attributes inherited from AssetGroupSummary
Class Method Summary collapse
-
.load(connection, id) ⇒ AssetGroup
Load an existing configuration from a Nexpose instance.
- .parse(xml) ⇒ Object
Instance Method Summary collapse
-
#as_xml ⇒ String
Generate an XML representation of this group configuration.
-
#initialize(name, desc, id = -1,, risk = 0.0) ⇒ AssetGroup
constructor
A new instance of AssetGroup.
-
#rescan_assets(connection) ⇒ Hash
Launch ad hoc scans against each group of assets per site.
- #save(connection) ⇒ Object
-
#to_xml ⇒ String
Get an XML representation of the group that is valid for a save request.
Methods included from Sanitize
Methods inherited from AssetGroupSummary
Constructor Details
#initialize(name, desc, id = -1,, risk = 0.0) ⇒ AssetGroup
Returns a new instance of AssetGroup.
81 82 83 84 85 86 87 88 |
# File 'lib/nexpose/group.rb', line 81 def initialize(name, desc, id = -1, risk = 0.0) @name = name @description = desc @id = id @risk_score = risk @assets = [] @tags = [] end |
Instance Attribute Details
#assets ⇒ Object Also known as: devices
Array of devices associated with this asset group.
77 78 79 |
# File 'lib/nexpose/group.rb', line 77 def assets @assets end |
#description ⇒ Object
Returns the value of attribute description.
74 75 76 |
# File 'lib/nexpose/group.rb', line 74 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
74 75 76 |
# File 'lib/nexpose/group.rb', line 74 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
74 75 76 |
# File 'lib/nexpose/group.rb', line 74 def name @name end |
#tags ⇒ Object
Returns the value of attribute tags.
74 75 76 |
# File 'lib/nexpose/group.rb', line 74 def @tags end |
Class Method Details
.load(connection, id) ⇒ AssetGroup
Load an existing configuration from a Nexpose instance.
160 161 162 163 164 |
# File 'lib/nexpose/group.rb', line 160 def self.load(connection, id) xml = %(<AssetGroupConfigRequest session-id="#{connection.session_id}" group-id="#{id}"/>) r = APIRequest.execute(connection.url, xml, '1.1', { timeout: connection.timeout, open_timeout: connection.open_timeout }) parse(r.res) end |
.parse(xml) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/nexpose/group.rb', line 166 def self.parse(xml) return nil unless xml group = REXML::XPath.first(xml, 'AssetGroupConfigResponse/AssetGroup') asset_group = new(group.attributes['name'], group.attributes['description'], group.attributes['id'].to_i, group.attributes['riskscore'].to_f) group.elements.each('Description') do |desc| asset_group.description = desc.text end group.elements.each('Devices/device') do |dev| asset_group.assets << Device.new(dev.attributes['id'].to_i, dev.attributes['address'], dev.attributes['site-id'].to_i, dev.attributes['riskfactor'].to_f, dev.attributes['riskscore'].to_f) end group.elements.each('Tags/Tag') do |tag| asset_group. << TagSummary.parse_xml(tag) end asset_group end |
Instance Method Details
#as_xml ⇒ String
Generate an XML representation of this group configuration
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/nexpose/group.rb', line 102 def as_xml xml = REXML::Element.new('AssetGroup') xml.attributes['id'] = @id xml.attributes['name'] = @name xml.attributes['description'] = @description if @description && !@description.empty? elem = REXML::Element.new('Description') elem.add_text(@description) xml.add_element(elem) end elem = REXML::Element.new('Devices') @assets.each { |a| elem.add_element('device', { 'id' => a.id }) } xml.add_element(elem) unless .empty? tag_xml = xml.add_element(REXML::Element.new('Tags')) @tags.each { |tag| tag_xml.add_element(tag.as_xml) } end xml end |
#rescan_assets(connection) ⇒ Hash
Launch ad hoc scans against each group of assets per site.
142 143 144 145 146 147 148 149 150 |
# File 'lib/nexpose/group.rb', line 142 def rescan_assets(connection) scans = {} sites_ids = @assets.map(&:site_id).uniq sites_ids.each do |site_id| to_scan = @assets.select { |d| d.site_id == site_id } scans[site_id] = connection.scan_devices(to_scan) end scans end |
#save(connection) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/nexpose/group.rb', line 90 def save(connection) xml = "<AssetGroupSaveRequest session-id='#{connection.session_id}'>" xml << to_xml xml << '</AssetGroupSaveRequest>' res = connection.execute(xml) @id = res.attributes['group-id'].to_i if res.success && @id < 1 end |
#to_xml ⇒ String
Get an XML representation of the group that is valid for a save request. Note that only name, description, and asset ID information is accepted by a save request.
132 133 134 |
# File 'lib/nexpose/group.rb', line 132 def to_xml as_xml.to_s end |