#!/usr/bin/env bash # Copy stdout to fd 3 and redirect stdout/stderr to /var/log/f5-monitor.log exec 3>&1 &> /dev/null #/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_url="$auth_proto://$auth_ip:$auth_port/v2.0/tokens" # Auth args pulled from source file tenant="admin" user="admin" pass="INSERTPWHERE" tenant_id="INSERTIDHERE" # Save token to file save_token() { echo "$token" > /var/tmp/keystone-token } # Get new token new_token() { # 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/xml" -H "Content-Type: application/json" -H "User-Agent: f5-ltm" -d @- -w "\n%{http_code}" <&3 exit 0 # Check for 401 (token expiration or unauthorized) elif [[ "$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