Skip to content

Commit 9fc227b

Browse files
authored
[FIX] Issue when exporting the advisory data
- Fixed issue when exporting the advisory data (information that should be variable was hard coded) - The number of objects when doing the API call was reduced to 10 (all of them) - The # of items per page was moved to the conf area
1 parent 7abdf89 commit 9fc227b

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

conf/conf.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@
4242

4343
# 43200 sec == 12h
4444
# 21600 sec == 6h
45-
TIME_TO_CHECK_THE_NEW_VERSION = 21600
45+
TIME_TO_CHECK_THE_NEW_VERSION = 21600
46+
47+
# Items per page when doing the API call
48+
ITEMS_PER_PAGE = 10

credential/token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_token():
8989

9090
# Setting the incremental to 500 in oder to avoid issues when
9191
# executing the `ts dump`. It's working with no issues.
92-
if (current_time_epoch + 500) >= exp_date_from_token:
92+
if (current_time_epoch + 800) >= exp_date_from_token:
9393
refresh_token()
9494

9595
except jwt.exceptions.DecodeError:

execution/execution.py

+40-18
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def inventory_list():
5656
This def will collect the first 50 HBI entries
5757
"""
5858

59-
url = "https://console.redhat.com/api/inventory/v1/hosts"
59+
url = "https://console.redhat.com/api/inventory/v1/hosts?per_page=10"
60+
# url = "https://console.redhat.com/api/inventory/v1/hosts"
6061
response = connection_request(url)
6162
check_authentication(response)
6263

@@ -103,7 +104,9 @@ def inventory_list_all():
103104

104105
# Here we are checking the total number of objects and setting the correct
105106
# number of pages based on that.
106-
check_response = divmod(response.json()['total'], 50)
107+
# check_response = divmod(response.json()['total'], 50)
108+
# ITEMS_PER_PAGE = 10
109+
check_response = divmod(response.json()['total'], conf.ITEMS_PER_PAGE)
107110

108111
if check_response[1] == 0:
109112
num_of_pages = check_response[0] + 1
@@ -121,7 +124,7 @@ def inventory_list_all():
121124
# num_of_pages = 2
122125

123126
for page in range(1, num_of_pages):
124-
url = "https://console.redhat.com/api/inventory/v1/hosts?per_page=50&page=" + str(page)
127+
url = "https://console.redhat.com/api/inventory/v1/hosts?per_page=" + str(conf.ITEMS_PER_PAGE) + "&page=" + str(page)
125128
response = connection_request(url)
126129

127130
for server in response.json()['results']:
@@ -191,7 +194,10 @@ def swatch_list():
191194
This def will collect the first 100 entries from Subscription Watch
192195
"""
193196

194-
url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=100&offset=0&sort=display_name"
197+
# ITEMS_PER_PAGE = 10
198+
199+
url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=" + str(conf.ITEMS_PER_PAGE) + "&offset=0&sort=display_name"
200+
# url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=100&offset=0&sort=display_name"
195201
response = connection_request(url)
196202
check_authentication(response)
197203

