scripts/Linux/url-check/url-check.py

27 lines
712 B
Python
Raw Normal View History

2023-04-17 13:14:01 +02:00
#!/usr/bin/env python3
import argparse
import requests
parser = argparse.ArgumentParser(description='Make an HTTP request and retry a health check if successful.')
parser.add_argument('url', help='the URL to request')
parser.add_argument('--hs', help='the health check URL')
args = parser.parse_args()
response = requests.get(args.url)
if response.status_code == 200:
if args.hs:
retry_count = 3
while retry_count > 0:
try:
requests.get(args.hs)
break
except requests.exceptions.RequestException:
retry_count -= 1
else:
print('Health check URL not provided, skipping...')
else:
print(f'HTTP status code is {response.status_code}, aborting...')
exit(1)