-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathport_alive_rule_middleware.sh
More file actions
85 lines (69 loc) · 2.35 KB
/
Copy pathport_alive_rule_middleware.sh
File metadata and controls
85 lines (69 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Configuration
DT_NODE_1="localhost_1"
DT_NODE_2="localhost_2"
DT_NODE_3="localhost_3"
HOSTS=("$DT_NODE_1" "$DT_NODE_2" "$DT_NODE_3")
PORT="9092"
TIMEOUT=3
echo
echo "***"
echo "Checking connectivity to ${HOST}:${PORT} for Kafka service.."
# Run netcat port scan
# -z: Zero-I/O mode (scans for listening daemons without sending data)
# -v: Verbose output
# -w: Timeout in seconds
#if nc -w "$TIMEOUT" -z "$HOST1" "$PORT1" > /dev/null 2>&1; then
# echo "[Kafka Service #1] SUCCESS: Port ${PORT} on ${HOST} is ALIVE and reachable."
# exit 0
#else
# echo "[Kafka Service #1] FAILED: Port ${PORT} on ${HOST} is DOWN or blocked."
# exit 1
#fi
# Get the total count of ports in the array
TOTAL_HOSTS=${#HOSTS[@]}
#for HOST in "${HOSTS[@]}"; do
for ((i=0; i<TOTAL_HOSTS; i++)); do
HOST=${HOSTS[$i]}
# Calculate Human-friendly progress index (1-based instead of 0-based)
PROGRESS=$((i + 1))
# Run netcat with a timeout
if nc -w "$TIMEOUT" -z "$HOST" "$PORT" > /dev/null 2>&1; then
#echo "Port ${PORT}: [ OPEN ]"
echo "[Kafka Service #$PROGRESS] SUCCESS: Port ${PORT} on ${HOST} is ALIVE and reachable."
else
#echo "Port ${PORT}: [ CLOSED / BLOCKED ]"
echo "[Kafka Service #$PROGRESS] FAILED: Port ${PORT} on ${HOST} is DOWN or blocked."
fi
done
echo
echo "***"
echo "Checking connectivity for Kafka Connect service.."
PORT="2181"
#for HOST in "${HOSTS[@]}"; do
for ((i=0; i<TOTAL_HOSTS; i++)); do
HOST=${HOSTS[$i]}
# Calculate Human-friendly progress index (1-based instead of 0-based)
PROGRESS=$((i + 1))
# Run netcat with a timeout
if nc -w "$TIMEOUT" -z "$HOST" "$PORT" > /dev/null 2>&1; then
#echo "Port ${PORT}: [ OPEN ]"
echo "[Kafka Connect Service #$PROGRESS] SUCCESS: Port ${PORT} on ${HOST} is ALIVE and reachable."
else
#echo "Port ${PORT}: [ CLOSED / BLOCKED ]"
echo "[Kafka Connect Service #$PROGRESS] FAILED: Port ${PORT} on ${HOST} is DOWN or blocked."
fi
done
echo
echo "***"
echo "Checking connectivity for Spark cluster service.."
HOST="$DT_NODE_1"
PORT="8480"
if nc -w "$TIMEOUT" -z "$HOST" "$PORT" > /dev/null 2>&1; then
echo "[Spark cluster Service] SUCCESS: Port ${PORT} on ${HOST} is ALIVE and reachable."
exit 0
else
echo "[Spark cluster Service] FAILED: Port ${PORT} on ${HOST} is DOWN or blocked."
# exit 1
fi
echo
echo "***"