diff --git a/README.md b/README.md index 2d3c1a1c5bffcd6c2bfdf7faf5c1ca5ab1f90930..82734cae8ef71d914280a3d076204925fc7962bd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/inv_cisco_support-0.2.1-20231008.mkp "inv_cisco_support-0.2.1-20231008.mkp" +[PACKAGE]: ../../raw/master/mkp/inv_cisco_support-0.2.1-20231024.mkp "inv_cisco_support-0.2.1-20231024.mkp" # Cisco support APIs inventory plugin Adds live cycle information for Cisco devices to the inventory. diff --git a/bin/ciscoapi/cisco-bug.py b/bin/ciscoapi/cisco-bug.py index e766beff13ad609cadcb9314ba2dda84e092fbe3..fc312c435aa46a0aed92e47d870b6632dd1232fb 100755 --- a/bin/ciscoapi/cisco-bug.py +++ b/bin/ciscoapi/cisco-bug.py @@ -32,7 +32,7 @@ from ciscoapi import ( def main(): settings = Settings() - access_token = AccessToken(settings.client_id, settings.client_secret) + access_token = AccessToken(settings.client_id, settings.client_secret, settings.proxies) configure_logger(log_level=settings.log_level) bug_path = settings.base_path + '/bug' diff --git a/bin/ciscoapi/cisco-eox.py b/bin/ciscoapi/cisco-eox.py index 630ca3c13a1071204f3ceba4da7807c420797a22..e5b8f7c979cc9f7f8337ffd2376400205a9cdada 100755 --- a/bin/ciscoapi/cisco-eox.py +++ b/bin/ciscoapi/cisco-eox.py @@ -115,7 +115,8 @@ def save_serials(eox, path): def main(): settings = Settings() - access_token = AccessToken(settings.client_id, settings.client_secret) + print(settings.proxies) + access_token = AccessToken(settings.client_id, settings.client_secret, settings.proxies) configure_logger(log_level=settings.log_level) eox_path = settings.base_path + '/EoX' diff --git a/bin/ciscoapi/cisco-psirt.py b/bin/ciscoapi/cisco-psirt.py index 3b0db9b4e42e83a7c925bf3f190cf242a7f444c7..876d50c4888b1a2f1cd8548fcc6edc107313e134 100755 --- a/bin/ciscoapi/cisco-psirt.py +++ b/bin/ciscoapi/cisco-psirt.py @@ -144,7 +144,7 @@ def _update_psirt_id(psirt_records: list, family_name: str, paths: Paths): def main(): settings = Settings() - access_token = AccessToken(settings.client_id, settings.client_secret) + access_token = AccessToken(settings.client_id, settings.client_secret, settings.proxies) configure_logger(log_level=settings.log_level) refresh = Refresh( diff --git a/bin/ciscoapi/cisco-sn2info.py b/bin/ciscoapi/cisco-sn2info.py index 1a45b2bde42bb646cc867cf44e2ad418db17b81c..f7c69459a1c7ea14193f45305577c4aceea4640a 100755 --- a/bin/ciscoapi/cisco-sn2info.py +++ b/bin/ciscoapi/cisco-sn2info.py @@ -69,7 +69,7 @@ def sn2info_save_serials(sn2infos, path): def main(): settings = Settings() - access_token = AccessToken(settings.client_id, settings.client_secret) + access_token = AccessToken(settings.client_id, settings.client_secret, settings.proxies) configure_logger(log_level=settings.log_level) sn2info_dir = settings.base_path + '/sn2info' diff --git a/bin/ciscoapi/cisco_live_cycle_utils.py b/bin/ciscoapi/cisco_live_cycle_utils.py index a32ddf948dd64cfb5545826b58265f65e5132aa8..17dc7732638e64c13218f014c8553c6b7eaa4f93 100755 --- a/bin/ciscoapi/cisco_live_cycle_utils.py +++ b/bin/ciscoapi/cisco_live_cycle_utils.py @@ -12,12 +12,6 @@ import os import time import random import sys -# import json -# import copy -# from ciscoapi import ( -# Settings, -# get_product_mdf_information_by_pid, -# ) def configure_logger(_path: str = '', _log_to_console: bool = True, log_level: str = 'INFO'): @@ -30,21 +24,6 @@ def configure_logger(_path: str = '', _log_to_console: bool = True, log_level: s else: logging.getLogger().setLevel(logging.WARNING) - # log_file = path - # # create a new file > 5 mb size - # log_handler_file = logging.handlers.RotatingFileHandler( - # log_file, - # mode='a', - # maxBytes=5 * 1024 * 1024, - # backupCount=10, - # # encoding=None, - # # delay=0 - # ) - - # log_handler_file.setFormatter(log_formatter) - # log_handler_file.setLevel(logging.INFO) - # log.addHandler(log_handler_file) - log_handler_console = logging.StreamHandler(sys.stdout) log_handler_console.setFormatter(log_formatter) log_handler_console.setLevel(logging.INFO) @@ -90,7 +69,7 @@ def get_ids_from_dir(directory, refresh_time: int = 0): return ids -# read list of sub directories from directory (PIDs) (don't anything) +# read list of subdirectories from directory (PIDs) (don't anything) def get_subdirs_from_dir(base_dir): sub_dirs = [] for (dir_path, sub_dirs, filenames) in os.walk(base_dir): @@ -186,53 +165,6 @@ def expand_path(path): return path -# needs to be moved out of cisco_live_cycle_utils -# get cisco product series by pid -# def get_cisco_product_series_by_pid(pids, access_token, settings: Settings): -# -# conf_file = '~/etc/ciscoapi/ciscoapi.json' -# conf_file = os.path.expanduser(conf_file) -# -# productseriesfile = '~/var/ciscoapi/productinfo' -# product_series = {} -# -# if os.path.isfile(conf_file): -# with open(conf_file) as f: -# try: -# config = json.load(f) -# productseriesfile = config['productinfo'].get('productseriesfile', productseriesfile) -# except ValueError as e: -# log_message(f'snmp_cisco_eox:status:JSON load error: {e}', level='WARNING') -# -# productseriesfile = expand_path(productseriesfile) + 'productseries.json' -# -# if os.path.isfile(productseriesfile): -# with open(productseriesfile) as f: -# product_series = json.load(f) -# -# requestpids = copy.deepcopy(pids) -# if product_series != {}: -# keys = product_series.keys() -# for pid in requestpids: -# if pid in keys: -# requestpids.remove(pid) -# -# if requestpids is not []: -# product_infos = get_product_mdf_information_by_pid(pids, access_token, settings=settings) -# -# for entry in product_infos: -# product_series.update({entry.get('product_id'): entry.get('product_series')}) -# -# with open(productseriesfile, 'w') as f: -# json.dump(product_series, f) -# -# return_product_series = {} -# for pid in pids: -# return_product_series.update({pid: product_series.get(pid, 'not found')}) -# -# return return_product_series - - # remove empty directories def remove_empty_sub_dirs(base_dir): subdirs = get_subdirs_from_dir(base_dir) diff --git a/bin/ciscoapi/ciscoapi.py b/bin/ciscoapi/ciscoapi.py index 133c77e68172a6444c4c811094630e87fa25f7f4..2ec1e74d2c78baa19731e6895c5bc0865dfc9a3d 100755 --- a/bin/ciscoapi/ciscoapi.py +++ b/bin/ciscoapi/ciscoapi.py @@ -38,7 +38,7 @@ class Settings: try: self.__settings = json.load(f) except ValueError as e: - log_message(f'snmp_cisco_eox:status:JSON load error: {e}', level='WARNING') + log_message(f'ciscoapi:settings:JSON load error: {e}', level='WARNING') exit() except FileNotFoundError as e: log_message(f'Config file not found {e}.', level='CRITICAL') @@ -160,10 +160,11 @@ class AccessToken: self, client_id: str, client_secret: str, + proxies: Dict, ): self.__client_id = client_id self.__client_secret = client_secret - self.__proxies = {} + self.__proxies = proxies self.__use_auth_proxy = None self.__client_fqdn = '' self.__root_cert = True @@ -186,7 +187,6 @@ class AccessToken: @property def token(self) -> str: - if self.__access_token and time.time() < self.__lifetime: return self.__access_token else: @@ -385,43 +385,6 @@ def get_psirt_by_product_family(families: List[str], access_token: AccessToken, return info -def get_suggested_release_by_pid(pids: List[str], access_token: AccessToken, settings: Settings): - max_pid_length = 240 - max_pids = 10 - optimisedpids = [] - pidstr = '' - count = 1 - info = [] - - # split list of PIDs in chunks of max 240 bytes length - for pid in pids: - if (len(pidstr) + len(pid)) < max_pid_length: - pidstr += pid + "," - count += 1 - if (count == max_pids) or ((len(pidstr) + len(pid)) >= max_pid_length): - optimisedpids.append(pidstr[:-1]) - pidstr = '' - count = 1 - optimisedpids.append(pidstr[:-1]) - - headers = {'accept': 'application/json', 'Authorization': 'Bearer ' + access_token.token} - req_url = 'https://apix.cisco.com/software/suggestion/v2/suggestions/releases/productIds/' - - # requests.packages.urllib3.disable_warnings() - if optimisedpids is not []: - for productids in optimisedpids: - suggestion_response = requests.get(req_url + productids, headers=headers, proxies=settings.proxies) - log_message('cisco-api:get_sugessted_release_by_pid:response:response.text %s' % suggestion_response.text) - if suggestion_response.ok: - suggestion_response.encoding = 'UTF-8' - response = (json.loads(suggestion_response.text)) - log_message('cisco-api:get_suggested_release_by_pid:response: %s' % response) - info.append(response.get('productList', 'notfound')) - log_message('ciscoapi:info-found: %s' % info) - - return info - - # get_clean_sn_for_bug_api('ASA5510', '9.1(7)15,8.4(7)30,9.1(6)1') # return {'9.1(7)15': '9.1(7.15)', '9.1(6)1': '9.1(6.1)', '8.4(7)30': '8.4(7.30)'} def get_clean_sn_for_bug_api(pid, software_releases): @@ -556,44 +519,3 @@ def get_bug_by_pid_and_release(pid, release, access_token: AccessToken, reqoptio 'reason': reason, 'missing': missing}) return info - - -def get_product_mdf_information_by_pid(pids, access_token: AccessToken, settings: Settings): - max_pid_length = 40 - max_pids = 5 - optimisedpids = [] - pidstr = '' - count = 1 - info = [] - - # split list of PIDs in chunks of max 240 bytes length - for pid in pids: - if (len(pidstr) + len(pid)) < max_pid_length: - pidstr += pid + "," - count += 1 - if (count == max_pids) or ((len(pidstr) + len(pid)) >= max_pid_length): - optimisedpids.append(pidstr[:-1]) - pidstr = '' - count = 1 - optimisedpids.append(pidstr[:-1]) - - headers = {'accept': 'application/json', 'Authorization': 'Bearer ' + access_token.token} - req_url = 'https://apix.cisco.com/product/v1/information/product_ids_mdf/' -# req_url = 'https://apix.cisco.com/product/v1/information/product_ids/' - - # requests.packages.urllib3.disable_warnings() - if optimisedpids is not []: - for productids in optimisedpids: - productinfo_response = requests.get(req_url + productids, headers=headers, proxies=settings.proxies) - log_message( - f'cisco-api:get_product_mdf_information_by_pid:response:response.text {productinfo_response.text}' - ) - if productinfo_response.ok: - productinfo_response.encoding = 'UTF-8' - response = (json.loads(productinfo_response.text)) - log_message('cisco-api:get_product_mdf_information_by_pid:response: %s' % response) - # info.append(response) - info.extend(response.get('product_list', 'notfound')) - log_message('ciscoapi:info-found: %s' % info) - - return info diff --git a/gui/views/inv_cisco_livecycle.py b/gui/views/inv_cisco_livecycle.py index c7e8f2cd890ad8606611021db1cf8f2a67d22d3f..9be8672231b910a9c54e3a2bf409b18588d56a82 100644 --- a/gui/views/inv_cisco_livecycle.py +++ b/gui/views/inv_cisco_livecycle.py @@ -138,9 +138,9 @@ def inv_paint_psirt_bugid(bugids) -> PaintResult: # EoX display hints inventory_displayhints.update({ - '.hardware.support': {'title': _('Cisco Live Cycle')}, + '.hardware.support:': {'title': _('Support')}, '.hardware.support.cisco_eox:': { - 'title': _('EoX'), + 'title': _('Cisco EoX'), 'keyorder': [ 'pid', 'serial_number', 'ProductIDDescription', 'Last_checked', 'ProductBulletinNumber', @@ -163,7 +163,7 @@ inventory_displayhints.update({ # SN2Info (contract) display hints inventory_displayhints.update({ '.hardware.support.cisco_contract:': { - 'title': _('Contract'), + 'title': _('Cisco Contract'), 'keyorder': [ 'pid', 'serial_number', 'ProductIDDescription', 'Last_checked', 'is_covered', 'service_contract_number', 'covered_product_line_end_date', @@ -189,6 +189,7 @@ inventory_displayhints.update({ # BUG display hints inventory_displayhints.update({ + '.software.support:': {'title': _('Support')}, '.software.support.cisco_bug.Total_records': {'title': _('Records total'), }, '.software.support.cisco_bug.duplicate_records': {'title': _('Records duplicate'), }, '.software.support.cisco_bug.missing_records': {'title': _('Records missing'), }, diff --git a/mkp/inv_cisco_support-0.2.1-20231024.mkp b/mkp/inv_cisco_support-0.2.1-20231024.mkp new file mode 100644 index 0000000000000000000000000000000000000000..8a6f3e2ba5803a1b0ade1e4bd07bc4656ca67e82 Binary files /dev/null and b/mkp/inv_cisco_support-0.2.1-20231024.mkp differ diff --git a/packages/inv_cisco_support b/packages/inv_cisco_support index b4cb1c803a1a2f1fa7dc6d72d09e28ea3dfddaef..8478c2dca3d466ed4630a88a693347ab67ee2525 100644 --- a/packages/inv_cisco_support +++ b/packages/inv_cisco_support @@ -38,7 +38,7 @@ 'name': 'inv_cisco_support', 'title': 'Inventory for Cisco Bug, EoX, contract status, PSIRT advisories and ' 'suggested software', - 'version': '0.2.1-20231008', + 'version': '0.2.1-20231024', 'version.min_required': '2.2.0b1', 'version.packaged': '2.2.0p11', 'version.usable_until': '2.3.0b1'}