Making log output friendlier
This commit is contained in:
parent
e2f0d97823
commit
8eab9df256
|
@ -15,7 +15,22 @@ else
|
|||
echo "MISSING .env FILE!"
|
||||
exit -1
|
||||
fi
|
||||
#source .env
|
||||
|
||||
#
|
||||
# Logging
|
||||
#
|
||||
write_log() {
|
||||
logLevel='DEBUG'
|
||||
if [[ ! -z $2 ]]; then
|
||||
echo "$1: $2"
|
||||
else
|
||||
echo "logLevel: $1"
|
||||
fi
|
||||
}
|
||||
write_message() {
|
||||
write_log 'INFO' "$1"
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# CURL to get the bearer token for the following calls
|
||||
|
@ -62,12 +77,11 @@ put_recordset() {
|
|||
https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$resource_group/providers/Microsoft.Network/dnsZones/$zone_name/$RECORD_TYPE/$RELATIVE_RECORD_SET_NAME?api-version=2018-05-01
|
||||
}
|
||||
|
||||
# Get an Accesss Token
|
||||
#access_token=$(get_token)
|
||||
# echo $access_token
|
||||
|
||||
resource_group_list=($RESOURCE_GROUP_NAMES)
|
||||
zone_list=($ZONE_NAMES)
|
||||
|
||||
write_message "======================================="
|
||||
write_message "======================================="
|
||||
for i in "${!resource_group_list[@]}"; do
|
||||
resource_group="${resource_group_list[i]}"
|
||||
zone_name="${zone_list[i]}"
|
||||
|
@ -75,31 +89,38 @@ for i in "${!resource_group_list[@]}"; do
|
|||
|
||||
# Get the Record Set
|
||||
azure_recordset=$(get_recordset)
|
||||
echo "Azure Record Set: $azure_recordset"
|
||||
write_message "Azure Record Set: $zone_name"
|
||||
|
||||
# Parse the Record Set
|
||||
azure_ip_address=$(get_recordset_address $azure_recordset)
|
||||
echo "Azure IP: $azure_ip_address"
|
||||
write_message "Azure IP: $azure_ip_address"
|
||||
|
||||
# Get the currently assigned Public IP
|
||||
isp_ip_address=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
||||
echo "ISP IP: $isp_ip_address"
|
||||
write_message "ISP IP: $isp_ip_address"
|
||||
|
||||
# If the currently assigned public IP doesn't match the configured IP address in Azure...
|
||||
# update the Azure record set.
|
||||
if [ $azure_ip_address != $isp_ip_address ]; then
|
||||
echo "IP ADDRESSES DON'T MATCH. UPDATING..."
|
||||
write_message "IP ADDRESSES DON'T MATCH. UPDATING..."
|
||||
|
||||
# Prepare the request content
|
||||
azure_recordset_UPDATE=$(update_recordset $isp_ip_address)
|
||||
echo $azure_recordset_UPDATE
|
||||
write_message $azure_recordset_UPDATE
|
||||
|
||||
# Perform the Update
|
||||
AZURE_PUT_RESPONSE=$(put_recordset $azure_recordset_UPDATE)
|
||||
echo "Azure PUT Response: $AZURE_PUT_RESPONSE"
|
||||
write_message "Azure PUT Response: $AZURE_PUT_RESPONSE"
|
||||
|
||||
echo "Azure IP Address updated successfully"
|
||||
write_message "======================================="
|
||||
write_message $'Azure IP Address updated successfully\n'
|
||||
write_message "======================================="
|
||||
else
|
||||
echo "IP Address is up to date."
|
||||
write_message "======================================="
|
||||
write_message $'IP Address is up to date.\n'
|
||||
write_message "======================================="
|
||||
fi
|
||||
done
|
||||
|
||||
write_message "======================================="
|
||||
write_message "======================================="
|
||||
|
|
Loading…
Reference in New Issue
Block a user