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.

Direct Known Subclasses

DiscoveryConnection::Criteria, Tag::Criteria

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.



323
324
325
326
# File 'lib/nexpose/filter.rb', line 323

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

Instance Attribute Details

#criteriaObject

Array of criteria to match against.



321
322
323
# File 'lib/nexpose/filter.rb', line 321

def criteria
  @criteria
end

#matchObject

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



319
320
321
# File 'lib/nexpose/filter.rb', line 319

def match
  @match
end

Class Method Details

.parse(json) ⇒ Object



354
355
356
357
358
359
360
361
362
# File 'lib/nexpose/filter.rb', line 354

def self.parse(json)
  # The call returns empty JSON, so default to 'AND' if not present.
  operator = json['operator'] || 'AND'
  ret = Criteria.new([], operator)
  json['criteria'].each do |c|
    ret.criteria << Criterion.parse(c)
  end
  ret
end

Instance Method Details

#<<(criterion) ⇒ Object



350
351
352
# File 'lib/nexpose/filter.rb', line 350

def <<(criterion)
  criteria << criterion
end

#_to_payloadObject

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



341
342
343
344
345
346
347
348
# File 'lib/nexpose/filter.rb', line 341

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

#to_hObject



328
329
330
331
# File 'lib/nexpose/filter.rb', line 328

def to_h
  { 'operator' => @match,
    'criteria' => @criteria.map(&:to_h) }
end

#to_jsonObject

Convert this object into the format expected by Nexpose.



335
336
337
# File 'lib/nexpose/filter.rb', line 335

def to_json
  JSON.generate(to_h)
end