Openwrt之断线邮件报告

为何断线了还能发邮件报告呢负载均衡

由于我用的是多wan配置,4个接口都断线的可能性不大oop

负载均衡用的是MWAN3这个软件搞得确实不错,自己就自带事件报告的脚本了,所以要实现断线报告也很简单,把发邮件的命令加到对应位置就能够了this

默认的脚本是这样的spa

#!/bin/sh

# to enable this script uncomment the case loop at the bottom
# to report mwan status on interface hotplug ifup/ifdown events modify the lines in the send_alert function

send_alert()
{
    # variable "$1" stores the MWAN status information
    # insert your code here to send the contents of "$1"
    echo "$1"
}

gather_event_info()
{
    # create event information message
    local EVENT_INFO="Interface [ "$INTERFACE" ($DEVICE) ] on router [ "$(uci get -p /var/state system.@system[0].hostname)" ] has triggered a hotplug [ "$ACTION" ] event on "$(date +"%a %b %d %Y %T %Z")""

    # get current interface, policy and rule status
    local CURRENT_STATUS="$(/usr/sbin/mwan3 status)"

    # get last 50 MWAN systemlog messages
    local MWAN_LOG="$(echo -e "Last 50 MWAN systemlog entries. Newest entries sorted at the top:\n$(logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x')")"

    # pass event info to send_alert function
    send_alert "$(echo -e "$EVENT_INFO\n\n$CURRENT_STATUS\n\n$MWAN_LOG")"
}

#case "$ACTION" in
#    ifup)
#        gather_event_info
#    ;;
#
#    ifdown)
#        gather_event_info
#    ;;
#esac

exit 0

可见最后的执行动做部分是屏蔽的,动做有两个,接口上线和接口断线。执行动做部分修改后的脚本以下code

case "$ACTION" in
    ifup)
    ;;

    ifdown)
        EMAIL='To: email_address@126.com\nSubject: Openwrt Alert\n\n'$INTERFACE' is down.'
        echo -e "$EMAIL" | sendmail -t
    ;;
esac

如此便完成断线时的邮件发送了~orm

相关文章
相关标签/搜索