Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
caddy-lb-policy-switch: Add if check for failed alarm, remove one ala…
Browse files Browse the repository at this point in the history
…rm to replace it with echo
  • Loading branch information
kreatoo committed Jun 26, 2024
1 parent 29af960 commit b561bb6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions caddy/caddy-lb-policy-switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function change_upstreams() {
echo "Sending request to change upstreams"

if curl -u "$USERNAME_PASSWORD" -X PATCH -H "Content-Type: application/json" -d "$REQ_TO_SEND" "$REQ_URL" 2> /tmp/caddy-lb-policy-switch-error.log; then
alarm "[Caddy lb-policy Switch] [$IDENTIFIER] [$URL_TO_FIND] [:check:] Switched upstreams to $1"
echo "[$IDENTIFIER] [$URL_TO_FIND] Switched upstreams to $1"
else
alarm "[Caddy lb-policy Switch] [$IDENTIFIER] [$URL_TO_FIND] [:red_circle:] Failed to switch upstreams to $1\nError log: \`\`\`\n$(cat /tmp/caddy-lb-policy-switch-error.log)\n\`\`\`"
fi
Expand Down Expand Up @@ -347,7 +347,9 @@ function main() {
bad_urls_humanreadable="${bad_urls[*]// /, }"

alarm "$CADDY_SERVERS_WO_BAD_HUMANREADABLE switched to upstream $1 in $((end_func-start_func)) seconds, slept for $slept_for seconds"
alarm "$bad_urls_humanreadable failed to switch upstreams to $1"
if [[ ${#bad_urls[@]} -ne 0 ]]; then
alarm "$bad_urls_humanreadable failed to switch upstreams to $1"
fi
else
for URL_UP in "${CADDY_API_URLS_NEW[@]}"; do
URL="${URL_UP#*@}"
Expand Down

0 comments on commit b561bb6

Please sign in to comment.