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

chore: Copy back from nwaku-compose - an enhanced version of convenient node health check script #2624

Merged
merged 1 commit into from
Apr 25, 2024
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
22 changes: 14 additions & 8 deletions scripts/chkhealth.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# optional argument to specgify the ip address
ip_address=$1
ip_address="localhost:8645"
plain_text_out=false

# Parse command line arguments
Expand Down Expand Up @@ -29,8 +29,6 @@ set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
# Check if an IP address is provided as an argument
if [[ -n "$1" ]]; then
ip_address="$1"
else
ip_address="localhost:8645"
fi

# check if curl is available
Expand All @@ -40,16 +38,24 @@ then
exit 1
fi

response=$(curl -s GET http://${ip_address}/health)
response=$(curl --connect-timeout 6 -s GET http://${ip_address}/health)

if [[ $? -ne 0 ]]; then
echo -e "$(date +'%H:%M:%S') - Node may not be running or not reachable at http://${ip_address}\n"
exit 1
fi

if [[ -z "${response}" ]]; then
echo -e "$(date +'%H:%M:%S')\tnode health status is: unknown\n"
echo -e "$(date +'%H:%M:%S') - node health status is: unknown\n"
exit 1
fi

if ! command -v jq &> /dev/null || [[ "$plain_text_out" = true ]]; then
echo -e "$(date +'%H:%M:%S')\tnode health status is: ${response}\n"
echo -e "$(date +'%H:%M:%S') - node health status is: ${response}\n"
else
echo -e "$(date +'%H:%M:%S')\tnode health status is:\n"
echo "${response}" | jq .
echo -e "$(date +'%H:%M:%S') - node health status is:\n"
echo "${response}" | jq . 2>/dev/null
if [[ $? -ne 0 ]]; then
echo -e "${response}"
fi
fi
Loading