[URL-Check] Added python version
This commit is contained in:
parent
f6819a957f
commit
e8e4c0acf1
26
Linux/url-check/url-check.py
Normal file
26
Linux/url-check/url-check.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/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)
|
25
Linux/url-check/url-check.sh
Normal file
25
Linux/url-check/url-check.sh
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/csh -f
|
||||||
|
set MODE=$1
|
||||||
|
set CURL=/usr/bin/curl
|
||||||
|
|
||||||
|
if ($MODE == no_auth) then
|
||||||
|
set URL=$2
|
||||||
|
set HS=$3
|
||||||
|
set STATUS=`$CURL -L -o /dev/null -s -w "%{http_code}\n" -m 1 $URL`
|
||||||
|
|
||||||
|
else if ($MODE == auth) then
|
||||||
|
set AUTH=$2
|
||||||
|
set URL=$3
|
||||||
|
set HS=$4
|
||||||
|
set STATUS=`$CURL -L -o /dev/null -s -w "%{http_code}\n" -m 1 --user $AUTH $URL`
|
||||||
|
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ($STATUS == 200) then
|
||||||
|
$CURL -fsS --retry 3 $HS > /dev/null
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user