Skip to content

Instantly share code, notes, and snippets.

@chitoku-k
Created May 14, 2018 14:25
Show Gist options
  • Save chitoku-k/6753141879c9fd5abcd929cfdf71ceae to your computer and use it in GitHub Desktop.
Save chitoku-k/6753141879c9fd5abcd929cfdf71ceae to your computer and use it in GitHub Desktop.
Send a Slack notification when load-balance status has been updated (for EdgeRouter)
#!/bin/bash
RUN=/opt/vyatta/bin/vyatta-op-cmd-wrapper
# Slack Webhook
HOOK_URL=''
# Arguments
GROUP=$1
INTF=$2
STATUS=$3
# Message
WATCHDOG=$($RUN show load-balance watchdog)
TEXT="Status has been updated.\n\`\`\`$WATCHDOG\`\`\`"
# Parameters
PAYLOAD="{\"text\": \"$TEXT\"}"
# The last interface defined in the load-balance group
TARGET_INTF=$($RUN show configuration commands | grep "^set load-balance group $GROUP interface" | tail -1 | cut -d' ' -f6)
# Script is called multiple times by the alphabetical order of interfaces
# Send the notification only once
if [ "$INTF" = "$TARGET_INTF" ]; then
curl -X POST --data-urlencode "payload=$PAYLOAD" $HOOK_URL
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment