Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create/edit a tag and adding criteria of multiple IP ranges #161

Closed
paagaard-r7 opened this issue Apr 20, 2015 · 3 comments
Closed

Create/edit a tag and adding criteria of multiple IP ranges #161

paagaard-r7 opened this issue Apr 20, 2015 · 3 comments

Comments

@paagaard-r7
Copy link

It seems to reverse the ranges in different cases. I haven’t figured out all of the cases that it does it, but it looks like it happens when at least the first octet matches. It appears to save correctly from inspection, however, it seems that when you inspect the tag.load request you see the issues with the IP Ranges (also in the UI).

Here is the example:

#!/usr/bin/env ruby

require 'nexpose'
require 'date'

nsc = Nexpose::Connection.from_uri('https://localhost:3780','nxadmin','nxadmin')
nsc.login

#ip_ranges = [ ['10.0.0.0','10.0.5.255'], ['10.0.5.64','10.0.5.255'] ]
ip_ranges = [ ['10.0.0.0','10.0.5.255'], ['10.0.10.64','10.0.10.255'] ]
ip_ranges.sort!

tag = Nexpose::Tag.new( "testtag_#{DateTime.now.to_s}", 'CUSTOM' )
tag.search_criteria = Nexpose::Tag::Criteria.new( [], 'OR' )
ip_ranges.each do |range|
    tag.search_criteria.criteria << Nexpose::Tag::Criterion.new( Nexpose::Search::Field::IP_RANGE, Nexpose::Search::Operator::IN, range )
end

puts "Creating tag #{tag.name} with ranges:"
tag.search_criteria.criteria.each { |r| puts "#{r.value}" }

#puts "Raw request (checking the gem's work)"
#puts tag.to_json

puts "Saving"
tagId = tag.save(nsc)

#puts "#{tag.inspect}"

puts "Loading"
tag = Nexpose::Tag.load( nsc, tagId )
puts "Tag now has ranges:"
tag.search_criteria.criteria.each { |c| puts "#{c.value}" }

new_ranges = tag.search_criteria.criteria.map { |c| c.value }
new_ranges.sort!

if ip_ranges == new_ranges
    puts "Data is consistent.  Test PASSED"
else
    puts "Data is inconsistent.  Test FAILED"
end
@sgreen-r7
Copy link
Contributor

@paagaard-r7 - can you give an example of what the input and expected output should be? I dont know if running the script is producing the same results as you're seeing.

@paagaard-r7
Copy link
Author

@sgreen-r7

Creating tag testtag_2015-04-22T13:57:25-07:00 with ranges:
["10.0.0.0", "10.0.5.255"]
["10.0.10.64", "10.0.10.255"]
["10.0.20.64", "10.0.20.255"]

#<Nexpose::Tag:0x0000000184fe58 @id=92, @type="CUSTOM", @name="testtag_2015-04-22T13:57:25-07:00", @source="nexpose-client", @color="#f6f6f6", @search_criteria=#<Nexpose::Tag::Criteria:0x0000000184fd18 @criteria=[#<Nexpose::Tag::Criterion:0x0000000184fc78 @operator="IN", @field="IP_RANGE", @value=["10.0.0.0", "10.0.5.255"]>, #<Nexpose::Tag::Criterion:0x000000018277f0 @operator="IN", @field="IP_RANGE", @value=["10.0.10.64", "10.0.10.255"]>, #<Nexpose::Tag::Criterion:0x00000001808b98 @operator="IN", @field="IP_RANGE", @value=["10.0.20.64", "10.0.20.255"]>], @match="OR">>
Saving
#<Nexpose::Tag:0x0000000184fe58 @id=92, @type="CUSTOM", @name="testtag_2015-04-22T13:57:25-07:00", @source="nexpose-client", @color="#f6f6f6", @search_criteria=#<Nexpose::Tag::Criteria:0x0000000184fd18 @criteria=[#<Nexpose::Tag::Criterion:0x0000000184fc78 @operator="IN", @field="IP_RANGE", @value=["10.0.0.0", "10.0.5.255"]>, #<Nexpose::Tag::Criterion:0x000000018277f0 @operator="IN", @field="IP_RANGE", @value=["10.0.10.64", "10.0.10.255"]>, #<Nexpose::Tag::Criterion:0x00000001808b98 @operator="IN", @field="IP_RANGE", @value=["10.0.20.64", "10.0.20.255"]>], @match="OR">>
Loading
Tag now has ranges:
checking the loading
#<Nexpose::Tag:0x000000017a49e0 @id=92, @type="CUSTOM", @name="testtag_2015-04-22T13:57:25-07:00", @source="nexpose-client", @color="#f6f6f6", @search_criteria=#<Nexpose::Tag::Criteria:0x000000017a4030 @criteria=[#<Nexpose::Tag::Criterion:0x000000017a4490 @operator="IN", @field="IP_RANGE", @value=["10.0.20.255", "10.0.20.64"]>, #<Nexpose::Tag::Criterion:0x000000017a4300 @operator="IN", @field="IP_RANGE", @value=["10.0.0.0", "10.0.5.255"]>, #<Nexpose::Tag::Criterion:0x000000017a4198 @operator="IN", @field="IP_RANGE", @value=["10.0.10.255", "10.0.10.64"]>], @match="OR">, @asset_ids=[], @site_ids=[], @associated_asset_ids=[], @asset_group_ids=[]>
Data is inconsistent.  Test FAILED

So we save it in a specific order and when we reload the values we see it reversed:

@value=["10.0.20.255", "10.0.20.64"]
@value=["10.0.0.0", "10.0.5.255"]
@value=["10.0.10.255", "10.0.10.64"]

It should not reverse the values and it should make them the same on tag.load:

["10.0.0.0", "10.0.5.255"]
["10.0.10.64", "10.0.10.255"]
["10.0.20.64", "10.0.20.255"]

@sgreen-r7
Copy link
Contributor

After getting more feedback, looks like this is due to a hiccup in the Nexpose API, and is nothing something fixable in the gem.

We have an open internal ticket which we'll use to track this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants