73 lines
No EOL
2.5 KiB
Bash
73 lines
No EOL
2.5 KiB
Bash
#!/bin/bash
|
|
|
|
# --- Styling ---
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
echo -e "${YELLOW}=== Wallarm Pre-Deployment Diagnostic ===${NC}"
|
|
|
|
# --- THIS IS THE INTERACTIVE PART ---
|
|
# The '-p' flag stands for 'prompt'
|
|
read -p "Enter the Application Server IP or Hostname: " APP_HOST
|
|
read -p "Enter the Application Server Port (e.g., 80 or 8080): " APP_PORT
|
|
|
|
# Check if they actually typed something
|
|
if [ -z "$APP_HOST" ] || [ -z "$APP_PORT" ]; then
|
|
echo "❌ Error: Application Server and Port are required."
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "Testing connection to ${APP_HOST} on port ${APP_PORT}...\n"
|
|
# --- End of Interactive Part ---
|
|
|
|
# 2. Check Sudo & Update Packages
|
|
echo -e "${YELLOW}[1/4] Checking Sudo & Updating Package Lists...${NC}"
|
|
if sudo -n true 2>/dev/null; then
|
|
echo -e "${GREEN}[PASS]${NC} Sudo is active/passwordless."
|
|
else
|
|
echo -e "${RED}[FAIL]${NC} Sudo requires a password or user is not in sudoers."
|
|
echo " Please ensure 'su -' or passwordless sudo is configured."
|
|
fi
|
|
|
|
# Detect OS and install basics
|
|
if [ -f /etc/debian_version ]; then
|
|
sudo apt-get update -y && sudo apt-get install -y nano curl wget git netcat-openbsd
|
|
elif [ -f /etc/redhat-release ]; then
|
|
sudo yum makecache && sudo yum install -y nano curl wget git nc
|
|
fi
|
|
|
|
# 3. Check Required Tools
|
|
echo -e "\n${YELLOW}[2/4] Verifying Installed Tools...${NC}"
|
|
for tool in nano curl wget git nc; do
|
|
if command -v $tool &> /dev/null; then
|
|
echo -e "${GREEN}[PASS]${NC} $tool is installed."
|
|
else
|
|
echo -e "${RED}[FAIL]${NC} $tool failed to install."
|
|
fi
|
|
done
|
|
|
|
# 4. Check Wallarm Cloud Connectivity
|
|
echo -e "\n${YELLOW}[3/4] Checking Wallarm Cloud Connections...${NC}"
|
|
check_conn() {
|
|
curl -Is --connect-timeout 5 "$1" | head -n 1 | grep -q "200\|301\|302\|404\|401"
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}[PASS]${NC} Reachable: $1"
|
|
else
|
|
echo -e "${RED}[FAIL]${NC} UNREACHABLE: $1"
|
|
fi
|
|
}
|
|
|
|
check_conn "https://api.wallarm.com" # US Cloud
|
|
check_conn "https://api.wallarm.eu" # EU Cloud
|
|
|
|
# 5. Check Backend Application Connectivity
|
|
echo -e "\n${YELLOW}[4/4] Checking Backend App Connectivity...${NC}"
|
|
if nc -zv -w 5 "$APP_HOST" "$APP_PORT" 2>&1 | grep -q "succeeded\|open"; then
|
|
echo -e "${GREEN}[PASS]${NC} Connection to $APP_HOST:$APP_PORT successful."
|
|
else
|
|
echo -e "${RED}[FAIL]${NC} CANNOT REACH $APP_HOST on port $APP_PORT."
|
|
fi
|
|
|
|
echo -e "\n${YELLOW}-------------------------------------------------------"
|
|
echo -e "PRE-DEPLOYMENT-TEST COMPLETE. PLEASE TAKE A SCREENSHOT OF THIS OUTPUT."
|
|
echo -e "-------------------------------------------------------${NC}" |