Skip to content

Commit

Permalink
fix(connectivity): zbctl port command (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
leiicamundi authored Dec 9, 2024
1 parent 2c6f1fe commit d3767a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ This script verifies connectivity to a Zeebe Gateway instance using HTTP/2 and g

##### Usage:
```bash
Usage: ./checks/zeebe/connectivity.sh [-h] [-H ZEEBE_HOST] [-p ZEEBE_VERSION] [-f PROTO_FILE] [-k] [-r CACERT] [-j CLIENTCERT]
Usage: ./checks/zeebe/connectivity.sh [-h] [-H ZEEBE_ADDRESS] [-p ZEEBE_VERSION] [-f PROTO_FILE] [-k] [-r CACERT] [-j CLIENTCERT]
[-a ZEEBE_AUTHORIZATION_SERVER_URL] [-i ZEEBE_CLIENT_ID] [-s ZEEBE_CLIENT_SECRET]
[-u ZEEBE_TOKEN_AUDIENCE] [-q API_PROTOCOL]
Options:
-h Display this help message
-H ZEEBE_HOST Specify the Zeebe host with the port (e.g., zeebe.c8.camunda.example.com:443)
-H ZEEBE_ADDRESS Specify the Zeebe address and optional port (e.g., zeebe.c8.camunda.example.com:443)
-p ZEEBE_VERSION Specify the Zeebe version (default is the latest version: 8.6.5)
-f PROTO_FILE Specify the path to the gateway.proto file or leave empty to download it (default behavior is to download the proto file)
-k Skip TLS verification (insecure mode)
Expand Down
40 changes: 15 additions & 25 deletions checks/zeebe/connectivity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ DIR_NAME=$(dirname "$0")
LVL_1_SCRIPT_NAME="$DIR_NAME/$SCRIPT_NAME"

# Define default variables
ZEEBE_HOST="${ZEEBE_HOST:-""}"
PROTO_FILE="${PROTO_FILE:-""}"
SKIP_TLS_VERIFICATION=""
EXTRA_FLAGS_CURL=""
Expand All @@ -24,18 +23,20 @@ ZEEBE_TOKEN_AUDIENCE="${ZEEBE_TOKEN_AUDIENCE:-""}"
ZEEBE_TOKEN_SCOPE="${ZEEBE_TOKEN_SCOPE:-"camunda-identity"}"
API_PROTOCOL="${API_PROTOCOL:-"grpc"}"

ZEEBE_ADDRESS="${ZEEBE_ADDRESS:-""}"

# renovate: datasource=github-releases depName=camunda/zeebe
ZEEBE_DEFAULT_VERSION="8.6.6"
ZEEBE_VERSION="${ZEEBE_VERSION:-$ZEEBE_DEFAULT_VERSION}"

# Function to display script usage
usage() {
echo "Usage: $0 [-h] [-H ZEEBE_HOST] [-p ZEEBE_VERSION] [-f PROTO_FILE] [-k] [-r CACERT] [-j CLIENTCERT]"
echo "Usage: $0 [-h] [-H ZEEBE_ADDRESS] [-p ZEEBE_VERSION] [-f PROTO_FILE] [-k] [-r CACERT] [-j CLIENTCERT]"
echo " [-a ZEEBE_AUTHORIZATION_SERVER_URL] [-i ZEEBE_CLIENT_ID] [-s ZEEBE_CLIENT_SECRET]"
echo " [-u ZEEBE_TOKEN_AUDIENCE] [-q API_PROTOCOL]"
echo "Options:"
echo " -h Display this help message"
echo " -H ZEEBE_HOST Specify the Zeebe host with the port (e.g., zeebe.c8.camunda.example.com:443)"
echo " -H ZEEBE_ADDRESS Specify the Zeebe address and optional port (e.g., zeebe.c8.camunda.example.com:443)"
echo " -p ZEEBE_VERSION Specify the Zeebe version (default is the latest version: $ZEEBE_VERSION)"
echo " -f PROTO_FILE Specify the path to the gateway.proto file or leave empty to download it (default behavior is to download the proto file)"
echo " -k Skip TLS verification (insecure mode)"
Expand All @@ -56,7 +57,7 @@ while getopts ":hH:f:kr:j:a:i:s:u:p:q:" opt; do
usage
;;
H)
ZEEBE_HOST=$OPTARG
ZEEBE_ADDRESS=$OPTARG
;;
f)
PROTO_FILE=$OPTARG
Expand Down Expand Up @@ -92,27 +93,16 @@ while getopts ":hH:f:kr:j:a:i:s:u:p:q:" opt; do
echo "Invalid option: $OPTARG" 1>&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." 1>&2
usage
;;
esac
done

SCRIPT_STATUS_OUTPUT=0

# Check if all required options are provided
if [ -z "$ZEEBE_HOST" ]; then
echo "Error: Missing one of the required options (list of all required options: ZEEBE_HOST)." 1>&2
if [ -z "$ZEEBE_ADDRESS" ]; then
echo "Error: Missing one of the required options (list of all required options: ZEEBE_ADDRESS)." 1>&2
usage
fi

# Extract host and port from ZEEBE_HOST
if ! [[ $ZEEBE_HOST =~ ^[^:]+:[0-9]+$ ]]; then
echo "Error: Invalid format ZEEBE_HOST=$ZEEBE_HOST. Please provide host and port. Aborting." >&2
exit 1
fi

# pre-check requirements
command -v curl >/dev/null 2>&1 || { echo >&2 "Error: curl is required but not installed. Please install it. Aborting."; exit 1; }

Expand Down Expand Up @@ -164,8 +154,8 @@ fi

if [ "$API_PROTOCOL" = "http" ]; then
check_rest(){
echo "[INFO] Checking REST API connectivity to $ZEEBE_HOST"
curl_command="curl -so /dev/null -L ${EXTRA_FLAGS_CURL} \"$ZEEBE_HOST/v2/topology\""
echo "[INFO] Checking REST API connectivity to $ZEEBE_ADDRESS:"
curl_command="curl -so /dev/null -L ${EXTRA_FLAGS_CURL} \"$ZEEBE_ADDRESS:/v2/topology\""
echo "[INFO] Running command: ${curl_command}"

if eval "${curl_command}"; then
Expand All @@ -181,8 +171,8 @@ fi
if [ "$API_PROTOCOL" = "grpc" ]; then
# Check HTTP/2 connectivity
check_http2(){
echo "[INFO] Checking HTTP/2 connectivity to $ZEEBE_HOST"
curl_command="curl -so /dev/null --http2 ${EXTRA_FLAGS_CURL} \"https://$ZEEBE_HOST\""
echo "[INFO] Checking HTTP/2 connectivity to ${ZEEBE_ADDRESS}"
curl_command="curl -so /dev/null --http2 ${EXTRA_FLAGS_CURL} \"https://${ZEEBE_ADDRESS}\""
echo "[INFO] Running command: ${curl_command}"

if eval "${curl_command}"; then
Expand Down Expand Up @@ -216,10 +206,10 @@ if [ "$API_PROTOCOL" = "grpc" ]; then

# Check gRPC connectivity using grpcurl
check_grpc(){
echo "[INFO] Checking gRPC connectivity to $ZEEBE_HOST"
echo "[INFO] Checking gRPC connectivity to ${ZEEBE_ADDRESS}"

local grcp_curl_command
grcp_curl_command="grpcurl ${EXTRA_FLAGS_GRPCURL} -proto \"${PROTO_FILE}\" \"${ZEEBE_HOST}\" gateway_protocol.Gateway/Topology"
grcp_curl_command="grpcurl ${EXTRA_FLAGS_GRPCURL} -proto \"${PROTO_FILE}\" \"${ZEEBE_ADDRESS}\" gateway_protocol.Gateway/Topology"
echo "[INFO] Running command: ${grcp_curl_command}"


Expand All @@ -234,10 +224,10 @@ if [ "$API_PROTOCOL" = "grpc" ]; then

# Check zbctl status
check_zbctl() {
echo "[INFO] Checking zbctl status to $ZEEBE_HOST..."
echo "[INFO] Checking zbctl status to $ZEEBE_ADDRESS..."

local zbctl_command
zbctl_command="ZEEBE_TOKEN_SCOPE=${ZEEBE_TOKEN_SCOPE} zbctl status --address \"${ZEEBE_HOST}\" --authzUrl \"${ZEEBE_AUTHORIZATION_SERVER_URL}\" --clientId \"${ZEEBE_CLIENT_ID}\" --clientSecret \"${ZEEBE_CLIENT_SECRET}\" --audience \"${ZEEBE_TOKEN_AUDIENCE}\" ${EXTRA_FLAGS_ZBCTL}"
zbctl_command="ZEEBE_TOKEN_SCOPE=${ZEEBE_TOKEN_SCOPE} ZEEBE_ADDRESS=${ZEEBE_ADDRESS} ZEEBE_HOST="" ZEEBE_PORT="" zbctl status --authzUrl \"${ZEEBE_AUTHORIZATION_SERVER_URL}\" --clientId \"${ZEEBE_CLIENT_ID}\" --clientSecret \"${ZEEBE_CLIENT_SECRET}\" --audience \"${ZEEBE_TOKEN_AUDIENCE}\" ${EXTRA_FLAGS_ZBCTL}"

echo "[INFO] Running command: ${zbctl_command}"

Expand Down

0 comments on commit d3767a0

Please sign in to comment.