Upgraded bluecat plugin
Now requires object types as specified in the API documentation. This means you can configure the bluecat plugin to search for whatever you want now. Added the ability to optionally toggle the search for parent data. Now that page sizes and results sized are respected, searches can go much longer and return much more data. Disabling parent searches can reduce the time needed to return results.
This commit is contained in:
parent
bef4d36d56
commit
30808eee70
@ -8,6 +8,11 @@ bluecat:
|
||||
username: ''
|
||||
page_size: '50'
|
||||
max_results: '100'
|
||||
include_parent: true
|
||||
object_types:
|
||||
- 'HostRecord'
|
||||
- 'IP4Address'
|
||||
- 'IP6Address'
|
||||
f5:
|
||||
hosts:
|
||||
p-chy4-lbint-101.imovetv.com: '10.126.136.35'
|
||||
|
@ -20,9 +20,17 @@ class ServiceDelegate(ServiceBase) :
|
||||
if requirement not in self._config or (requirement in self._config and (self._config[requirement] == '' or type(self._config[requirement]) != str)):
|
||||
self._error.append('Missing required config option ' + requirement)
|
||||
return
|
||||
if 'include_parent' not in self._config or ('include_parent' in self._config and (self._config['include_parent'] == '' or type(self._config['include_parent']) != bool)):
|
||||
self._error.append('Missing required config option ' + requirement)
|
||||
return
|
||||
if 'object_types' not in self._config or ('object_types' in self._config and (self._config['object_types'] == '' or type(self._config['object_types']) != list)):
|
||||
self._error.append('Missing at least one object type in object_types')
|
||||
return
|
||||
self._host = self._config['host']
|
||||
self._page_size = int(self._config['page_size'])
|
||||
self._max_results = int(self._config['max_results'])
|
||||
self._object_types = self._config['object_types']
|
||||
self._include_parent = self._config['include_parent']
|
||||
self._current_auth_header = self.get_bc_auth_header(self._config['host'],self._config['username'],self._config['key'])
|
||||
self.debug('Logged into Bluecat',1)
|
||||
|
||||
@ -37,9 +45,10 @@ class ServiceDelegate(ServiceBase) :
|
||||
self.debug('Getting parent objects from Bluecat...',1)
|
||||
for object in objects :
|
||||
result = {'object':object}
|
||||
parent = self.search_bc_parent_object(object)
|
||||
if parent :
|
||||
result.update({'parent':parent})
|
||||
if self._include_parent :
|
||||
parent = self.search_bc_parent_object(object)
|
||||
if parent :
|
||||
result.update({'parent':parent})
|
||||
object_list.append(result)
|
||||
if len(object_list) > 0 :
|
||||
return object_list
|
||||
@ -91,7 +100,9 @@ class ServiceDelegate(ServiceBase) :
|
||||
return result
|
||||
|
||||
def get_bc_result_page(self,subject,start,count) :
|
||||
response = requests.get('https://' + self._host + '/Services/REST/v1/searchByObjectTypes?keyword=' + subject + '&types=IP4Address,IP6Address&start=' + str(start) + '&count=' + str(count),headers=self._current_auth_header)
|
||||
types = ','.join(self._object_types)
|
||||
params = { 'keyword': subject, 'types': types, 'start': str(start), 'count': str(count) }
|
||||
response = requests.get('https://' + self._host + '/Services/REST/v1/searchByObjectTypes',params=params, headers=self._current_auth_header)
|
||||
return self.clean_response(response)
|
||||
|
||||
def search_bc_parent_object(self,object) :
|
||||
@ -105,7 +116,9 @@ class ServiceDelegate(ServiceBase) :
|
||||
try :
|
||||
ip = ipaddress.IPv4Network(subject + net,strict=False)
|
||||
network = str(ip.network_address)
|
||||
response = requests.get('https://' + self._host + '/Services/REST/v1/searchByObjectTypes?keyword=' + network + '&types=IP4Network,IP4Block&start=0&count=10',headers=self._current_auth_header)
|
||||
types = 'IP4Network,IP4Block'
|
||||
params = { 'keyword': network, 'types': types, 'start': 0, 'count': 10 }
|
||||
response = requests.get('https://' + self._host + '/Services/REST/v1/searchByObjectTypes',params=params,headers=self._current_auth_header)
|
||||
if not response.text.startswith('[]') :
|
||||
return self.clean_response(response)
|
||||
except:
|
||||
|
Loading…
Reference in New Issue
Block a user