Skip to content

Commit

Permalink
Set update interval (1-120 days) manually for NVD API
Browse files Browse the repository at this point in the history
Adds -d (--days) options for passing manual interval to CveXplore.

Requires CveXplore with cve-search/CveXplore#300.
  • Loading branch information
oh2fih committed Jul 3, 2024
1 parent 62c8183 commit 56094cf
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions sbin/db_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main(args):
loop_count = 0

while loop:
if not args.l:
if not args.l or args.days > 0:
loop = False
else:
loop_count += 1
Expand All @@ -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.days > 0:
days_info = f" (manual interval of {str(args.days)} 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("==========================")

Expand All @@ -102,7 +107,13 @@ def main(args):
f"minimal import without redis-cache-cpe source (-m) is used"
)

cvex.database.update()
if args.days > 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.days)

newelement = 0
for source in sources:
Expand Down Expand Up @@ -165,7 +176,7 @@ def main(args):
)
).wait()

if args.l:
if args.l and args.days <= 0:
logger.info("Sleeping 1 hour...")
time.sleep(3600)

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 56094cf

Please sign in to comment.