@@ -203,20 +209,26 @@ def swatch_list_all():
203209
This def will collect all the entries from Subscription Watch
204210
"""
205211

206-
url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=100&offset=0&sort=display_name"
212+
# ITEMS_PER_PAGE = 10
213+
214+
url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=" + str(conf.ITEMS_PER_PAGE) + "&offset=0&sort=display_name"
215+
# url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=100&offset=0&sort=display_name"
207216
response = connection_request(url)
208217
check_authentication(response)
209218

210-
num_of_pages = round(response.json()['meta']['count'] / 100 + 1)
219+
num_of_pages = round(response.json()['meta']['count'] / conf.ITEMS_PER_PAGE + 1)
220+
# num_of_pages = round(response.json()['meta']['count'] / 100 + 1)
211221

212222
dic_full_list = {'data': '', 'meta': {'count': response.json()['meta']['count']}}
213223
full_list = []
214224

215225
count = 0
216226
for page in range(0, num_of_pages):
217-
url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=100&offset=" + str(count) + "&sort=display_name"
227+
url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=" + str(conf.ITEMS_PER_PAGE) + "&offset=" + str(count) + "&sort=display_name"
228+
# url = "https://console.redhat.com/api/rhsm-subscriptions/v1/hosts/products/RHEL?limit=100&offset=" + str(count) + "&sort=display_name"
218229
response = connection_request(url)
219-
count = count + 100
230+
count = count + conf.ITEMS_PER_PAGE
231+
# count = count + 100
220232

221233
for entry in response.json()['data']:
222234
full_list.append(entry)
@@ -378,15 +390,20 @@ def patch_systems():
378390
response = connection_request(url)
379391
check_authentication(response)
380392

381-
num_of_pages = int(response.json()['meta']['total_items'] / 20 + 1)
393+
# ITEMS_PER_PAGE = 10
394+
395+
num_of_pages = int(response.json()['meta']['total_items'] / conf.ITEMS_PER_PAGE + 1)
396+
# num_of_pages = int(response.json()['meta']['total_items'] / 20 + 1)
382397

383398
dic_full_list = {'data': '', 'total': response.json()['meta']['total_items']}
384399
full_list = []
385400

386401
count = 0
387402
for page in range(0, num_of_pages):
388-
url = "https://console.redhat.com/api/patch/v1/systems?limit=20&offset=" + str(count) + "&sort=-last_upload"
389-
count = count + 20
403+
url = "https://console.redhat.com/api/patch/v1/systems?limit=" + str(conf.ITEMS_PER_PAGE) + "&offset=" + str(count) + "&sort=-last_upload"
404+
# url = "https://console.redhat.com/api/patch/v1/systems?limit=20&offset=" + str(count) + "&sort=-last_upload"
405+
count = count + conf.ITEMS_PER_PAGE
406+
# count = count + 20
390407
response = connection_request(url)
391408

392409
for entry in response.json()['data']:
@@ -406,9 +423,12 @@ def vulnerability_systems():
406423
response = connection_request(url)
407424
check_authentication(response)
408425

426+
# ITEMS_PER_PAGE = 10
427+
409428
# Here we are checking the total number of objects and setting the correct
410429
# number of pages based on that.
411-
check_response = divmod(response.json()['meta']['total_items'], 20)
430+
check_response = divmod(response.json()['meta']['total_items'], conf.ITEMS_PER_PAGE)
431+
# check_response = divmod(response.json()['meta']['total_items'], 20)
412432

413433
if check_response[1] == 0:
414434
num_of_pages = check_response[0]
@@ -422,8 +442,10 @@ def vulnerability_systems():
422442

423443
count = 0
424444
for page in range(0, num_of_pages):
425-
url = "https://console.redhat.com/api/vulnerability/v1/systems?limit=20&offset=" + str(count) + "&sort=-last_upload"
426-
count = count + 20
445+
url = "https://console.redhat.com/api/vulnerability/v1/systems?limit=" + str(conf.ITEMS_PER_PAGE) + "&offset=" + str(count) + "&sort=-last_upload"
446+
# url = "https://console.redhat.com/api/vulnerability/v1/systems?limit=20&offset=" + str(count) + "&sort=-last_upload"
447+
count = count + conf.ITEMS_PER_PAGE
448+
# count = count + 20
427449
response = connection_request(url)
428450

429451
for entry in response.json()['data']:
@@ -438,21 +460,21 @@ def advisor_systems():
438460
This def will collect all the entries from advisor/insights systems
439461
"""
440462

441-
ITEMS_PER_PAGE = 10
463+
# ITEMS_PER_PAGE = 10
442464

443465
url = "https://console.redhat.com/api/insights/v1/system"
444466
response = connection_request(url)
445467
check_authentication(response)
446468

447-
num_of_pages = int(response.json()['meta']['count'] / ITEMS_PER_PAGE + 1)
469+
num_of_pages = int(response.json()['meta']['count'] / conf.ITEMS_PER_PAGE + 1)
448470

449471
dic_full_list = {'data': '', 'total': response.json()['meta']['count']}
450472
full_list = []
451473

452474
count = 0
453475
for page in range(0, num_of_pages):
454-
url = "https://console.redhat.com/api/insights/v1/system?limit=ITEMS_PER_PAGE&offset=" + str(count)
455-
count = count + ITEMS_PER_PAGE
476+
url = "https://console.redhat.com/api/insights/v1/system?limit=" + str(conf.ITEMS_PER_PAGE) + "&offset=" + str(count)
477+
count = count + conf.ITEMS_PER_PAGE
456478
response = connection_request(url)
457479

458480
for entry in response.json()['data']:

0 commit comments

Comments
 (0)