#!/usr/bin/env bash # F5 External monitor script for Queens deployments # Copy stdout to fd 3 and redirect stdout/stderr to /var/log/f5-monitor.log exec 3>&1 &> /dev/null # exec 3>&1 &> /var/log/f5-monitor.log #- replace null with this file to enable logging when executing the script # Auth connection auth_proto="http" auth_ip="INSERT-IP-HERE" #Internal IP address of f5 VIP auth_port="5000" auth_ver="v3" # Auth args pulled from source file tenant="admin" user="heat" pass="INSERTPWHERE" tenant_id="INSERTIDHERE" domain="Default" case $auth_ver in v2.0) auth_url="$auth_proto://$auth_ip:$auth_port/v2.0/tokens" ;; v3) auth_url="$auth_proto://$auth_ip:$auth_port/v3/auth/tokens" ;; *) # Guard echo "Invalid keystone auth version specified; bailing out" exit -1 ;; esac # Save token to file save_token() { echo "$token" > /var/tmp/keystone-token-queens } # Get new token new_token() { if [[ "$auth_ver" == "v2.0" ]]; then echo "Attempting v2.0 Auth" # Curl new token from keystone from user/pass for tenant IFS=$'\n' read -rd '' -a resp < <(curl -sk $auth_url -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "User-Agent: f5-ltm" -d @- -w "\n%{http_code}" <&3 exit 0 fi done # Check for 401 (token expiration or unauthorized) if [[ "$status" == "401" ]]; then # Exit if token is new if [[ "$token_new" == "1" ]]; then echo "Exiting after failure to authorize with valid token $token on $check_url" printf "%s\n" "${resp[@]}" exit -1 # Else we tried cached token else # Get a new token and try again new_token do_check fi # Something else happened, so bail else echo "Exiting on status: $status" printf "%s\n" "${resp[@]}" exit -1 fi } # Get token get_token # Do endpoint check do_check $1 $2