Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Fixes update-database script on the last few days of a month. #2121

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions intelmq/bots/experts/asn_lookup/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,26 @@ def update_database(cls):
try:
print("Searching for the latest database update...")
session = create_request_session()
url = "http://archive.routeviews.org/route-views4/bgpdata/"
response = session.get(url)
base_url = "http://archive.routeviews.org/route-views4/bgpdata/"
response = session.get(base_url)
pattern = re.compile(r"href=\"(\d{4}\.\d{2})/\"")
months = pattern.findall(response.text)
months.sort(reverse=True)

if not months:
sys.exit("Database update failed. Couldn't find the latest database update.")

url += str(months[0]) + "/RIBS/"
response = session.get(url)
pattern = re.compile(r"href=\"(rib\.\d{8}\.\d{4}\.bz2)\"")
days = pattern.findall(response.text)
days.sort(reverse=True)
# routeviews website creates next month's directory on 28th of the current month
# therefore on 28th, 29th, 30th, 31st it's necessary to find the second highest month directory
for i in range(2):
url = base_url + str(months[i]) + "/RIBS/"
response = session.get(url)
pattern = re.compile(r"href=\"(rib\.\d{8}\.\d{4}\.bz2)\"")
days = pattern.findall(response.text)
days.sort(reverse=True)
print(url)
if days:
break

if not days:
sys.exit("Database update failed. Couldn't find the latest database update.")
Expand Down