swarm_triggers_test.sh #1

  • //
  • guest/
  • perforce_software/
  • sdp/
  • main/
  • Unsupported/
  • setup/
  • swarm_triggers_test.sh
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
#------------------------------------------------------------------------------
# This script automates a connectivity test for Perforce Helix Swarm triggers.
# This should be run on the Helix Core (p4d) server machine where Swarm
# triggers are installed.  It tests settings in the swarm-trigger.config
# file including the host and trigger token, as well as testing connectivity
# from the Helix Core to the Helix Swarm server. It exercises things such as
# DNS names, HTTPS certificates (if used), current availability of the Swarm
# server/service, and network firewall rules for port 80 (HTTP) or 443 (HTTPS).
#------------------------------------------------------------------------------
# The core of the test was extracted from a Perforce Support article.
# See the 'Trigger Problems' section of the Knowledge Base article
# Troubleshooting Helix Swarm: https://community.perforce.com/s/article/3696 
#------------------------------------------------------------------------------
set -u

declare ThisScript=${0##*/}
declare ThisUser=
declare Version=1.1.0
declare -i ErrorCount=0
declare Cmd=
declare TmpFile=
declare SwarmTriggerConf="${1:-/opt/perforce/etc/swarm-trigger.conf}"

function msg () { echo -e "$*"; }
function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "${2:-1}"; }

TmpFile=$(mktemp)
ThisUser=$(id -n -u)
msg "\\nStarting $ThisScript v$Version as $ThisUser@${HOSTNAME%%.*} at $(date)."

# shellcheck disable=SC1090
source "$SwarmTriggerConf" || bail "Could not read Swarm Trigger conf file: $SwarmTriggerConf\\nTry: $ThisScript /path/to/swarm-trigger.conf"

Cmd="wget --timeout 10 --post-data shelve,1234 ${SWARM_HOST}/queue/add/${SWARM_TOKEN}"

msg "Testing Swarm access with:\\n\\t$Cmd"

$Cmd > "$TmpFile" 2>&1

cat "$TmpFile"

if grep -q "200 OK" "$TmpFile"; then
   msg "\\nVerified: Access to Swarm was successful using settings in: $SwarmTriggerConf"
else
   errmsg "\\nDid not get expected '200 OK' output accessing Swarm using settings in: $SwarmTriggerConf"
fi

exit "$ErrorCount"
# Change User Description Committed
#5 30297 C. Thomas Tyler Released SDP 2023.2.30295 (2024/05/08).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#4 29954 C. Thomas Tyler Released SDP 2023.1.29949 (2023/12/01).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#3 29143 C. Thomas Tyler Released SDP 2022.1.29141 (2022/10/29).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#2 28858 C. Thomas Tyler Released SDP 2022.1.28855 (2022/05/27).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
#1 28651 C. Thomas Tyler Released SDP 2021.2.28649 (2022/03/03).
Copy Up using 'p4 copy -r -b perforce_software-sdp-dev'.
//guest/perforce_software/sdp/dev/Unsupported/setup/swarm_triggers_test.sh
#1 28614 C. Thomas Tyler Added sample utility to test Swarm triggers.