Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

API & Integration

Reply
Highlighted
Accepted Solution

Regexp getting too many records - why?

Techie
Posts: 12
2338     0

I'm trying to filter my request for records with:

1. Any of the strings: idrac, drc, or oob
2. Where the string 'site' follows the occurrence from #1
3. Ends in ds.domain1.net

(values sanitized).

 

==========================================================================
So, to do that, I have the following python code:

#Assemble string based on regex to match on keywords
p = re.compile('(\.)')
domain_for_regex = p.sub('.*', domain)
match_string = '.*' + str(srch_str) + '.*' + str(site) + '.*' + str(domain_for_regex)
log.debug("Match string " + match_string + ", keyword (srch_wrd) is - " + str(srch_wrd) )

#Use that string as part of parameters to be sent with request for a response to URL
params = {'_max_results':'500','_paging':'1','_return_as_object':'1','name~':match_string}
log.debug("Req param is " + str(params))
url = 'https://' + str(grid_master_ip) + '/wapi/v2.7/' + str(srch_wrd)
log.debug("URL is " + url)

#Get the response based on the assembled information
response = GetResponse(params, url, acct, passwd)
log.debug("Object response is " + str(response))

 

==========================================================================
And this is what I see in the log:

2018-03-30 18:10:23,702 - GetHostAndIP - DEBUG - Match string .*drc|idrac|oob.*site.*ds.*domain1.*net, keyword (srch_wrd) is - record:host
2018-03-30 18:10:23,702 - GetHostAndIP - DEBUG - Req param is {'_return_as_object': '1', 'name~': '.*drc|idrac|oob.*site.*ds.*domain1.*net', '_max_results': '500', '_paging': '1'}
2018-03-30 18:10:23,702 - GetHostAndIP - DEBUG - URL is https://grid-master-ip-here/wapi/v2.7/record:host
2018-03-30 18:10:23,705 - _new_conn - DEBUG - Starting new HTTPS connection (1): 10.26.85.136
2018-03-30 18:10:32,758 - _make_request - DEBUG - https://grid-master-ip-here:443 "GET /wapi/v2.7/record:host?_return_as_object=1&name~=.%2Adrc%7Cidrac%7Coob.%2Asite.%2Ads.%2Adomain1.%2Anet&_max_results=500&_paging=1 HTTP/1.1" 200 None
2018-03-30 18:10:32,773 - GetHostAndIP - DEBUG - Object response is <Response [200]>


==========================================================================
However, the response I get includes records that **Do Not** have 'site' nor 'domain1'. Any thoughts on why?

Highlighted

Re: Regexp getting too many records - why?

Techie
Posts: 12
2338     0

Any thoughts on this?

Highlighted

Re: Regexp getting too many records - why?

Techie
Posts: 12
2338     0

I talked to our support engineer, and it seems that this may be a bug.   I may have to resort to pulling all records for a given domain and parse the output in python instead of with WAPI.  If so, that's pretty disappointing, as it is not what a regular expression is supposed to do, and not what the documentation currently says.  Thoughts, anyone?

 

I'm leery of marking this as a solution, as it really isn't a solution.  It's more of a workaround....

Highlighted

Re: Regexp getting too many records - why?

Community Manager
Community Manager
Posts: 248
2338     0

you need to change your regex grouping because you're mixing AND and OR regexes.

and you have too many wilcards.

Note that '.' also matches 'any character' so you need to be specific if you want to match a '.'

Support should have picked up on this.

 

I did a few random tests, and I think something like this will work:

 

(irac|drc|oob)site.*ds\.domain\.net$

Highlighted

Re: Regexp getting too many records - why?

Techie
Posts: 12
2338     0

That sounds great, and entirely reasonable.  That said, I decided to make the changes for the workaround I mentioned, which also gives me the flexibility to manipulate the data downloaded from IPAM anyway.   But I'll take this into account for the next iteration.

Showing results for 
Search instead for 
Do you mean 

Recommended for You