From 9982f982516cfb60dede695f800a0919cf7294e8 Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Wed, 3 Jul 2024 18:05:03 +0300 Subject: [PATCH] Set update interval (1-120 days) manually for NVD API Adds -d (--days) options for passing manual interval to CveXplore. Requires CveXplore with cve-search/CveXplore#300. --- sbin/db_updater.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/sbin/db_updater.py b/sbin/db_updater.py index fd51a7b1b..43e3deff5 100755 --- a/sbin/db_updater.py +++ b/sbin/db_updater.py @@ -76,7 +76,7 @@ def main(args): loop_count = 0 while loop: - if not args.l: + if not args.l or args.d > 0: loop = False else: loop_count += 1 @@ -88,11 +88,16 @@ def main(args): redis_info = "; CPE redis cache enabled" else: redis_info = "" - if args.l: - loop_info = f" (loop #{loop_count})" + if args.d > 0: + days_info = f" (manual interval of {str(args.d)} days)" + loop_info = "" # loop not supported with manual days else: - loop_info = "" - logger.info(f"Update{redis_info}{loop_info}") + days_info = "" + if args.l: + loop_info = f" (loop #{loop_count})" + else: + loop_info = "" + logger.info(f"Update{redis_info}{loop_info}{days_info}") logger.info(time.strftime("%a %d %B %Y %H:%M", time.gmtime())) logger.info("==========================") @@ -102,7 +107,13 @@ def main(args): f"minimal import without redis-cache-cpe source (-m) is used" ) - cvex.database.update() + if args.d > 0 and args.l: + logger.warning( + f"Loop (-l) not supported with manual days (-d, --days); " + f"only running once" + ) + + cvex.database.update(manual_days=args.d) newelement = 0 for source in sources: @@ -165,7 +176,7 @@ def main(args): ) ).wait() - if args.l: + if args.l and args.d <= 0: logger.info("Sleeping 1 hour...") time.sleep(3600) @@ -202,6 +213,13 @@ def main(args): help="Drop collections and force initial import", default=False, ) + argParser.add_argument( + "-d", + "--days", + type=int, + help="Set update interval (1-120 days) manually for NVD API (CPE, CVE)", + default=0, # not manually set; updates CPE & CVE since last update + ) argParser.add_argument( "-m", action="store_true",