Forum Discussion

Zeeguy09's avatar
Icon for Nimbostratus rankNimbostratus
Jun 27, 2024

Script to send an email if Traffic-group failovers on F5

I am using this script to detect the status of a traffic-group and send out an email if it changes its status from Active to Standby, some how i am not getting any email when i flip over the traffic group between active standby boxes. Though i have tested email through CLI and mail works. need experts advice if i am missing any thing?





# Variables

EMAIL_SUBJECT="HLR-STG-LB01 WHARF Traffic-Group Failover Alert"

# Function to send email
send_email() {
    local message=$1
    echo -e "To: ${EMAIL_TO}\nSubject: ${EMAIL_SUBJECT}\n\n${message}" | ssmtp ${EMAIL_TO}

# Function to log messages
log_message() {
    local message=$1
    echo "$(date): ${message}" >> ${LOG_FILE} 2>&1

# Function to get the current status of the traffic group
get_traffic_group_status() {
    tmsh show cm traffic-group | grep "${TRAFFIC_GROUP}"

# Initial state

# Main loop
while true; do

    if [[ "${previous_status}" != "${current_status}" ]]; then
        if echo "${current_status}" | grep -qi "standby"; then
            log_message "Traffic group ${TRAFFIC_GROUP} failed over to standby."
            send_email "Alert: Traffic group ${TRAFFIC_GROUP} has failed over to standby on another device."
        elif echo "${current_status}" | grep -qi "active"; then
            log_message "Traffic group ${TRAFFIC_GROUP} is now active."
            send_email "Info: Traffic group ${TRAFFIC_GROUP} is now active on this device."

    sleep ${CHECK_INTERVAL}


Added this script to crontab.

ensured that script is running


#ps aux | grep
root     23928  0.0  0.0 115208  1500 pts/1    T    12:04   0:00 /bin/bash ./
root     31495  0.0  0.0 114736   948 pts/1    S+   12:52   0:00 grep



2 Replies

  • Hi Zeeguy09  What does your cron entry look like? Are you getting the log messages? Any ssmtp error messages?

    • JRahm's avatar
      Icon for Admin rankAdmin

      also you might consider a perpetual iCall script that will act on a triggered event like a failover. Could customize this one from the codeshare, which generates a UCS on failover:

      Generate QKView on failover