From e8e4c0acf10a5d5c3f5665857917fcabafa8d9d8 Mon Sep 17 00:00:00 2001 From: Simon Cornet Date: Mon, 17 Apr 2023 13:14:01 +0200 Subject: [PATCH] [URL-Check] Added python version --- Linux/url-check/url-check.py | 26 ++++++++++++++++++++++++++ Linux/url-check/url-check.sh | 25 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Linux/url-check/url-check.py create mode 100644 Linux/url-check/url-check.sh diff --git a/Linux/url-check/url-check.py b/Linux/url-check/url-check.py new file mode 100644 index 0000000..a00d8d3 --- /dev/null +++ b/Linux/url-check/url-check.py @@ -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) diff --git a/Linux/url-check/url-check.sh b/Linux/url-check/url-check.sh new file mode 100644 index 0000000..b5c0cce --- /dev/null +++ b/Linux/url-check/url-check.sh @@ -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 +