Skip to content

URL Status Check

URL Status Check #220

Workflow file for this run

name: URL Status Check
on:
schedule:
- cron: "*/50 * * * *" # Run every 15 minutes
workflow_dispatch:
jobs:
check_urls:
runs-on: ubuntu-latest
steps:
- name: URL Status Check
run: |
# Fail script if an error is not handled explicitly
set -e
# Define an array of URLs to check
urls=("https://www.swm.de/energiewende" "https://crm-m-waermepumpe.swm.de/web/login" "https://crm-m-waerme.swm.de/de/web/login" "https://nis-map-nahfw.apps.intra.swm.de")
# Prepare an empty results array to hold URL and status code
results=()
# Loop through each URL and make a GET request using curl
for url in "${urls[@]}"; do
echo "Checking URL: $url"
# Make the GET request and capture the HTTP status code and any potential errors
status_code=$(curl -o /dev/null -s -w "%{http_code}" --connect-timeout 5 --max-time 10 "$url" || true)
# Capture the curl exit code
curl_exit_code=$?
echo "Curl Exit Code: $curl_exit_code"
# Handle curl exit codes
case $curl_exit_code in
0)
# Success, keep the actual status code
;;
6)
echo "URL: $url could not be resolved (DNS failure). Setting response code to 0."
status_code=0 # DNS error, set to 0 (non-HTTP error)
;;
7)
echo "URL: $url failed to connect. Setting response code to 502."
status_code=502 # Failed to connect, set to 502 Bad Gateway
;;
28)
echo "URL: $url timed out. Setting response code to 504."
status_code=504 # Timeout, set to 504 Gateway Timeout
;;
35|51|77)
echo "URL: $url encountered an SSL error. Setting response code to 495."
status_code=495 # SSL/TLS error, set to 495 SSL Certificate Error
;;
52)
echo "URL: $url received an empty reply. Setting response code to 502."
status_code=502 # Empty reply, set to 502 Bad Gateway
;;
56)
echo "URL: $url failed to receive network data. Setting response code to 502."
status_code=502 # Network data failure, set to 502 Bad Gateway
;;
*)
echo "URL: $url encountered an unknown error. Setting response code to 500."
status_code=500 # Unknown error, set to 500 Internal Server Error
;;
esac
# Append the result with the actual or adjusted status code
echo "URL: $url, Status Code: $status_code"
results+=("{\"url\":\"$url\",\"response_code\":$status_code}")
done
# Join the results array into a JSON array string
results_json=$(printf "%s\n" "${results[@]}" | jq -s '.')
# Print the JSON to see the results
echo "Results: $results_json"
# Send the results to the specified endpoint using curl
post_results_url="https://prod-29.germanywestcentral.logic.azure.com:443/workflows/fcb5d309d16a46a7a683f5c0de3825ba/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=v_ZR9ulsxAYO8qsfMNCD4fg8emRme4Uxe6GbIilP-MQ"
curl -X POST "$post_results_url" \
-H "Content-Type: application/json" \
-d "$results_json"