Skip to content

Commit

Permalink
add select parameter to redfish calls to filter for properties
Browse files Browse the repository at this point in the history
and use expand parameter to reduce the amount of calls to Systems
  • Loading branch information
BerndKue committed Oct 17, 2024
1 parent 8391257 commit 2b4d7a8
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions redfish_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_session(self):
)


def connect_server(self, command, noauth = False, basic_auth = False):
def connect_server(self, command, noauth = False, basic_auth = False, fields = None):
"""
connect to the server and get the data
"""
Expand All @@ -165,6 +165,10 @@ def connect_server(self, command, noauth = False, basic_auth = False):
self.last_http_code = 0
request_start = time.time()

if fields:
logging.debug(" Target %s: Getting fields %s", self.target, fields)
command += "?$select=" + ",".join(fields)

url = f"https://{self.ip_address}{command}"

# check if we already established a session with the server
Expand Down Expand Up @@ -282,7 +286,7 @@ def _check_req_text(self, req):

def _get_system_urls(self):

systems = self.connect_server(self._urls['Systems_Root'])
systems = self.connect_server(self._urls['Systems_Root']+'?$expand=*')

if not systems:
logging.error(
Expand All @@ -304,13 +308,10 @@ def _get_system_urls(self):
self.target
)

# Get the server info for the labels
self._urls.update({'Systems': systems['Members'][0]['@odata.id']})
server_info = self.connect_server(self._urls['Systems'])
server_info = systems['Members'][0]

if not server_info:
logging.warning(" Target %s: No Server Info could be retrieved!", self.target)
return
# Get the server info for the labels
self._urls.update({'Systems': server_info['@odata.id']})

fields = (
'SKU',
Expand All @@ -322,6 +323,10 @@ def _get_system_urls(self):
'ProcessorSummary'
)

if not server_info:
logging.warning(" Target %s: No Server Info could be retrieved!", self.target)
return

for field in fields:
self._inventory.update({field: server_info.get(field)})

Expand All @@ -331,17 +336,6 @@ def _get_system_urls(self):
)

# get the links of the parts for later
# for link in server_info['Links'].keys():
# # some Cisco servers have the links as strings
# if isinstance(server_info['Links'][link], str):
# logging.warning(" Target %s: The Link is a string!")
# self._urls.update({link: server_info['Links'][link][0]})
# if isinstance(server_info['Links'][link], list) and server_info['Links'][link] != []:
# if isinstance(server_info['Links'][link][0], str):
# url = server_info['Links'][link][0]
# else:
# url = server_info['Links'][link][0]['@odata.id']
# self._urls.update({link: url})

urls = (
'Memory',
Expand Down Expand Up @@ -771,8 +765,10 @@ def _get_network_info(self, fields):
self._inventory.update({'NetworkAdapters': network_cards_updated})

def _get_tpm_info(self):

logging.info(" Target %s: Get the TPM data.", self.target)
systeminfo = self.connect_server(self._urls['Systems'])
systeminfo = self.connect_server(self._urls['Systems'], fields=['TrustedModules'])

tpm_modules = []
if systeminfo and systeminfo.get('TrustedModules'):
for tpm in systeminfo['TrustedModules']:
Expand Down

0 comments on commit 2b4d7a8

Please sign in to comment.