Class: Nexpose::Criteria

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

Overview

Join search criteria for an asset filter search or dynamic asset group.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(criteria = [], match = 'AND') ⇒ Criteria

Returns a new instance of Criteria.



269
270
271
272
273
274
275
276
# File 'lib/nexpose/filter.rb', line 269

def initialize(criteria = [], match = 'AND')
  if criteria.kind_of?(Array)
    @criteria = criteria
  else
    @criteria = [criteria]
  end
  @match = match.upcase
end

Instance Attribute Details

#criteriaObject

Array of criteria to match against.



267
268
269
# File 'lib/nexpose/filter.rb', line 267

def criteria
  @criteria
end

#matchObject

Whether to match any or all filters. One of ‘OR’ or ‘AND’.



265
266
267
# File 'lib/nexpose/filter.rb', line 265

def match
  @match
end

Class Method Details

.parse(json) ⇒ Object



300
301
302
303
304
305
306
# File 'lib/nexpose/filter.rb', line 300

def self.parse(json)
  ret = Criteria.new([], json['operator'])
  json['criteria'].each do |c|
    ret.criteria << Criterion.parse(c)
  end
  ret
end

Instance Method Details

#_to_payloadObject

Generate the payload needed for a POST request for Asset Filter.



291
292
293
294
295
296
297
298
# File 'lib/nexpose/filter.rb', line 291

def _to_payload
  { 'dir' => -1,
    'results' => -1,
    'sort' => 'assetIP',
    'startIndex' => -1,
    'table-id' => 'assetfilter',
    'searchCriteria' => to_json }
end

#to_jsonObject

Convert this object into the format expected by Nexpose.



285
286
287
# File 'lib/nexpose/filter.rb', line 285

def to_json
  JSON.generate(to_map)
end

#to_mapObject



278
279
280
281
# File 'lib/nexpose/filter.rb', line 278

def to_map
  { 'operator' => @match,
    'criteria' => @criteria.map { |c| c.to_map } }
end